diff --git a/src/yunohost/app.py b/src/yunohost/app.py index cf4b47681..fd088bce9 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -62,7 +62,12 @@ from yunohost.utils.i18n import _value_for_locale from yunohost.utils.error import YunohostError, YunohostValidationError from yunohost.utils.filesystem import free_space_in_directory from yunohost.log import is_unit_operation, OperationLogger -from yunohost.app_catalog import app_catalog, app_search, _load_apps_catalog, app_fetchlist # noqa +from yunohost.app_catalog import ( + app_catalog, + app_search, + _load_apps_catalog, + app_fetchlist, +) # noqa logger = getActionLogger("yunohost.app") @@ -393,7 +398,9 @@ def app_change_url(operation_logger, app, domain, path): app_setting_path = os.path.join(APPS_SETTING_PATH, app) path_requirement = _guess_webapp_path_requirement(app_setting_path) - _validate_webpath_requirement({"domain": domain, "path": path}, path_requirement, ignore_app=app) + _validate_webpath_requirement( + {"domain": domain, "path": path}, path_requirement, ignore_app=app + ) tmp_workdir_for_app = _make_tmp_workdir_for_app(app=app) @@ -551,7 +558,9 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False app_setting_path = os.path.join(APPS_SETTING_PATH, app_instance_name) # Prepare env. var. to pass to script - env_dict = _make_environment_for_app_script(app_instance_name, workdir=extracted_app_folder) + env_dict = _make_environment_for_app_script( + app_instance_name, workdir=extracted_app_folder + ) env_dict["YNH_APP_UPGRADE_TYPE"] = upgrade_type env_dict["YNH_APP_MANIFEST_VERSION"] = str(app_new_version) env_dict["YNH_APP_CURRENT_VERSION"] = str(app_current_version) @@ -615,7 +624,7 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False if upgrade_failed or broke_the_system: # display this if there are remaining apps - if apps[number + 1:]: + if apps[number + 1 :]: not_upgraded_apps = apps[number:] logger.error( m18n.n( @@ -647,9 +656,13 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False # Replace scripts and manifest and conf (if exists) # Move scripts and manifest to the right place for file_to_copy in APP_FILES_TO_COPY: - rm(f'{app_setting_path}/{file_to_copy}', recursive=True, force=True) + rm(f"{app_setting_path}/{file_to_copy}", recursive=True, force=True) if os.path.exists(os.path.join(extracted_app_folder, file_to_copy)): - cp(f'{extracted_app_folder}/{file_to_copy}', f'{app_setting_path}/{file_to_copy}', recursive=True) + cp( + f"{extracted_app_folder}/{file_to_copy}", + f"{app_setting_path}/{file_to_copy}", + recursive=True, + ) # Clean and set permissions shutil.rmtree(extracted_app_folder) @@ -820,7 +833,11 @@ def app_install( # Move scripts and manifest to the right place for file_to_copy in APP_FILES_TO_COPY: if os.path.exists(os.path.join(extracted_app_folder, file_to_copy)): - cp(f'{extracted_app_folder}/{file_to_copy}', f'{app_setting_path}/{file_to_copy}', recursive=True) + cp( + f"{extracted_app_folder}/{file_to_copy}", + f"{app_setting_path}/{file_to_copy}", + recursive=True, + ) # Initialize the main permission for the app # The permission is initialized with no url associated, and with tile disabled @@ -835,7 +852,9 @@ def app_install( ) # Prepare env. var. to pass to script - env_dict = _make_environment_for_app_script(app_instance_name, args=args, workdir=extracted_app_folder) + env_dict = _make_environment_for_app_script( + app_instance_name, args=args, workdir=extracted_app_folder + ) env_dict_for_logging = env_dict.copy() for question in questions: @@ -896,7 +915,9 @@ def app_install( logger.warning(m18n.n("app_remove_after_failed_install")) # Setup environment for remove script - env_dict_remove = _make_environment_for_app_script(app_instance_name, workdir=extracted_app_folder) + env_dict_remove = _make_environment_for_app_script( + app_instance_name, workdir=extracted_app_folder + ) # Execute remove script operation_logger_remove = OperationLogger( @@ -1504,7 +1525,9 @@ def app_action_run(operation_logger, app, action, args=None): tmp_workdir_for_app = _make_tmp_workdir_for_app(app=app) - env_dict = _make_environment_for_app_script(app, args=args, args_prefix="ACTION_", workdir=tmp_workdir_for_app) + env_dict = _make_environment_for_app_script( + app, args=args, args_prefix="ACTION_", workdir=tmp_workdir_for_app + ) env_dict["YNH_ACTION"] = action _, action_script = tempfile.mkstemp(dir=tmp_workdir_for_app) @@ -1984,7 +2007,7 @@ def _is_app_repo_url(string: str) -> bool: string = string.strip() # Dummy test for ssh-based stuff ... should probably be improved somehow - if '@' in string: + if "@" in string: return True return bool(APP_REPO_URL.match(string)) @@ -1992,7 +2015,7 @@ def _is_app_repo_url(string: str) -> bool: def _app_quality(src: str) -> str: """ - app may in fact be an app name, an url, or a path + app may in fact be an app name, an url, or a path """ raw_app_catalog = _load_apps_catalog()["apps"] @@ -2026,13 +2049,15 @@ def _app_quality(src: str) -> str: return "thirdparty" else: if "http://" in src or "https://" in src: - logger.error(f"{src} is not a valid app url: app url are expected to look like https://domain.tld/path/to/repo_ynh") + logger.error( + f"{src} is not a valid app url: app url are expected to look like https://domain.tld/path/to/repo_ynh" + ) raise YunohostValidationError("app_unknown") def _extract_app(src: str) -> Tuple[Dict, str]: """ - src may be an app name, an url, or a path + src may be an app name, an url, or a path """ raw_app_catalog = _load_apps_catalog()["apps"] @@ -2054,8 +2079,8 @@ def _extract_app(src: str) -> Tuple[Dict, str]: revision = "HEAD" # gitlab urls may look like 'https://domain/org/group/repo/-/tree/testing' # compated to github urls looking like 'https://domain/org/repo/tree/testing' - if '/-/' in url: - url = url.replace('/-/', '/') + if "/-/" in url: + url = url.replace("/-/", "/") if "/tree/" in url: url, branch = url.split("/tree/", 1) return _extract_app_from_gitrepo(url, branch, revision, {}) @@ -2064,7 +2089,9 @@ def _extract_app(src: str) -> Tuple[Dict, str]: return _extract_app_from_folder(src) else: if "http://" in src or "https://" in src: - logger.error(f"{src} is not a valid app url: app url are expected to look like https://domain.tld/path/to/repo_ynh") + logger.error( + f"{src} is not a valid app url: app url are expected to look like https://domain.tld/path/to/repo_ynh" + ) raise YunohostValidationError("app_unknown") @@ -2108,7 +2135,9 @@ def _extract_app_from_folder(path: str) -> Tuple[Dict, str]: return manifest, extracted_app_folder -def _extract_app_from_gitrepo(url: str, branch: str, revision: str, app_info: Dict = {}) -> Tuple[Dict, str]: +def _extract_app_from_gitrepo( + url: str, branch: str, revision: str, app_info: Dict = {} +) -> Tuple[Dict, str]: logger.debug(m18n.n("downloading")) @@ -2237,8 +2266,12 @@ def _guess_webapp_path_requirement(app_folder: str) -> str: manifest = _get_manifest_of_app(app_folder) raw_questions = manifest.get("arguments", {}).get("install", {}) - domain_questions = [question for question in raw_questions if question.get("type") == "domain"] - path_questions = [question for question in raw_questions if question.get("type") == "path"] + domain_questions = [ + question for question in raw_questions if question.get("type") == "domain" + ] + path_questions = [ + question for question in raw_questions if question.get("type") == "path" + ] if len(domain_questions) == 0 and len(path_questions) == 0: return "" @@ -2276,7 +2309,9 @@ def _validate_webpath_requirement( _assert_no_conflicting_apps(domain, path, ignore_app=ignore_app) elif path_requirement == "full_domain": - _assert_no_conflicting_apps(domain, "/", full_domain=True, ignore_app=ignore_app) + _assert_no_conflicting_apps( + domain, "/", full_domain=True, ignore_app=ignore_app + ) def _get_conflicting_apps(domain, path, ignore_app=None): @@ -2341,7 +2376,9 @@ def _assert_no_conflicting_apps(domain, path, ignore_app=None, full_domain=False ) -def _make_environment_for_app_script(app, args={}, args_prefix="APP_ARG_", workdir=None): +def _make_environment_for_app_script( + app, args={}, args_prefix="APP_ARG_", workdir=None +): app_setting_path = os.path.join(APPS_SETTING_PATH, app) diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 5664af3a0..cce66597a 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -1348,7 +1348,11 @@ class RestoreManager: app_instance_name -- (string) The app name to restore (no app with this name should be already install) """ - from yunohost.utils.legacy import _patch_legacy_php_versions, _patch_legacy_php_versions_in_settings, _patch_legacy_helpers + from yunohost.utils.legacy import ( + _patch_legacy_php_versions, + _patch_legacy_php_versions_in_settings, + _patch_legacy_helpers, + ) from yunohost.user import user_group_list from yunohost.permission import ( permission_create, @@ -1485,7 +1489,9 @@ class RestoreManager: # Prepare env. var. to pass to script # FIXME : workdir should be a tmp workdir app_workdir = os.path.join(self.work_dir, "apps", app_instance_name, "settings") - env_dict = _make_environment_for_app_script(app_instance_name, workdir=app_workdir) + env_dict = _make_environment_for_app_script( + app_instance_name, workdir=app_workdir + ) env_dict.update( { "YNH_BACKUP_DIR": self.work_dir, @@ -1529,7 +1535,9 @@ class RestoreManager: remove_script = os.path.join(app_scripts_in_archive, "remove") # Setup environment for remove script - env_dict_remove = _make_environment_for_app_script(app_instance_name, workdir=app_workdir) + env_dict_remove = _make_environment_for_app_script( + app_instance_name, workdir=app_workdir + ) remove_operation_logger = OperationLogger( "remove_on_failed_restore", [("app", app_instance_name)], diff --git a/src/yunohost/tests/test_appurl.py b/src/yunohost/tests/test_appurl.py index d50877445..186b76cdf 100644 --- a/src/yunohost/tests/test_appurl.py +++ b/src/yunohost/tests/test_appurl.py @@ -32,17 +32,25 @@ def test_repo_url_definition(): assert _is_app_repo_url("https://github.com/YunoHost-Apps/foobar123_ynh") assert _is_app_repo_url("https://github.com/YunoHost-Apps/foobar123_ynh/") assert _is_app_repo_url("https://github.com/YunoHost-Apps/foobar123_ynh.git") - assert _is_app_repo_url("https://github.com/YunoHost-Apps/foobar123_ynh/tree/testing") - assert _is_app_repo_url("https://github.com/YunoHost-Apps/foobar123_ynh/tree/testing/") + assert _is_app_repo_url( + "https://github.com/YunoHost-Apps/foobar123_ynh/tree/testing" + ) + assert _is_app_repo_url( + "https://github.com/YunoHost-Apps/foobar123_ynh/tree/testing/" + ) assert _is_app_repo_url("https://github.com/YunoHost-Apps/foo-bar-123_ynh") assert _is_app_repo_url("https://github.com/YunoHost-Apps/foo_bar_123_ynh") assert _is_app_repo_url("https://github.com/YunoHost-Apps/FooBar123_ynh") assert _is_app_repo_url("https://github.com/labriqueinternet/vpnclient_ynh") assert _is_app_repo_url("https://framagit.org/YunoHost/apps/nodebb_ynh") - assert _is_app_repo_url("https://framagit.org/YunoHost/apps/nodebb_ynh/-/tree/testing") + assert _is_app_repo_url( + "https://framagit.org/YunoHost/apps/nodebb_ynh/-/tree/testing" + ) assert _is_app_repo_url("https://gitlab.com/yunohost-apps/foobar_ynh") assert _is_app_repo_url("https://code.antopie.org/miraty/qr_ynh") - assert _is_app_repo_url("https://gitlab.domainepublic.net/Neutrinet/neutrinet_ynh/-/tree/unstable") + assert _is_app_repo_url( + "https://gitlab.domainepublic.net/Neutrinet/neutrinet_ynh/-/tree/unstable" + ) assert _is_app_repo_url("git@github.com:YunoHost-Apps/foobar_ynh.git") assert not _is_app_repo_url("github.com/YunoHost-Apps/foobar_ynh") @@ -50,7 +58,9 @@ def test_repo_url_definition(): assert not _is_app_repo_url("https://github.com/YunoHost-Apps/foobar_wat") assert not _is_app_repo_url("https://github.com/YunoHost-Apps/foobar_ynh_wat") assert not _is_app_repo_url("https://github.com/YunoHost-Apps/foobar/tree/testing") - assert not _is_app_repo_url("https://github.com/YunoHost-Apps/foobar_ynh_wat/tree/testing") + assert not _is_app_repo_url( + "https://github.com/YunoHost-Apps/foobar_ynh_wat/tree/testing" + ) assert not _is_app_repo_url("https://framagit.org/YunoHost/apps/") assert not _is_app_repo_url("https://framagit.org/YunoHost/apps/pwet") assert not _is_app_repo_url("https://framagit.org/YunoHost/apps/pwet_foo") diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 671f8768c..e89081abd 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -1151,7 +1151,11 @@ class Migration(object): os.system("systemctl stop slapd") cp("/etc/ldap", f"{backup_folder}/ldap_config", recursive=True) cp("/var/lib/ldap", f"{backup_folder}/ldap_db", recursive=True) - cp("/etc/yunohost/apps", f"{backup_folder}/apps_settings", recursive=True) + cp( + "/etc/yunohost/apps", + f"{backup_folder}/apps_settings", + recursive=True, + ) except Exception as e: raise YunohostError( "migration_ldap_can_not_backup_before_migration", error=str(e) @@ -1170,7 +1174,11 @@ class Migration(object): rm("/etc/ldap/slapd.d", force=True, recursive=True) cp(f"{backup_folder}/ldap_config", "/etc/ldap", recursive=True) cp(f"{backup_folder}/ldap_db", "/var/lib/ldap", recursive=True) - cp(f"{backup_folder}/apps_settings", "/etc/yunohost/apps", recursive=True) + cp( + f"{backup_folder}/apps_settings", + "/etc/yunohost/apps", + recursive=True, + ) os.system("systemctl start slapd") rm(backup_folder, force=True, recursive=True) logger.info(m18n.n("migration_ldap_rollback_success")) diff --git a/src/yunohost/utils/legacy.py b/src/yunohost/utils/legacy.py index 7ae98bed8..87c163f1b 100644 --- a/src/yunohost/utils/legacy.py +++ b/src/yunohost/utils/legacy.py @@ -4,7 +4,13 @@ import glob from moulinette import m18n from moulinette.core import MoulinetteError from moulinette.utils.log import getActionLogger -from moulinette.utils.filesystem import read_file, write_to_file, write_to_json, write_to_yaml, read_yaml +from moulinette.utils.filesystem import ( + read_file, + write_to_file, + write_to_json, + write_to_yaml, + read_yaml, +) from yunohost.user import user_list from yunohost.app import (