From 05b1a8f96e45002d9abebe74a620d11da8b14d4e Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 30 Oct 2020 15:22:40 +0100 Subject: [PATCH] autopep8 --in-place -a -a -a --ignore E402,E501,E722 -r src/yunohost/*.py --- src/yunohost/app.py | 55 +++++++++++++++++++------------------- src/yunohost/backup.py | 23 ++++++++-------- src/yunohost/domain.py | 2 +- src/yunohost/permission.py | 6 ++--- 4 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index e0d8894f9..86073f5e9 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -670,15 +670,15 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu if confirm in ["danger", "thirdparty"]: answer = msignals.prompt(m18n.n('confirm_app_install_' + confirm, - answers='Yes, I understand'), - color="red") + answers='Yes, I understand'), + color="red") if answer != "Yes, I understand": raise YunohostError("aborting") else: answer = msignals.prompt(m18n.n('confirm_app_install_' + confirm, - answers='Y/N'), - color="yellow") + answers='Y/N'), + color="yellow") if answer.upper() != "Y": raise YunohostError("aborting") @@ -816,7 +816,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu # Initialize the main permission for the app # After the install, if apps don't have a domain and path defined, the default url '/' is removed from the permission - permission_create(app_instance_name+".main", allowed=["all_users"], label=label, show_tile=False, protected=False) + permission_create(app_instance_name + ".main", allowed=["all_users"], label=label, show_tile=False, protected=False) # Execute the app install script install_failed = True @@ -901,7 +901,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu # Remove all permission in LDAP for permission_name in user_permission_list()["permissions"].keys(): - if permission_name.startswith(app_instance_name+"."): + if permission_name.startswith(app_instance_name + "."): permission_delete(permission_name, force=True, sync_perm=False) if remove_retcode != 0: @@ -1074,7 +1074,7 @@ def app_remove(operation_logger, app): # Remove all permission in LDAP for permission_name in user_permission_list()["permissions"].keys(): - if permission_name.startswith(app+"."): + if permission_name.startswith(app + "."): permission_delete(permission_name, force=True, sync_perm=False) permission_sync_to_user() @@ -1096,7 +1096,7 @@ def app_addaccess(apps, users=[]): output = {} for app in apps: - permission = user_permission_update(app+".main", add=users, remove="all_users") + permission = user_permission_update(app + ".main", add=users, remove="all_users") output[app] = permission["corresponding_users"] return {'allowed_users': output} @@ -1117,7 +1117,7 @@ def app_removeaccess(apps, users=[]): output = {} for app in apps: - permission = user_permission_update(app+".main", remove=users) + permission = user_permission_update(app + ".main", remove=users) output[app] = permission["corresponding_users"] return {'allowed_users': output} @@ -1137,7 +1137,7 @@ def app_clearaccess(apps): output = {} for app in apps: - permission = user_permission_reset(app+".main") + permission = user_permission_reset(app + ".main") output[app] = permission["corresponding_users"] return {'allowed_users': output} @@ -1209,7 +1209,7 @@ def app_setting(app, key, value=None, delete=False): # (unprotected, protected, skipped_uri/regex) # - is_legacy_permission_setting = any(key.startswith(word+"_") for word in ["unprotected", "protected", "skipped"]) + is_legacy_permission_setting = any(key.startswith(word + "_") for word in ["unprotected", "protected", "skipped"]) if is_legacy_permission_setting: @@ -1286,7 +1286,6 @@ def app_setting(app, key, value=None, delete=False): show_tile=False, protected=True) - # # Regular setting management # @@ -1356,16 +1355,16 @@ def app_ssowatconf(): "show_tile": False, "auth_header": False, "public": True, - "uris": \ - [domain + '/yunohost/admin' for domain in domains] + \ - [domain + '/yunohost/api' for domain in domains] + [ - "re:^[^/]*/%.well%-known/ynh%-diagnosis/.*$", - "re:^[^/]*/%.well%-known/acme%-challenge/.*$", - "re:^[^/]*/%.well%-known/autoconfig/mail/config%-v1%.1%.xml.*$" - ] + "uris": + [domain + '/yunohost/admin' for domain in domains] + + [domain + '/yunohost/api' for domain in domains] + [ + "re:^[^/]*/%.well%-known/ynh%-diagnosis/.*$", + "re:^[^/]*/%.well%-known/acme%-challenge/.*$", + "re:^[^/]*/%.well%-known/autoconfig/mail/config%-v1%.1%.xml.*$" + ] } } - redirected_regex = {main_domain + '/yunohost[\/]?$': 'https://' + main_domain + '/yunohost/sso/'} + redirected_regex = {main_domain + r'/yunohost[\/]?$': 'https://' + main_domain + '/yunohost/sso/'} redirected_urls = {} for app in _installed_apps(): @@ -1825,7 +1824,7 @@ def _get_app_config_panel(app_id): "panel": [], } - panels = filter(lambda (key, value): key not in ("name", "version") and isinstance(value, OrderedDict), + panels = filter(lambda key_value: key_value[0] not in ("name", "version") and isinstance(key_value[1], OrderedDict), toml_config_panel.items()) for key, value in panels: @@ -1835,7 +1834,7 @@ def _get_app_config_panel(app_id): "sections": [], } - sections = filter(lambda (k, v): k not in ("name",) and isinstance(v, OrderedDict), + sections = filter(lambda k_v1: k_v1[0] not in ("name",) and isinstance(k_v1[1], OrderedDict), value.items()) for section_key, section_value in sections: @@ -1845,7 +1844,7 @@ def _get_app_config_panel(app_id): "options": [], } - options = filter(lambda (k, v): k not in ("name",) and isinstance(v, OrderedDict), + options = filter(lambda k_v: k_v[0] not in ("name",) and isinstance(k_v[1], OrderedDict), section_value.items()) for option_key, option_value in options: @@ -1884,12 +1883,12 @@ def _get_app_settings(app_id): settings = yaml.load(f) # If label contains unicode char, this may later trigger issues when building strings... # FIXME: this should be propagated to read_yaml so that this fix applies everywhere I think... - settings = {k:_encode_string(v) for k,v in settings.items()} + settings = {k: _encode_string(v) for k, v in settings.items()} if app_id == settings['id']: return settings except (IOError, TypeError, KeyError): logger.error(m18n.n('app_not_correctly_installed', - app=app_id)) + app=app_id)) return {} @@ -3095,7 +3094,7 @@ def _patch_legacy_helpers(app_folder): }, # We can't migrate easily port-available # .. but at the time of writing this code, only two non-working apps are using it. - "yunohost tools port-available": {"important":True}, + "yunohost tools port-available": {"important": True}, # Replace # yunohost app checkurl "${domain}${path_url}" -a "${app}" # by @@ -3151,7 +3150,7 @@ def _patch_legacy_helpers(app_folder): if filename.split("/")[-1] in ["install", "remove", "upgrade", "backup", "restore"]: source_helpers = "source /usr/share/yunohost/helpers" if source_helpers not in content: - content.replace("#!/bin/bash", "#!/bin/bash\n"+source_helpers) + content.replace("#!/bin/bash", "#!/bin/bash\n" + source_helpers) if source_helpers not in content: content = source_helpers + "\n" + content @@ -3160,4 +3159,4 @@ def _patch_legacy_helpers(app_folder): if show_warning: # And complain about those damn deprecated helpers - logger.error("/!\ Packagers ! This app uses a very old deprecated helpers ... Yunohost automatically patched the helpers to use the new recommended practice, but please do consider fixing the upstream code right now ...") + logger.error(r"/!\ Packagers ! This app uses a very old deprecated helpers ... Yunohost automatically patched the helpers to use the new recommended practice, but please do consider fixing the upstream code right now ...") diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 0b851b88b..cafe452ea 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -882,7 +882,6 @@ class RestoreManager(): logger.debug("executing the post-install...") tools_postinstall(domain, 'Yunohost', True) - def clean(self): """ End a restore operations by cleaning the working directory and @@ -951,7 +950,7 @@ class RestoreManager(): continue hook_paths = self.info['system'][system_part]['paths'] - hook_paths = [ 'hooks/restore/%s' % os.path.basename(p) for p in hook_paths ] + hook_paths = ['hooks/restore/%s' % os.path.basename(p) for p in hook_paths] # Otherwise, add it from the archive to the system # FIXME: Refactor hook_add and use it instead @@ -1200,7 +1199,7 @@ class RestoreManager(): # do the migration 0011 : setup group and permission # # Legacy code - if not "all_users" in user_group_list()["groups"].keys(): + if "all_users" not in user_group_list()["groups"].keys(): from yunohost.utils.legacy import SetupGroupPermissions # Update LDAP schema restart slapd logger.info(m18n.n("migration_0011_update_LDAP_schema")) @@ -1225,7 +1224,6 @@ class RestoreManager(): permission_sync_to_user() - def _restore_apps(self): """Restore all apps targeted""" @@ -1423,7 +1421,7 @@ class RestoreManager(): # Remove all permission in LDAP for this app for permission_name in user_permission_list()["permissions"].keys(): - if permission_name.startswith(app_instance_name+"."): + if permission_name.startswith(app_instance_name + "."): permission_delete(permission_name, force=True) # TODO Cleaning app hooks @@ -1518,7 +1516,7 @@ class BackupMethod(object): Return a BackupMethod instance """ - known_methods = {c.method_name:c for c in BackupMethod.__subclasses__()} + known_methods = {c.method_name: c for c in BackupMethod.__subclasses__()} backup_method = known_methods.get(method, CustomBackupMethod) return backup_method(manager, method=method, **kwargs) @@ -1780,14 +1778,14 @@ class CopyBackupMethod(BackupMethod): filesystem.mkdir(self.work_dir, parent=True) ret = subprocess.call(["mount", "-r", "--rbind", self.repo, - self.work_dir]) + self.work_dir]) if ret == 0: return logger.warning("Could not mount the backup in readonly mode with --rbind ... Unmounting") # FIXME : Does this stuff really works ? '&&' is going to be interpreted as an argument for mounpoint here ... Not as a classical '&&' ... subprocess.call(["mountpoint", "-q", self.work_dir, - "&&", "umount", "-R", self.work_dir]) + "&&", "umount", "-R", self.work_dir]) raise YunohostError('backup_cant_mount_uncompress_archive') def copy(self, file, target): @@ -1911,12 +1909,12 @@ class TarBackupMethod(BackupMethod): system_part = system_part.replace("_", "/") + "/" subdir_and_files = [ tarinfo for tarinfo in tar.getmembers() - if tarinfo.name.startswith(leading_dot+system_part) + if tarinfo.name.startswith(leading_dot + system_part) ] tar.extractall(members=subdir_and_files, path=self.work_dir) subdir_and_files = [ tarinfo for tarinfo in tar.getmembers() - if tarinfo.name.startswith(leading_dot+"hooks/restore/") + if tarinfo.name.startswith(leading_dot + "hooks/restore/") ] tar.extractall(members=subdir_and_files, path=self.work_dir) @@ -1924,7 +1922,7 @@ class TarBackupMethod(BackupMethod): for app in apps_targets: subdir_and_files = [ tarinfo for tarinfo in tar.getmembers() - if tarinfo.name.startswith(leading_dot+"apps/" + app) + if tarinfo.name.startswith(leading_dot + "apps/" + app) ] tar.extractall(members=subdir_and_files, path=self.work_dir) @@ -2176,6 +2174,7 @@ def backup_list(with_info=False, human_readable=False): archives = set([os.path.realpath(archive) for archive in archives]) archives = sorted(archives, key=lambda x: os.path.getctime(x)) # Extract only filename without the extension + def remove_extension(f): if f.endswith(".tar.gz"): return os.path.basename(f)[:-len(".tar.gz")] @@ -2192,7 +2191,7 @@ def backup_list(with_info=False, human_readable=False): logger.warning(str(e)) except Exception as e: import traceback - logger.warning("Could not check infos for archive %s: %s" % (archive, '\n'+traceback.format_exc())) + logger.warning("Could not check infos for archive %s: %s" % (archive, '\n' + traceback.format_exc())) archives = d diff --git a/src/yunohost/domain.py b/src/yunohost/domain.py index 9aa6d0c70..88fd9e3e9 100644 --- a/src/yunohost/domain.py +++ b/src/yunohost/domain.py @@ -76,7 +76,7 @@ def domain_list(exclude_subdomains=False): result_list = sorted(result_list, cmp_domain) return {'domains': result_list} - + return { 'domains': result_list, 'main': _get_maindomain() diff --git a/src/yunohost/permission.py b/src/yunohost/permission.py index 060a00e6a..8a5ef7260 100644 --- a/src/yunohost/permission.py +++ b/src/yunohost/permission.py @@ -140,8 +140,8 @@ def user_permission_update(operation_logger, permission, add=None, remove=None, raise YunohostError('permission_require_account', permission=permission) # Refuse to add "visitors" to protected permission - if ((add and "visitors" in add and existing_permission["protected"]) or \ - (remove and "visitors" in remove and existing_permission["protected"])) and not force: + if ((add and "visitors" in add and existing_permission["protected"]) or + (remove and "visitors" in remove and existing_permission["protected"])) and not force: raise YunohostError('permission_protected', permission=permission) # Fetch currently allowed groups for this permission @@ -447,7 +447,7 @@ def permission_url(operation_logger, permission, ldap.update('cn=%s,ou=permission' % permission, {'URL': [url] if url is not None else [], 'additionalUrls': new_additional_urls, 'authHeader': [str(auth_header).upper()], - 'showTile': [str(show_tile).upper()],}) + 'showTile': [str(show_tile).upper()], }) except Exception as e: raise YunohostError('permission_update_failed', permission=permission, error=e)