From 97d27ca6cb024d595a386bc06dbd52a1468b7923 Mon Sep 17 00:00:00 2001 From: Xieyt Date: Tue, 27 Feb 2024 23:39:35 +0530 Subject: [PATCH 1/3] fix: app installation path --- Docker/frappe/helper-function.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Docker/frappe/helper-function.sh b/Docker/frappe/helper-function.sh index 645413be..59b17eae 100755 --- a/Docker/frappe/helper-function.sh +++ b/Docker/frappe/helper-function.sh @@ -208,7 +208,9 @@ update_uid_gid() { # $1 -> app_name respective to apps dir get_app_name(){ local app="$1" - hooks_py_path="/workspce/frappe-bench/apps/$app" + local app_dir + app_dir="/workspace/frappe-bench/apps/${app}" + hooks_py_path=$(find "$app_dir" -maxdepth 2 -type f -name hooks.py) # Extract the app name from the hooks.py file APP_NAME=$(awk -F'"' '/app_name/{print $2}' "$hooks_py_path" || exit 0) From db6f829beb0fe66bfd610caf3a7de28a384bbd52 Mon Sep 17 00:00:00 2001 From: Xieyt Date: Tue, 27 Feb 2024 23:40:50 +0530 Subject: [PATCH 2/3] Update image tag in template --- frappe_manager/templates/docker-compose.tmpl | 4 ++-- frappe_manager/templates/docker-compose.workers.tmpl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe_manager/templates/docker-compose.tmpl b/frappe_manager/templates/docker-compose.tmpl index cc13ed81..a44006ee 100644 --- a/frappe_manager/templates/docker-compose.tmpl +++ b/frappe_manager/templates/docker-compose.tmpl @@ -76,7 +76,7 @@ services: global-backend-network: socketio: - image: ghcr.io/rtcamp/frappe-manager-frappe:v0.10.0 + image: ghcr.io/rtcamp/frappe-manager-frappe:v0.11.0 container_name: REPLACE_ME_WITH_CONTAINER_NAME restart: always environment: @@ -95,7 +95,7 @@ services: site-network: schedule: - image: ghcr.io/rtcamp/frappe-manager-frappe:v0.10.0 + image: ghcr.io/rtcamp/frappe-manager-frappe:v0.11.0 container_name: REPLACE_ME_WITH_CONTAINER_NAME restart: always environment: diff --git a/frappe_manager/templates/docker-compose.workers.tmpl b/frappe_manager/templates/docker-compose.workers.tmpl index 4cdeaf16..98a6accd 100644 --- a/frappe_manager/templates/docker-compose.workers.tmpl +++ b/frappe_manager/templates/docker-compose.workers.tmpl @@ -1,6 +1,6 @@ services: worker-name: - image: ghcr.io/rtcamp/frappe-manager-frappe:v0.10.0 + image: ghcr.io/rtcamp/frappe-manager-frappe:v0.11.0 restart: always environment: TIMEOUT: 6000 From a8c7888c7e59952919d3529f14278257b9c51be9 Mon Sep 17 00:00:00 2001 From: Xieyt Date: Tue, 27 Feb 2024 23:42:41 +0530 Subject: [PATCH 3/3] remove double prompt in fm create, format code --- frappe_manager/site_manager/SiteManager.py | 137 +++++++++++++-------- 1 file changed, 86 insertions(+), 51 deletions(-) diff --git a/frappe_manager/site_manager/SiteManager.py b/frappe_manager/site_manager/SiteManager.py index 00db0333..179f2a87 100644 --- a/frappe_manager/site_manager/SiteManager.py +++ b/frappe_manager/site_manager/SiteManager.py @@ -21,7 +21,7 @@ class SiteManager: - def __init__(self, sitesdir: Path, services = None): + def __init__(self, sitesdir: Path, services=None): self.sitesdir = sitesdir self.site = None self.sitepath = None @@ -57,7 +57,12 @@ def init(self, sitename: str | None = None): f"The site '{sitename}' does not exist. Aborting operation." ) - self.site: Site = Site(sitepath, sitename, verbose=self.verbose,services=self.services) + self.site: Site = Site( + sitepath, + sitename, + verbose=self.verbose, + services=self.services, + ) def set_verbose(self): """ @@ -102,14 +107,16 @@ def stop_sites(self): for site_compose_path in site_compose: docker = DockerClient(compose_file_path=site_compose_path) try: - output = docker.compose.stop(timeout=10, stream=not self.verbose) + output = docker.compose.stop( + timeout=10, stream=not self.verbose + ) if not self.verbose: richprint.live_lines(output, padding=(0, 0, 0, 2)) except DockerException as e: richprint.exit(f"{status_text}: Failed") richprint.print(f"{status_text}: Done") - def create_site(self, template_inputs: dict,template_site: bool = False): + def create_site(self, template_inputs: dict, template_site: bool = False): """ Creates a new site using the provided template inputs. @@ -130,7 +137,10 @@ def create_site(self, template_inputs: dict,template_site: bool = False): if template_site: self.site.remove_secrets() - richprint.exit(f"Created template site: {self.site.name}",emoji_code=":white_check_mark:") + richprint.exit( + f"Created template site: {self.site.name}", + emoji_code=":white_check_mark:", + ) richprint.change_head(f"Starting Site") self.site.start() @@ -149,10 +159,14 @@ def create_site(self, template_inputs: dict,template_site: bool = False): ) richprint.print(f"Started site") self.info() - if not '.localhost' in self.site.name: - richprint.print(f"Please note that You will have to add a host entry to your system's hosts file to access the site locally.") + if not ".localhost" in self.site.name: + richprint.print( + f"Please note that You will have to add a host entry to your system's hosts file to access the site locally." + ) else: - self.typer_context.obj["logger"].error(f"{self.site.name}: NOT WORKING") + self.typer_context.obj["logger"].error( + f"{self.site.name}: NOT WORKING" + ) richprint.stop() @@ -165,23 +179,27 @@ def create_site(self, template_inputs: dict,template_site: bool = False): richprint.error(error_message.format(log_path)) - # prompt if site not working to delete the site - if typer.confirm(f"Do you want to delete this site {self.site.name}?"): - richprint.start("Removing Site") - self.remove_site() - else: + remove_status = self.remove_site() + if not remove_status: self.info() - def remove_site(self): + def remove_site(self) -> bool: """ Removes the site. """ richprint.stop() - continue_remove= Prompt.ask(f"🤔 Do you want to remove [bold][green]'{self.site.name}'[/bold][/green]", choices=["yes", "no"],default='no') - if continue_remove == 'yes': - richprint.start('Removing Site') - self.site.remove_database_and_user() - self.site.remove() + continue_remove = Prompt.ask( + f"🤔 Do you want to remove [bold][green]'{self.site.name}'[/bold][/green]", + choices=["yes", "no"], + default="no", + ) + if continue_remove == "no": + return False + + richprint.start("Removing Site") + self.site.remove_database_and_user() + self.site.remove() + return True def list_sites(self): """ @@ -206,7 +224,9 @@ def list_sites(self): temp_site = Site(site_path, site_name) row_data = f"[link=http://{temp_site.name}]{temp_site.name}[/link]" - path_data = f"[link=file://{temp_site.path}]{temp_site.path}[/link]" + path_data = ( + f"[link=file://{temp_site.path}]{temp_site.path}[/link]" + ) status_color = "white" status_msg = "Inactive" @@ -237,13 +257,15 @@ def start_site(self): """ Starts the site. """ - #self.migrate_site() + # self.migrate_site() self.site.sync_site_common_site_config() self.site.start() self.site.frappe_logs_till_start(status_msg="Starting Site") self.site.sync_workers_compose() - def attach_to_site(self, user: str, extensions: List[str], debugger: bool = False): + def attach_to_site( + self, user: str, extensions: List[str], debugger: bool = False + ): """ Attaches to a running site's container using Visual Studio Code Remote Containers extension. @@ -276,15 +298,15 @@ def attach_to_site(self, user: str, extensions: List[str], debugger: bool = Fals vscode_config_json = [ { "remoteUser": user, - "remoteEnv": { - "SHELL": "/bin/zsh" + "remoteEnv": {"SHELL": "/bin/zsh"}, + "customizations": { + "vscode": { + "settings": { + "python.pythonPath": "/workspace/frappe-bench/env/bin/python" + }, + "extensions": extensions, + } }, - "customizations": {"vscode": { - "settings": { - "python.pythonPath": "/workspace/frappe-bench/env/bin/python" - }, - "extensions": extensions - }}, } ] @@ -295,10 +317,12 @@ def attach_to_site(self, user: str, extensions: List[str], debugger: bool = Fals # check if the extension are the same if they are different then only update # check if customizations key available try: - extensions_previous = json.loads(labels_previous["devcontainer.metadata"]) - extensions_previous = extensions_previous[0]["customizations"]["vscode"][ - "extensions" - ] + extensions_previous = json.loads( + labels_previous["devcontainer.metadata"] + ) + extensions_previous = extensions_previous[0]["customizations"][ + "vscode" + ]["extensions"] except KeyError: extensions_previous = [] @@ -315,27 +339,32 @@ def attach_to_site(self, user: str, extensions: List[str], debugger: bool = Fals # sync debugger files if debugger: richprint.change_head("Sync vscode debugger configuration") - dot_vscode_dir = self.site.path / 'workspace' / '.vscode' - tasks_json_path = dot_vscode_dir / 'tasks' - launch_json_path = dot_vscode_dir / 'launch' + dot_vscode_dir = self.site.path / "workspace" / ".vscode" + tasks_json_path = dot_vscode_dir / "tasks" + launch_json_path = dot_vscode_dir / "launch" dot_vscode_config = { - tasks_json_path : VSCODE_TASKS_JSON, - launch_json_path : VSCODE_LAUNCH_JSON, + tasks_json_path: VSCODE_TASKS_JSON, + launch_json_path: VSCODE_LAUNCH_JSON, } if not dot_vscode_dir.exists(): - dot_vscode_dir.mkdir(exist_ok=True,parents=True) + dot_vscode_dir.mkdir(exist_ok=True, parents=True) - for file_path in [launch_json_path,tasks_json_path]: - file_name = f'{file_path.name}.json' + for file_path in [launch_json_path, tasks_json_path]: + file_name = f"{file_path.name}.json" real_file_path = file_path.parent / file_name if real_file_path.exists(): - backup_tasks_path = file_path.parent / f"{file_path.name}.{datetime.now().strftime('%d-%b-%y--%H-%M-%S')}.json" + backup_tasks_path = ( + file_path.parent + / f"{file_path.name}.{datetime.now().strftime('%d-%b-%y--%H-%M-%S')}.json" + ) shutil.copy2(real_file_path, backup_tasks_path) - richprint.print(f"Backup previous '{file_name}' : {backup_tasks_path}") + richprint.print( + f"Backup previous '{file_name}' : {backup_tasks_path}" + ) - with open(real_file_path, 'w+') as f: + with open(real_file_path, "w+") as f: f.write(json.dumps(dot_vscode_config[file_path])) richprint.print("Sync vscode debugger configuration: Done") @@ -419,13 +448,17 @@ def info(self): db_user = site_config["db_name"] db_pass = site_config["db_password"] - frappe_password = self.site.composefile.get_envs("frappe")["ADMIN_PASS"] + frappe_password = self.site.composefile.get_envs("frappe")[ + "ADMIN_PASS" + ] services_db_info = self.services.get_database_info() - root_db_password = services_db_info['password'] - root_db_host = services_db_info['host'] - root_db_user = services_db_info['user'] + root_db_password = services_db_info["password"] + root_db_host = services_db_info["host"] + root_db_user = services_db_info["user"] - site_info_table = Table(show_lines=True, show_header=False, highlight=True) + site_info_table = Table( + show_lines=True, show_header=False, highlight=True + ) data = { "Site Url": f"http://{self.site.name}", @@ -468,7 +501,9 @@ def info(self): running_site_workers = self.site.workers.get_services_running_status() if running_site_services: - site_services_table = generate_services_table(running_site_services) + site_services_table = generate_services_table( + running_site_services + ) site_info_table.add_row("Site Services", site_services_table) if running_site_workers: