From 877e812fbbee2fcb65e3759175883096f5ea55a5 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 26 Nov 2021 18:53:13 +0530 Subject: [PATCH] fix: Patch to move archived_sites to archived/sites This patch runs only if Frappe >= v14. Doesn't do anything else Frappe PR: https://github.com/frappe/frappe/pull/15060 --- bench/patches/patches.txt | 3 +- bench/patches/v5/update_archived_sites.py | 51 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 bench/patches/v5/update_archived_sites.py diff --git a/bench/patches/patches.txt b/bench/patches/patches.txt index da51be2e..4be1468c 100644 --- a/bench/patches/patches.txt +++ b/bench/patches/patches.txt @@ -6,4 +6,5 @@ bench.patches.v4.update_socketio bench.patches.v4.install_yarn #2 bench.patches.v5.fix_user_permissions bench.patches.v5.fix_backup_cronjob -bench.patches.v5.set_live_reload_config \ No newline at end of file +bench.patches.v5.set_live_reload_config +bench.patches.v5.update_archived_sites \ No newline at end of file diff --git a/bench/patches/v5/update_archived_sites.py b/bench/patches/v5/update_archived_sites.py new file mode 100644 index 00000000..76507daf --- /dev/null +++ b/bench/patches/v5/update_archived_sites.py @@ -0,0 +1,51 @@ +""" +Deprecate archived_sites folder for consistency. This change is +only for Frappe v14 benches. If not a v14 bench yet, skip this +patch and try again later. + +1. Rename folder `./archived_sites` to `./archived/sites` +2. Create a symlink `./archived_sites` => `./archived/sites` + +Corresponding changes in frappe/frappe via https://github.com/frappe/frappe/pull/15060 +""" +import os +import shutil +from pathlib import Path + +import click +from bench.utils.app import get_current_version +from semantic_version import Version + + +def execute(bench_path): + frappe_version = Version(get_current_version('frappe')) + + if frappe_version.major < 14 or os.name != "posix": + # Returning False means patch has been skipped + return False + + pre_patch_dir = os.getcwd() + old_directory = Path(bench_path, "archived_sites") + new_directory = Path(bench_path, "archived", "sites") + + if old_directory.is_symlink(): + return True + + os.chdir(bench_path) + + if not os.path.exists(new_directory): + os.makedirs(new_directory) + + for archived_site_path in old_directory.glob("*"): + shutil.move(archived_site_path, new_directory) + + click.secho(f"Archived sites are now stored under {new_directory}") + + if not os.listdir(old_directory): + os.rmdir(old_directory) + + os.symlink(new_directory, old_directory) + + click.secho(f"Symlink {old_directory} that points to {new_directory}") + + os.chdir(pre_patch_dir)