From 5af4ce14923f18a982c2926b3179a4555d56b49c Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Sun, 1 Oct 2023 14:43:28 +0100 Subject: [PATCH] fix double logging in extension, dont get apps with name or status null and update package_repo.py script --- pilot/database/database.py | 2 +- pilot/helpers/AgentConvo.py | 2 +- scripts/package_repo.py | 57 ++++++++++++++++++++++++++----------- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/pilot/database/database.py b/pilot/database/database.py index 76b7cdf..b9dc305 100644 --- a/pilot/database/database.py +++ b/pilot/database/database.py @@ -51,7 +51,7 @@ TABLES = [ ] def get_created_apps(): - return [model_to_dict(app) for app in App.select()] + return [model_to_dict(app) for app in App.select().where((App.name.is_null(False)) & (App.status.is_null(False)))] def get_created_apps_with_steps(): diff --git a/pilot/helpers/AgentConvo.py b/pilot/helpers/AgentConvo.py index 7dd60f4..f0676c5 100644 --- a/pilot/helpers/AgentConvo.py +++ b/pilot/helpers/AgentConvo.py @@ -187,7 +187,7 @@ class AgentConvo: if self.log_to_user: if self.agent.project.checkpoints['last_development_step'] is not None: print(yellow("\nDev step ") + yellow_bold(str(self.agent.project.checkpoints['last_development_step'])) + '\n', end='') - print(f"\n{content}\n") + print(f"\n{content}\n", type='local') logger.info(f"{print_msg}: {content}\n") def to_playground(self): diff --git a/scripts/package_repo.py b/scripts/package_repo.py index fbf912f..50ad0d1 100644 --- a/scripts/package_repo.py +++ b/scripts/package_repo.py @@ -5,31 +5,54 @@ import zipfile def main(): # Define the base directory (one level up from /scripts) base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - # Define paths based on base directory - env_path = os.path.join(base_dir, "pilot", ".env") - tmp_env_path = os.path.join("/tmp", ".env") repo_path = os.path.abspath(base_dir) - # Check if .env exists - if os.path.exists(env_path): - # Step 1: Move .env to /tmp/x - shutil.move(env_path, tmp_env_path) + # Files to exclude from the repo temporarily while packaging + files_to_exclude = [ + "pilot/.env", + "pilot/gpt-pilot" + ] - # Step 2: Package the repository using Python's zipfile module + # Step 1: Move excluded files to /tmp + tmp_excluded_paths = [] + for file in files_to_exclude: + source_path = os.path.join(repo_path, file) + if os.path.exists(source_path): + tmp_path = os.path.join("/tmp", os.path.basename(file)) + shutil.move(source_path, tmp_path) + tmp_excluded_paths.append((tmp_path, source_path)) + + # Items to package + items_to_package = [ + "pilot", + "scripts", + "Dockerfile", + "docker-compose.yml", + "LICENSE", + "README.md", + "requirements.txt" + ] + + # Step 2: Package the specified items using Python's zipfile module parent_directory = os.path.dirname(base_dir) archive_path = os.path.join(parent_directory, "gpt-pilot-packaged.zip") with zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED) as archive: - for root, _, files in os.walk(repo_path): - for file in files: - file_path = os.path.join(root, file) - archive_path = os.path.relpath(file_path, repo_path) - archive.write(file_path, archive_path) + for item in items_to_package: + item_path = os.path.join(repo_path, item) + if os.path.isfile(item_path): + archive.write(item_path, item) + elif os.path.isdir(item_path): + for root, _, files in os.walk(item_path): + for file in files: + file_path = os.path.join(root, file) + archive_path = os.path.relpath(file_path, repo_path) + archive.write(file_path, archive_path) - # Step 3: Move the .env file back, if it existed initially - if os.path.exists(tmp_env_path): - shutil.move(tmp_env_path, env_path) + # Step 3: Move the excluded files back + for tmp_path, orig_path in tmp_excluded_paths: + if os.path.exists(tmp_path): + shutil.move(tmp_path, orig_path) if __name__ == "__main__": main()