From 49f63942337a5953b6b6345d553b697820045225 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 3 Sep 2020 17:31:52 +0200 Subject: [PATCH] autopep8 --in-place -a -a -a --ignore E402,E501,E722 -r src/yunohost/{__init__.py,certificate.py,diagnosis.py,domain.py,dyndns.py,firewall.py,hook.py,log.py,regenconf.py,service.py,settings.py,ssh.py,tools.py} --- src/yunohost/__init__.py | 2 +- src/yunohost/diagnosis.py | 9 +++++---- src/yunohost/domain.py | 16 ++++++++-------- src/yunohost/hook.py | 20 ++++++++++---------- src/yunohost/log.py | 2 +- src/yunohost/regenconf.py | 2 +- src/yunohost/service.py | 1 - src/yunohost/settings.py | 10 +++++++--- src/yunohost/tools.py | 13 +++++++------ 9 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/yunohost/__init__.py b/src/yunohost/__init__.py index ce505ffd9..d909ad9e2 100644 --- a/src/yunohost/__init__.py +++ b/src/yunohost/__init__.py @@ -91,7 +91,7 @@ def init_logging(interface="cli", logfile = os.path.join(logdir, "yunohost-%s.log" % interface) if not os.path.isdir(logdir): - os.makedirs(logdir, 0750) + os.makedirs(logdir, 0o750) # ####################################################################### # # Logging configuration for CLI (or any other interface than api...) # diff --git a/src/yunohost/diagnosis.py b/src/yunohost/diagnosis.py index 23884a53d..e4dd84f6d 100644 --- a/src/yunohost/diagnosis.py +++ b/src/yunohost/diagnosis.py @@ -176,7 +176,7 @@ def diagnosis_run(categories=[], force=False, except_if_never_ran_yet=False, ema code, report = hook_exec(path, args={"force": force}, env=None) except Exception: import traceback - logger.error(m18n.n("diagnosis_failed_for_category", category=category, error='\n'+traceback.format_exc())) + logger.error(m18n.n("diagnosis_failed_for_category", category=category, error='\n' + traceback.format_exc())) else: diagnosed_categories.append(category) if report != {}: @@ -403,11 +403,11 @@ class Diagnoser(): Diagnoser.i18n(new_report) add_ignore_flag_to_issues(new_report) - errors = [item for item in new_report["items"] if item["status"] == "ERROR" and not item["ignored"]] + errors = [item for item in new_report["items"] if item["status"] == "ERROR" and not item["ignored"]] warnings = [item for item in new_report["items"] if item["status"] == "WARNING" and not item["ignored"]] errors_ignored = [item for item in new_report["items"] if item["status"] == "ERROR" and item["ignored"]] warning_ignored = [item for item in new_report["items"] if item["status"] == "WARNING" and item["ignored"]] - ignored_msg = " " + m18n.n("diagnosis_ignored_issues", nb_ignored=len(errors_ignored+warning_ignored)) if errors_ignored or warning_ignored else "" + ignored_msg = " " + m18n.n("diagnosis_ignored_issues", nb_ignored=len(errors_ignored + warning_ignored)) if errors_ignored or warning_ignored else "" if errors and warnings: logger.error(m18n.n("diagnosis_found_errors_and_warnings", errors=len(errors), warnings=len(warnings), category=new_report["description"]) + ignored_msg) @@ -477,6 +477,7 @@ class Diagnoser(): meta_data.update(item.get("data", {})) html_tags = re.compile(r'<[^>]+>') + def m18n_(info): if not isinstance(info, tuple) and not isinstance(info, list): info = (info, {}) @@ -485,7 +486,7 @@ class Diagnoser(): # In cli, we remove the html tags if msettings.get("interface") != "api" or force_remove_html_tags: s = s.replace("", "'").replace("", "'") - s = html_tags.sub('', s.replace("
","\n")) + s = html_tags.sub('', s.replace("
", "\n")) else: s = s.replace("", "").replace("", "") # Make it so that links open in new tabs diff --git a/src/yunohost/domain.py b/src/yunohost/domain.py index e1d2b1649..160c8f622 100644 --- a/src/yunohost/domain.py +++ b/src/yunohost/domain.py @@ -89,7 +89,7 @@ def domain_add(operation_logger, domain, dyndns=False): raise YunohostError('domain_exists') operation_logger.start() - + # Lower domain to avoid some edge cases issues # See: https://forum.yunohost.org/t/invalid-domain-causes-diagnosis-web-to-fail-fr-on-demand/11765 domain = domain.lower() @@ -614,17 +614,17 @@ def _get_DKIM(domain): if is_legacy_format: dkim = re.match(( r'^(?P[a-z_\-\.]+)[\s]+([0-9]+[\s]+)?IN[\s]+TXT[\s]+' - '[^"]*"v=(?P[^";]+);' - '[\s"]*k=(?P[^";]+);' - '[\s"]*p=(?P

[^";]+)'), dkim_content, re.M | re.S + '[^"]*"v=(?P[^";]+);' + r'[\s"]*k=(?P[^";]+);' + '[\s"]*p=(?P

[^";]+)'), dkim_content, re.M | re.S ) else: dkim = re.match(( r'^(?P[a-z_\-\.]+)[\s]+([0-9]+[\s]+)?IN[\s]+TXT[\s]+' - '[^"]*"v=(?P[^";]+);' - '[\s"]*h=(?P[^";]+);' - '[\s"]*k=(?P[^";]+);' - '[\s"]*p=(?P

[^";]+)'), dkim_content, re.M | re.S + '[^"]*"v=(?P[^";]+);' + r'[\s"]*h=(?P[^";]+);' + r'[\s"]*k=(?P[^";]+);' + '[\s"]*p=(?P

[^";]+)'), dkim_content, re.M | re.S ) if not dkim: diff --git a/src/yunohost/hook.py b/src/yunohost/hook.py index b57300f54..f939f2c99 100644 --- a/src/yunohost/hook.py +++ b/src/yunohost/hook.py @@ -270,9 +270,9 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None, # Validate callbacks if not callable(pre_callback): - pre_callback = lambda name, priority, path, args: args + def pre_callback(name, priority, path, args): return args if not callable(post_callback): - post_callback = lambda name, priority, path, succeed: None + def post_callback(name, priority, path, succeed): return None # Iterate over hooks and execute them for priority in sorted(hooks_dict): @@ -283,7 +283,7 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None, hook_args = pre_callback(name=name, priority=priority, path=path, args=args) hook_return = hook_exec(path, args=hook_args, chdir=chdir, env=env, - no_trace=no_trace, raise_on_error=True)[1] + no_trace=no_trace, raise_on_error=True)[1] except YunohostError as e: state = 'failed' hook_return = {} @@ -293,9 +293,9 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None, else: post_callback(name=name, priority=priority, path=path, succeed=True) - if not name in result: + if name not in result: result[name] = {} - result[name][path] = {'state' : state, 'stdreturn' : hook_return } + result[name][path] = {'state': state, 'stdreturn': hook_return} return result @@ -446,17 +446,17 @@ def _hook_exec_python(path, args, env, loggers): dir_ = os.path.dirname(path) name = os.path.splitext(os.path.basename(path))[0] - if not dir_ in sys.path: + if dir_ not in sys.path: sys.path = [dir_] + sys.path module = import_module(name) ret = module.main(args, env, loggers) # # Assert that the return is a (int, dict) tuple assert isinstance(ret, tuple) \ - and len(ret) == 2 \ - and isinstance(ret[0],int) \ - and isinstance(ret[1],dict), \ - "Module %s did not return a (int, dict) tuple !" % module + and len(ret) == 2 \ + and isinstance(ret[0], int) \ + and isinstance(ret[1], dict), \ + "Module %s did not return a (int, dict) tuple !" % module return ret diff --git a/src/yunohost/log.py b/src/yunohost/log.py index 892105c6b..88da1ebf0 100644 --- a/src/yunohost/log.py +++ b/src/yunohost/log.py @@ -270,7 +270,7 @@ def log_display(path, number=None, share=False, filter_irrelevant=False, with_su if os.path.exists(log_path): from yunohost.service import _tail if number and filters: - logs = _tail(log_path, int(number*4)) + logs = _tail(log_path, int(number * 4)) elif number: logs = _tail(log_path, int(number)) else: diff --git a/src/yunohost/regenconf.py b/src/yunohost/regenconf.py index 7f4f73247..6b369fc8c 100644 --- a/src/yunohost/regenconf.py +++ b/src/yunohost/regenconf.py @@ -47,7 +47,7 @@ logger = log.getActionLogger('yunohost.regenconf') # FIXME : check for all reference of 'service' close to operation_logger stuff @is_unit_operation([('names', 'configuration')]) def regen_conf(operation_logger, names=[], with_diff=False, force=False, dry_run=False, - list_pending=False): + list_pending=False): """ Regenerate the configuration file(s) diff --git a/src/yunohost/service.py b/src/yunohost/service.py index 522395718..084df471d 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -654,7 +654,6 @@ def _tail(file, n): avg_line_length = 74 to_read = n - try: if file.endswith(".gz"): import gzip diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index 9b8589d35..0f8860529 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -15,6 +15,7 @@ logger = getActionLogger('yunohost.settings') SETTINGS_PATH = "/etc/yunohost/settings.json" SETTINGS_PATH_OTHER_LOCATION = "/etc/yunohost/settings-%s.json" + def is_boolean(value): """ Ensure a string value is intended as a boolean @@ -60,11 +61,11 @@ DEFAULTS = OrderedDict([ ("service.ssh.allow_deprecated_dsa_hostkey", {"type": "bool", "default": False}), ("security.ssh.compatibility", {"type": "enum", "default": "modern", - "choices": ["intermediate", "modern"]}), + "choices": ["intermediate", "modern"]}), ("security.nginx.compatibility", {"type": "enum", "default": "intermediate", - "choices": ["intermediate", "modern"]}), + "choices": ["intermediate", "modern"]}), ("security.postfix.compatibility", {"type": "enum", "default": "intermediate", - "choices": ["intermediate", "modern"]}), + "choices": ["intermediate", "modern"]}), ("pop3.enabled", {"type": "bool", "default": False}), ("smtp.allow_ipv6", {"type": "bool", "default": True}), @@ -321,17 +322,20 @@ def reconfigure_nginx(setting_name, old_value, new_value): if old_value != new_value: service_regen_conf(names=['nginx']) + @post_change_hook("security.ssh.compatibility") def reconfigure_ssh(setting_name, old_value, new_value): if old_value != new_value: service_regen_conf(names=['ssh']) + @post_change_hook("smtp.allow_ipv6") @post_change_hook("security.postfix.compatibility") def reconfigure_postfix(setting_name, old_value, new_value): if old_value != new_value: service_regen_conf(names=['postfix']) + @post_change_hook("pop3.enabled") def reconfigure_dovecot(setting_name, old_value, new_value): dovecot_package = 'dovecot-pop3d' diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 2e90b38ee..fcc2810d6 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -51,9 +51,11 @@ MIGRATIONS_STATE_PATH = "/etc/yunohost/migrations.yaml" logger = getActionLogger('yunohost.tools') + def tools_versions(): return ynh_packages_version() + def tools_ldapinit(): """ YunoHost LDAP initialization @@ -146,7 +148,7 @@ def tools_adminpw(new_password, check_strength=True): ldap = _get_ldap_interface() try: - ldap.update("cn=admin", {"userPassword": [ new_hash ], }) + ldap.update("cn=admin", {"userPassword": [new_hash], }) except: logger.exception('unable to change admin password') raise YunohostError('admin_password_change_failed') @@ -599,7 +601,6 @@ def tools_upgrade(operation_logger, apps=None, system=False, allow_yunohost_upgr logger.debug("Running apt command :\n{}".format(dist_upgrade)) - def is_relevant(l): irrelevants = [ "service sudo-ldap already provided", @@ -936,7 +937,7 @@ def _migrate_legacy_migration_json(): # Extract the list of migration ids from . import data_migrations migrations_path = data_migrations.__path__[0] - migration_files = filter(lambda x: re.match("^\d+_[a-zA-Z0-9_]+\.py$", x), os.listdir(migrations_path)) + migration_files = filter(lambda x: re.match(r"^\d+_[a-zA-Z0-9_]+\.py$", x), os.listdir(migrations_path)) # (here we remove the .py extension and make sure the ids are sorted) migration_ids = sorted([f.rsplit(".", 1)[0] for f in migration_files]) @@ -985,7 +986,7 @@ def _get_migrations_list(): # (in particular, pending migrations / not already ran are not listed states = tools_migrations_state()["migrations"] - for migration_file in filter(lambda x: re.match("^\d+_[a-zA-Z0-9_]+\.py$", x), os.listdir(migrations_path)): + for migration_file in filter(lambda x: re.match(r"^\d+_[a-zA-Z0-9_]+\.py$", x), os.listdir(migrations_path)): m = _load_migration(migration_file) m.state = states.get(m.id, "pending") migrations.append(m) @@ -1004,7 +1005,7 @@ def _get_migration_by_name(migration_name): raise AssertionError("Unable to find migration with name %s" % migration_name) migrations_path = data_migrations.__path__[0] - migrations_found = filter(lambda x: re.match("^\d+_%s\.py$" % migration_name, x), os.listdir(migrations_path)) + migrations_found = filter(lambda x: re.match(r"^\d+_%s\.py$" % migration_name, x), os.listdir(migrations_path)) assert len(migrations_found) == 1, "Unable to find migration with name %s" % migration_name @@ -1048,7 +1049,7 @@ class Migration(object): # Those are to be implemented by daughter classes mode = "auto" - dependencies = [] # List of migration ids required before running this migration + dependencies = [] # List of migration ids required before running this migration @property def disclaimer(self):