From 4713a6804097c334fabc67e5e8efbf190caa22cc Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Sun, 1 Oct 2023 02:46:45 +0100 Subject: [PATCH] fix updating of app status --- pilot/database/database.py | 69 ++++++++++++------------------- pilot/database/models/app.py | 2 +- pilot/helpers/Project.py | 8 +--- pilot/helpers/agents/Developer.py | 3 +- pilot/main.py | 1 - pilot/utils/arguments.py | 1 + 6 files changed, 31 insertions(+), 53 deletions(-) diff --git a/pilot/database/database.py b/pilot/database/database.py index 206e6ee..ba8edb9 100644 --- a/pilot/database/database.py +++ b/pilot/database/database.py @@ -32,7 +32,23 @@ DB_HOST = os.getenv("DB_HOST") DB_PORT = os.getenv("DB_PORT") DB_USER = os.getenv("DB_USER") DB_PASSWORD = os.getenv("DB_PASSWORD") - +TABLES = [ + User, + App, + ProjectDescription, + UserStories, + UserTasks, + Architecture, + DevelopmentPlanning, + DevelopmentSteps, + EnvironmentSetup, + Development, + FileSnapshot, + CommandRuns, + UserApps, + UserInputs, + File, + ] def get_created_apps(): return [model_to_dict(app) for app in App.select()] @@ -94,16 +110,18 @@ def get_user(user_id=None, email=None): def save_app(project): + args = project.args + app_status = getattr(project, "current_step", None) + try: - args = project.args app = App.get(App.id == args['app_id']) for key, value in args.items(): if key != 'app_id' and value is not None: setattr(app, key, value) - app.status = project.current_step + + app.status = app_status app.save() except DoesNotExist: - args = project.args if args.get('user_id') is not None: try: user = get_user(user_id=args['user_id']) @@ -119,7 +137,7 @@ def save_app(project): user=user, app_type=args.get('app_type'), name=args.get('name'), - status=project.current_step + status=app_status ) return app @@ -401,44 +419,12 @@ def save_file_description(project, path, name, description): def create_tables(): with database: - database.create_tables([ - User, - App, - ProjectDescription, - UserStories, - UserTasks, - Architecture, - DevelopmentPlanning, - DevelopmentSteps, - EnvironmentSetup, - Development, - FileSnapshot, - CommandRuns, - UserApps, - UserInputs, - File, - ]) + database.create_tables(TABLES) def drop_tables(): with database.atomic(): - for table in [ - User, - App, - ProjectDescription, - UserStories, - UserTasks, - Architecture, - DevelopmentPlanning, - DevelopmentSteps, - EnvironmentSetup, - Development, - FileSnapshot, - CommandRuns, - UserApps, - UserInputs, - File, - ]: + for table in TABLES: if DATABASE_TYPE == "postgres": sql = f'DROP TABLE IF EXISTS "{table._meta.table_name}" CASCADE' elif DATABASE_TYPE == "sqlite": @@ -484,11 +470,8 @@ def create_database(): def tables_exist(): - tables = [User, App, ProjectDescription, UserStories, UserTasks, Architecture, DevelopmentPlanning, - DevelopmentSteps, EnvironmentSetup, Development, FileSnapshot, CommandRuns, UserApps, UserInputs, File] - if DATABASE_TYPE == "postgres": - for table in tables: + for table in TABLES: try: database.get_tables().index(table._meta.table_name) except ValueError: diff --git a/pilot/database/models/app.py b/pilot/database/models/app.py index 2940397..f55e814 100644 --- a/pilot/database/models/app.py +++ b/pilot/database/models/app.py @@ -8,4 +8,4 @@ class App(BaseModel): user = ForeignKeyField(User, backref='apps') app_type = CharField(null=True) name = CharField(null=True) - status = CharField(default='started') \ No newline at end of file + status = CharField(null=True) \ No newline at end of file diff --git a/pilot/helpers/Project.py b/pilot/helpers/Project.py index 2e7f2a7..a14cb7a 100644 --- a/pilot/helpers/Project.py +++ b/pilot/helpers/Project.py @@ -94,7 +94,7 @@ class Project: self.architecture = self.architect.get_architecture() self.developer = Developer(self) - self.developer.set_up_environment(); + self.developer.set_up_environment() self.tech_lead = TechLead(self) self.development_plan = self.tech_lead.create_development_plan() @@ -129,12 +129,6 @@ class Project: break # TODO END - self.developer = Developer(self) - print(json.dumps({ - "project_stage": "environment_setup" - }), type='info') - self.developer.set_up_environment() - print(json.dumps({ "project_stage": "coding" }), type='info') diff --git a/pilot/helpers/agents/Developer.py b/pilot/helpers/agents/Developer.py index 597c88e..93f9a2c 100644 --- a/pilot/helpers/agents/Developer.py +++ b/pilot/helpers/agents/Developer.py @@ -13,7 +13,7 @@ from helpers.AgentConvo import AgentConvo from utils.utils import should_execute_step, array_of_objects_to_string, generate_app_data from helpers.cli import run_command_until_success, execute_command_and_check_cli_response from const.function_calls import FILTER_OS_TECHNOLOGIES, EXECUTE_COMMANDS, GET_TEST_TYPE, IMPLEMENT_TASK -from database.database import save_progress, get_progress_steps +from database.database import save_progress, get_progress_steps, update_app_status from utils.utils import get_os_info ENVIRONMENT_SETUP_STEP = 'environment_setup' @@ -27,6 +27,7 @@ class Developer(Agent): def start_coding(self): self.project.current_step = 'coding' + update_app_status(self.project.args['app_id'], self.project.current_step) if self.project.skip_steps is None: self.project.skip_steps = False if ('skip_until_dev_step' in self.project.args and self.project.args['skip_until_dev_step'] == '0') else True diff --git a/pilot/main.py b/pilot/main.py index b658461..0fb7ceb 100644 --- a/pilot/main.py +++ b/pilot/main.py @@ -43,7 +43,6 @@ def get_custom_print(args): if 'type' not in kwargs: kwargs['type'] = 'verbose' - return elif kwargs['type'] == MESSAGE_TYPE['local']: local_print(*args, **kwargs) return diff --git a/pilot/utils/arguments.py b/pilot/utils/arguments.py index 27d8614..75dc5c0 100644 --- a/pilot/utils/arguments.py +++ b/pilot/utils/arguments.py @@ -42,6 +42,7 @@ def get_arguments(): arguments['app_type'] = app.app_type arguments['name'] = app.name + arguments['step'] = app.status # Add any other fields from the App model you wish to include print(green_bold('\n------------------ LOADING PROJECT ----------------------'))