mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
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}
This commit is contained in:
parent
ecbd63636b
commit
49f6394233
9 changed files with 40 additions and 35 deletions
|
@ -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...) #
|
||||
|
|
|
@ -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("<cmd>", "'").replace("</cmd>", "'")
|
||||
s = html_tags.sub('', s.replace("<br>","\n"))
|
||||
s = html_tags.sub('', s.replace("<br>", "\n"))
|
||||
else:
|
||||
s = s.replace("<cmd>", "<code class='cmd'>").replace("</cmd>", "</code>")
|
||||
# Make it so that links open in new tabs
|
||||
|
|
|
@ -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<host>[a-z_\-\.]+)[\s]+([0-9]+[\s]+)?IN[\s]+TXT[\s]+'
|
||||
'[^"]*"v=(?P<v>[^";]+);'
|
||||
'[\s"]*k=(?P<k>[^";]+);'
|
||||
'[\s"]*p=(?P<p>[^";]+)'), dkim_content, re.M | re.S
|
||||
'[^"]*"v=(?P<v>[^";]+);'
|
||||
r'[\s"]*k=(?P<k>[^";]+);'
|
||||
'[\s"]*p=(?P<p>[^";]+)'), dkim_content, re.M | re.S
|
||||
)
|
||||
else:
|
||||
dkim = re.match((
|
||||
r'^(?P<host>[a-z_\-\.]+)[\s]+([0-9]+[\s]+)?IN[\s]+TXT[\s]+'
|
||||
'[^"]*"v=(?P<v>[^";]+);'
|
||||
'[\s"]*h=(?P<h>[^";]+);'
|
||||
'[\s"]*k=(?P<k>[^";]+);'
|
||||
'[\s"]*p=(?P<p>[^";]+)'), dkim_content, re.M | re.S
|
||||
'[^"]*"v=(?P<v>[^";]+);'
|
||||
r'[\s"]*h=(?P<h>[^";]+);'
|
||||
r'[\s"]*k=(?P<k>[^";]+);'
|
||||
'[\s"]*p=(?P<p>[^";]+)'), dkim_content, re.M | re.S
|
||||
)
|
||||
|
||||
if not dkim:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -654,7 +654,6 @@ def _tail(file, n):
|
|||
avg_line_length = 74
|
||||
to_read = n
|
||||
|
||||
|
||||
try:
|
||||
if file.endswith(".gz"):
|
||||
import gzip
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue