mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[CI] Format code with Black
This commit is contained in:
parent
3779b9203a
commit
b9060da750
19 changed files with 106 additions and 92 deletions
|
@ -60,7 +60,8 @@ def autofix_i18n_placeholders():
|
||||||
k[0] for k in re.findall(r"{(\w+)(:\w)?}", this_locale[key])
|
k[0] for k in re.findall(r"{(\w+)(:\w)?}", this_locale[key])
|
||||||
]
|
]
|
||||||
if any(k not in subkeys_in_ref for k in subkeys_in_this_locale):
|
if any(k not in subkeys_in_ref for k in subkeys_in_this_locale):
|
||||||
raise Exception("""\n
|
raise Exception(
|
||||||
|
"""\n
|
||||||
==========================
|
==========================
|
||||||
Format inconsistency for string {key} in {locale_file}:"
|
Format inconsistency for string {key} in {locale_file}:"
|
||||||
en.json -> {string}
|
en.json -> {string}
|
||||||
|
@ -71,7 +72,8 @@ Please fix it manually !
|
||||||
string=string.encode("utf-8"),
|
string=string.encode("utf-8"),
|
||||||
locale_file=locale_file,
|
locale_file=locale_file,
|
||||||
translated_string=this_locale[key].encode("utf-8"),
|
translated_string=this_locale[key].encode("utf-8"),
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if fixed_stuff:
|
if fixed_stuff:
|
||||||
json.dump(
|
json.dump(
|
||||||
|
@ -86,7 +88,6 @@ Please fix it manually !
|
||||||
|
|
||||||
|
|
||||||
def autofix_orthotypography_and_standardized_words():
|
def autofix_orthotypography_and_standardized_words():
|
||||||
|
|
||||||
def reformat(lang, transformations):
|
def reformat(lang, transformations):
|
||||||
|
|
||||||
locale = open(f"{LOCALE_FOLDER}{lang}.json").read()
|
locale = open(f"{LOCALE_FOLDER}{lang}.json").read()
|
||||||
|
|
|
@ -28,7 +28,7 @@ def cli(debug, quiet, output_as, timeout, args, parser):
|
||||||
locales_dir="/usr/share/yunohost/locales/",
|
locales_dir="/usr/share/yunohost/locales/",
|
||||||
output_as=output_as,
|
output_as=output_as,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
top_parser=parser
|
top_parser=parser,
|
||||||
)
|
)
|
||||||
sys.exit(ret)
|
sys.exit(ret)
|
||||||
|
|
||||||
|
|
11
src/app.py
11
src/app.py
|
@ -1425,7 +1425,7 @@ def app_action_run(operation_logger, app, action, args=None):
|
||||||
actions = {x["id"]: x for x in actions}
|
actions = {x["id"]: x for x in actions}
|
||||||
|
|
||||||
if action not in actions:
|
if action not in actions:
|
||||||
available_actions = ", ".join(actions.keys()),
|
available_actions = (", ".join(actions.keys()),)
|
||||||
raise YunohostValidationError(
|
raise YunohostValidationError(
|
||||||
f"action '{action}' not available for app '{app}', available actions are: {available_actions}",
|
f"action '{action}' not available for app '{app}', available actions are: {available_actions}",
|
||||||
raw_msg=True,
|
raw_msg=True,
|
||||||
|
@ -2416,10 +2416,15 @@ def unstable_apps():
|
||||||
|
|
||||||
for infos in app_list(full=True)["apps"]:
|
for infos in app_list(full=True)["apps"]:
|
||||||
|
|
||||||
if not infos.get("from_catalog") or infos.get("from_catalog").get("state") in [
|
if (
|
||||||
|
not infos.get("from_catalog")
|
||||||
|
or infos.get("from_catalog").get("state")
|
||||||
|
in [
|
||||||
"inprogress",
|
"inprogress",
|
||||||
"notworking",
|
"notworking",
|
||||||
] or infos["id"] in deprecated_apps:
|
]
|
||||||
|
or infos["id"] in deprecated_apps
|
||||||
|
):
|
||||||
output.append(infos["id"])
|
output.append(infos["id"])
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
|
@ -103,7 +103,9 @@ def _initialize_apps_catalog_system():
|
||||||
)
|
)
|
||||||
write_to_yaml(APPS_CATALOG_CONF, default_apps_catalog_list)
|
write_to_yaml(APPS_CATALOG_CONF, default_apps_catalog_list)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise YunohostError(f"Could not initialize the apps catalog system... : {e}", raw_msg=True)
|
raise YunohostError(
|
||||||
|
f"Could not initialize the apps catalog system... : {e}", raw_msg=True
|
||||||
|
)
|
||||||
|
|
||||||
logger.success(m18n.n("apps_catalog_init_success"))
|
logger.success(m18n.n("apps_catalog_init_success"))
|
||||||
|
|
||||||
|
@ -119,7 +121,9 @@ def _read_apps_catalog_list():
|
||||||
# by returning [] if list_ is None
|
# by returning [] if list_ is None
|
||||||
return list_ if list_ else []
|
return list_ if list_ else []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise YunohostError(f"Could not read the apps_catalog list ... : {e}", raw_msg=True)
|
raise YunohostError(
|
||||||
|
f"Could not read the apps_catalog list ... : {e}", raw_msg=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _actual_apps_catalog_api_url(base_url):
|
def _actual_apps_catalog_api_url(base_url):
|
||||||
|
@ -172,7 +176,10 @@ def _update_apps_catalog():
|
||||||
try:
|
try:
|
||||||
write_to_json(cache_file, apps_catalog_content)
|
write_to_json(cache_file, apps_catalog_content)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise YunohostError(f"Unable to write cache data for {apps_catalog_id} apps_catalog : {e}", raw_msg=True)
|
raise YunohostError(
|
||||||
|
f"Unable to write cache data for {apps_catalog_id} apps_catalog : {e}",
|
||||||
|
raw_msg=True,
|
||||||
|
)
|
||||||
|
|
||||||
logger.success(m18n.n("apps_catalog_update_success"))
|
logger.success(m18n.n("apps_catalog_update_success"))
|
||||||
|
|
||||||
|
@ -220,7 +227,9 @@ def _load_apps_catalog():
|
||||||
# in which case we keep only the first one found)
|
# in which case we keep only the first one found)
|
||||||
if app in merged_catalog["apps"]:
|
if app in merged_catalog["apps"]:
|
||||||
other_catalog = merged_catalog["apps"][app]["repository"]
|
other_catalog = merged_catalog["apps"][app]["repository"]
|
||||||
logger.warning(f"Duplicate app {app} found between apps catalog {apps_catalog_id} and {other_catalog}")
|
logger.warning(
|
||||||
|
f"Duplicate app {app} found between apps catalog {apps_catalog_id} and {other_catalog}"
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
info["repository"] = apps_catalog_id
|
info["repository"] = apps_catalog_id
|
||||||
|
|
|
@ -866,7 +866,7 @@ class RestoreManager:
|
||||||
from_version = self.info.get("from_yunohost_version", "")
|
from_version = self.info.get("from_yunohost_version", "")
|
||||||
# Remove any '~foobar' in the version ... c.f ~alpha, ~beta version during
|
# Remove any '~foobar' in the version ... c.f ~alpha, ~beta version during
|
||||||
# early dev for next debian version
|
# early dev for next debian version
|
||||||
from_version = re.sub(r'~\w+', '', from_version)
|
from_version = re.sub(r"~\w+", "", from_version)
|
||||||
|
|
||||||
if not from_version or version.parse(from_version) < version.parse("4.2.0"):
|
if not from_version or version.parse(from_version) < version.parse("4.2.0"):
|
||||||
raise YunohostValidationError("restore_backup_too_old")
|
raise YunohostValidationError("restore_backup_too_old")
|
||||||
|
@ -2403,10 +2403,9 @@ def backup_list(with_info=False, human_readable=False):
|
||||||
logger.warning(str(e))
|
logger.warning(str(e))
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
trace_ = "\n" + traceback.format_exc()
|
trace_ = "\n" + traceback.format_exc()
|
||||||
logger.warning(
|
logger.warning(f"Could not check infos for archive {archive}: {trace_}")
|
||||||
f"Could not check infos for archive {archive}: {trace_}"
|
|
||||||
)
|
|
||||||
|
|
||||||
archives = d
|
archives = d
|
||||||
|
|
||||||
|
|
|
@ -415,9 +415,7 @@ def certificate_renew(
|
||||||
traceback.print_exc(file=stack)
|
traceback.print_exc(file=stack)
|
||||||
msg = f"Certificate renewing for {domain} failed!"
|
msg = f"Certificate renewing for {domain} failed!"
|
||||||
if no_checks:
|
if no_checks:
|
||||||
msg += (
|
msg += f"\nPlease consider checking the 'DNS records' (basic) and 'Web' categories of the diagnosis to check for possible issues that may prevent installing a Let's Encrypt certificate on domain {domain}."
|
||||||
f"\nPlease consider checking the 'DNS records' (basic) and 'Web' categories of the diagnosis to check for possible issues that may prevent installing a Let's Encrypt certificate on domain {domain}."
|
|
||||||
)
|
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
operation_logger.error(msg)
|
operation_logger.error(msg)
|
||||||
logger.error(stack.getvalue())
|
logger.error(stack.getvalue())
|
||||||
|
@ -788,7 +786,10 @@ def _enable_certificate(domain, new_cert_folder):
|
||||||
|
|
||||||
for service in ("postfix", "dovecot", "metronome"):
|
for service in ("postfix", "dovecot", "metronome"):
|
||||||
# Ugly trick to not restart metronome if it's not installed
|
# Ugly trick to not restart metronome if it's not installed
|
||||||
if service == "metronome" and os.system("dpkg --list | grep -q 'ii *metronome'") != 0:
|
if (
|
||||||
|
service == "metronome"
|
||||||
|
and os.system("dpkg --list | grep -q 'ii *metronome'") != 0
|
||||||
|
):
|
||||||
continue
|
continue
|
||||||
_run_service_command("restart", service)
|
_run_service_command("restart", service)
|
||||||
|
|
||||||
|
|
|
@ -155,9 +155,7 @@ class MyDiagnoser(Diagnoser):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# We use the resolver file as a list of well-known, trustable (ie not google ;)) IPs that we can ping
|
# We use the resolver file as a list of well-known, trustable (ie not google ;)) IPs that we can ping
|
||||||
resolver_file = (
|
resolver_file = "/usr/share/yunohost/conf/dnsmasq/plain/resolv.dnsmasq.conf"
|
||||||
"/usr/share/yunohost/conf/dnsmasq/plain/resolv.dnsmasq.conf"
|
|
||||||
)
|
|
||||||
resolvers = [
|
resolvers = [
|
||||||
r.split(" ")[1]
|
r.split(" ")[1]
|
||||||
for r in read_file(resolver_file).split("\n")
|
for r in read_file(resolver_file).split("\n")
|
||||||
|
|
|
@ -419,10 +419,7 @@ class Diagnoser:
|
||||||
|
|
||||||
def diagnose(self, force=False):
|
def diagnose(self, force=False):
|
||||||
|
|
||||||
if (
|
if not force and self.cached_time_ago() < self.cache_duration:
|
||||||
not force
|
|
||||||
and self.cached_time_ago() < self.cache_duration
|
|
||||||
):
|
|
||||||
logger.debug(f"Cache still valid : {self.cache_file}")
|
logger.debug(f"Cache still valid : {self.cache_file}")
|
||||||
logger.info(
|
logger.info(
|
||||||
m18n.n("diagnosis_cache_still_valid", category=self.description)
|
m18n.n("diagnosis_cache_still_valid", category=self.description)
|
||||||
|
@ -659,7 +656,9 @@ class Diagnoser:
|
||||||
def _list_diagnosis_categories():
|
def _list_diagnosis_categories():
|
||||||
|
|
||||||
paths = glob.glob(os.path.dirname(__file__) + "/diagnosers/??-*.py")
|
paths = glob.glob(os.path.dirname(__file__) + "/diagnosers/??-*.py")
|
||||||
names = sorted([os.path.basename(path)[: -len(".py")].split("-")[-1] for path in paths])
|
names = sorted(
|
||||||
|
[os.path.basename(path)[: -len(".py")].split("-")[-1] for path in paths]
|
||||||
|
)
|
||||||
|
|
||||||
return names
|
return names
|
||||||
|
|
||||||
|
@ -671,7 +670,10 @@ def _load_diagnoser(diagnoser_name):
|
||||||
paths = glob.glob(os.path.dirname(__file__) + f"/diagnosers/??-{diagnoser_name}.py")
|
paths = glob.glob(os.path.dirname(__file__) + f"/diagnosers/??-{diagnoser_name}.py")
|
||||||
|
|
||||||
if len(paths) != 1:
|
if len(paths) != 1:
|
||||||
raise YunohostError(f"Uhoh, found several matches (or none?) for diagnoser {diagnoser_name} : {paths}", raw_msg=True)
|
raise YunohostError(
|
||||||
|
f"Uhoh, found several matches (or none?) for diagnoser {diagnoser_name} : {paths}",
|
||||||
|
raw_msg=True,
|
||||||
|
)
|
||||||
|
|
||||||
module_id = os.path.basename(paths[0][: -len(".py")])
|
module_id = os.path.basename(paths[0][: -len(".py")])
|
||||||
|
|
||||||
|
@ -686,7 +688,9 @@ def _load_diagnoser(diagnoser_name):
|
||||||
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
raise YunohostError(f"Failed to load diagnoser {diagnoser_name} : {e}", raw_msg=True)
|
raise YunohostError(
|
||||||
|
f"Failed to load diagnoser {diagnoser_name} : {e}", raw_msg=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _email_diagnosis_issues():
|
def _email_diagnosis_issues():
|
||||||
|
|
|
@ -68,9 +68,7 @@ def domain_list(exclude_subdomains=False):
|
||||||
ldap = _get_ldap_interface()
|
ldap = _get_ldap_interface()
|
||||||
result = [
|
result = [
|
||||||
entry["virtualdomain"][0]
|
entry["virtualdomain"][0]
|
||||||
for entry in ldap.search(
|
for entry in ldap.search("ou=domains", "virtualdomain=*", ["virtualdomain"])
|
||||||
"ou=domains", "virtualdomain=*", ["virtualdomain"]
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
result_list = []
|
result_list = []
|
||||||
|
|
|
@ -190,7 +190,6 @@ def dyndns_update(
|
||||||
import dns.tsigkeyring
|
import dns.tsigkeyring
|
||||||
import dns.update
|
import dns.update
|
||||||
|
|
||||||
|
|
||||||
# If domain is not given, try to guess it from keys available...
|
# If domain is not given, try to guess it from keys available...
|
||||||
key = None
|
key = None
|
||||||
if domain is None:
|
if domain is None:
|
||||||
|
@ -227,7 +226,7 @@ def dyndns_update(
|
||||||
with open(key) as f:
|
with open(key) as f:
|
||||||
key = f.readline().strip().split(" ", 6)[-1]
|
key = f.readline().strip().split(" ", 6)[-1]
|
||||||
|
|
||||||
keyring = dns.tsigkeyring.from_text({f'{domain}.': key})
|
keyring = dns.tsigkeyring.from_text({f"{domain}.": key})
|
||||||
# Python's dns.update is similar to the old nsupdate cli tool
|
# Python's dns.update is similar to the old nsupdate cli tool
|
||||||
update = dns.update.Update(zone, keyring=keyring, keyalgorithm=dns.tsig.HMAC_SHA512)
|
update = dns.update.Update(zone, keyring=keyring, keyalgorithm=dns.tsig.HMAC_SHA512)
|
||||||
|
|
||||||
|
@ -300,7 +299,9 @@ def dyndns_update(
|
||||||
# [{"name": "...", "ttl": "...", "type": "...", "value": "..."}]
|
# [{"name": "...", "ttl": "...", "type": "...", "value": "..."}]
|
||||||
for records in dns_conf.values():
|
for records in dns_conf.values():
|
||||||
for record in records:
|
for record in records:
|
||||||
name = f"{record['name']}.{domain}." if record['name'] != "@" else f"{domain}."
|
name = (
|
||||||
|
f"{record['name']}.{domain}." if record["name"] != "@" else f"{domain}."
|
||||||
|
)
|
||||||
update.delete(name)
|
update.delete(name)
|
||||||
|
|
||||||
# Add the new records for all domain/subdomains
|
# Add the new records for all domain/subdomains
|
||||||
|
@ -313,9 +314,11 @@ def dyndns_update(
|
||||||
if record["value"] == "@":
|
if record["value"] == "@":
|
||||||
record["value"] = domain
|
record["value"] = domain
|
||||||
record["value"] = record["value"].replace(";", r"\;")
|
record["value"] = record["value"].replace(";", r"\;")
|
||||||
name = f"{record['name']}.{domain}." if record['name'] != "@" else f"{domain}."
|
name = (
|
||||||
|
f"{record['name']}.{domain}." if record["name"] != "@" else f"{domain}."
|
||||||
|
)
|
||||||
|
|
||||||
update.add(name, record['ttl'], record['type'], record['value'])
|
update.add(name, record["ttl"], record["type"], record["value"])
|
||||||
|
|
||||||
logger.debug("Now pushing new conf to DynDNS host...")
|
logger.debug("Now pushing new conf to DynDNS host...")
|
||||||
logger.debug(update)
|
logger.debug(update)
|
||||||
|
@ -347,9 +350,7 @@ def _guess_current_dyndns_domain():
|
||||||
dynette...)
|
dynette...)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DYNDNS_KEY_REGEX = re.compile(
|
DYNDNS_KEY_REGEX = re.compile(r".*/K(?P<domain>[^\s\+]+)\.\+165.+\.key$")
|
||||||
r".*/K(?P<domain>[^\s\+]+)\.\+165.+\.key$"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Retrieve the first registered domain
|
# Retrieve the first registered domain
|
||||||
paths = list(glob.iglob("/etc/yunohost/dyndns/K*.key"))
|
paths = list(glob.iglob("/etc/yunohost/dyndns/K*.key"))
|
||||||
|
|
|
@ -406,9 +406,7 @@ def permission_create(
|
||||||
permission = permission + ".main"
|
permission = permission + ".main"
|
||||||
|
|
||||||
# Validate uniqueness of permission in LDAP
|
# Validate uniqueness of permission in LDAP
|
||||||
if ldap.get_conflict(
|
if ldap.get_conflict({"cn": permission}, base_dn="ou=permission"):
|
||||||
{"cn": permission}, base_dn="ou=permission"
|
|
||||||
):
|
|
||||||
raise YunohostValidationError("permission_already_exist", permission=permission)
|
raise YunohostValidationError("permission_already_exist", permission=permission)
|
||||||
|
|
||||||
# Get random GID
|
# Get random GID
|
||||||
|
@ -678,8 +676,7 @@ def permission_sync_to_user():
|
||||||
|
|
||||||
new_inherited_perms = {
|
new_inherited_perms = {
|
||||||
"inheritPermission": [
|
"inheritPermission": [
|
||||||
f"uid={u},ou=users,dc=yunohost,dc=org"
|
f"uid={u},ou=users,dc=yunohost,dc=org" for u in should_be_allowed_users
|
||||||
for u in should_be_allowed_users
|
|
||||||
],
|
],
|
||||||
"memberUid": should_be_allowed_users,
|
"memberUid": should_be_allowed_users,
|
||||||
}
|
}
|
||||||
|
|
|
@ -505,9 +505,7 @@ def _calculate_hash(path):
|
||||||
return hasher.hexdigest()
|
return hasher.hexdigest()
|
||||||
|
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
logger.warning(
|
logger.warning(f"Error while calculating file '{path}' hash: {e}", exc_info=1)
|
||||||
f"Error while calculating file '{path}' hash: {e}", exc_info=1
|
|
||||||
)
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -695,19 +695,25 @@ def _get_services():
|
||||||
if "log" not in services["ynh-vpnclient"]:
|
if "log" not in services["ynh-vpnclient"]:
|
||||||
services["ynh-vpnclient"]["log"] = ["/var/log/ynh-vpnclient.log"]
|
services["ynh-vpnclient"]["log"] = ["/var/log/ynh-vpnclient.log"]
|
||||||
|
|
||||||
services_with_package_condition = [name for name, infos in services.items() if infos.get("ignore_if_package_is_not_installed")]
|
services_with_package_condition = [
|
||||||
|
name
|
||||||
|
for name, infos in services.items()
|
||||||
|
if infos.get("ignore_if_package_is_not_installed")
|
||||||
|
]
|
||||||
for name in services_with_package_condition:
|
for name in services_with_package_condition:
|
||||||
package = services[name]["ignore_if_package_is_not_installed"]
|
package = services[name]["ignore_if_package_is_not_installed"]
|
||||||
if os.system(f"dpkg --list | grep -q 'ii *{package}'") != 0:
|
if os.system(f"dpkg --list | grep -q 'ii *{package}'") != 0:
|
||||||
del services[name]
|
del services[name]
|
||||||
|
|
||||||
php_fpm_versions = check_output(r"dpkg --list | grep -P 'ii php\d.\d-fpm' | awk '{print $2}' | grep -o -P '\d.\d' || true")
|
php_fpm_versions = check_output(
|
||||||
php_fpm_versions = [v for v in php_fpm_versions.split('\n') if v.strip()]
|
r"dpkg --list | grep -P 'ii php\d.\d-fpm' | awk '{print $2}' | grep -o -P '\d.\d' || true"
|
||||||
|
)
|
||||||
|
php_fpm_versions = [v for v in php_fpm_versions.split("\n") if v.strip()]
|
||||||
for version in php_fpm_versions:
|
for version in php_fpm_versions:
|
||||||
services[f"php{version}-fpm"] = {
|
services[f"php{version}-fpm"] = {
|
||||||
"log": f"/var/log/php{version}-fpm.log",
|
"log": f"/var/log/php{version}-fpm.log",
|
||||||
"test_conf": f"php-fpm{version} --test", # ofc the service is phpx.y-fpm but the program is php-fpmx.y because why not ...
|
"test_conf": f"php-fpm{version} --test", # ofc the service is phpx.y-fpm but the program is php-fpmx.y because why not ...
|
||||||
"category": "web"
|
"category": "web",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove legacy /var/log/daemon.log and /var/log/syslog from log entries
|
# Remove legacy /var/log/daemon.log and /var/log/syslog from log entries
|
||||||
|
@ -833,7 +839,6 @@ def _get_journalctl_logs(service, number="all"):
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
trace_ = traceback.format_exc()
|
trace_ = traceback.format_exc()
|
||||||
return (
|
return f"error while get services logs from journalctl:\n{trace_}"
|
||||||
f"error while get services logs from journalctl:\n{trace_}"
|
|
||||||
)
|
|
||||||
|
|
|
@ -341,9 +341,7 @@ def _get_settings():
|
||||||
_save_settings(unknown_settings, location=unknown_settings_path)
|
_save_settings(unknown_settings, location=unknown_settings_path)
|
||||||
_save_settings(settings)
|
_save_settings(settings)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(
|
logger.warning(f"Failed to save unknown settings (because {e}), aborting.")
|
||||||
f"Failed to save unknown settings (because {e}), aborting."
|
|
||||||
)
|
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
@ -373,12 +371,12 @@ post_change_hooks = {}
|
||||||
|
|
||||||
def post_change_hook(setting_name):
|
def post_change_hook(setting_name):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
assert setting_name in DEFAULTS.keys(), (
|
assert (
|
||||||
f"The setting {setting_name} does not exists"
|
setting_name in DEFAULTS.keys()
|
||||||
)
|
), f"The setting {setting_name} does not exists"
|
||||||
assert setting_name not in post_change_hooks, (
|
assert (
|
||||||
f"You can only register one post change hook per setting (in particular for {setting_name})"
|
setting_name not in post_change_hooks
|
||||||
)
|
), f"You can only register one post change hook per setting (in particular for {setting_name})"
|
||||||
post_change_hooks[setting_name] = func
|
post_change_hooks[setting_name] = func
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
10
src/tools.py
10
src/tools.py
|
@ -536,9 +536,7 @@ def tools_upgrade(operation_logger, target=None):
|
||||||
# Restart the API after 10 sec (at now doesn't support sub-minute times...)
|
# Restart the API after 10 sec (at now doesn't support sub-minute times...)
|
||||||
# We do this so that the API / webadmin still gets the proper HTTP response
|
# We do this so that the API / webadmin still gets the proper HTTP response
|
||||||
# It's then up to the webadmin to implement a proper UX process to wait 10 sec and then auto-fresh the webadmin
|
# It's then up to the webadmin to implement a proper UX process to wait 10 sec and then auto-fresh the webadmin
|
||||||
cmd = (
|
cmd = 'at -M now >/dev/null 2>&1 <<< "sleep 10; systemctl restart yunohost-api"'
|
||||||
"at -M now >/dev/null 2>&1 <<< \"sleep 10; systemctl restart yunohost-api\""
|
|
||||||
)
|
|
||||||
# For some reason subprocess doesn't like the redirections so we have to use bash -c explicity...
|
# For some reason subprocess doesn't like the redirections so we have to use bash -c explicity...
|
||||||
subprocess.check_call(["bash", "-c", cmd])
|
subprocess.check_call(["bash", "-c", cmd])
|
||||||
|
|
||||||
|
@ -894,9 +892,9 @@ def _get_migration_by_name(migration_name):
|
||||||
if re.match(r"^\d+_%s\.py$" % migration_name, x)
|
if re.match(r"^\d+_%s\.py$" % migration_name, x)
|
||||||
]
|
]
|
||||||
|
|
||||||
assert len(migrations_found) == 1, (
|
assert (
|
||||||
f"Unable to find migration with name {migration_name}"
|
len(migrations_found) == 1
|
||||||
)
|
), f"Unable to find migration with name {migration_name}"
|
||||||
|
|
||||||
return _load_migration(migrations_found[0])
|
return _load_migration(migrations_found[0])
|
||||||
|
|
||||||
|
|
|
@ -254,9 +254,7 @@ def user_create(
|
||||||
logger.warning(m18n.n("user_home_creation_failed", home=home), exc_info=1)
|
logger.warning(m18n.n("user_home_creation_failed", home=home), exc_info=1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(
|
subprocess.check_call(["setfacl", "-m", "g:all_users:---", f"/home/{username}"])
|
||||||
["setfacl", "-m", "g:all_users:---", f"/home/{username}"]
|
|
||||||
)
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
logger.warning(f"Failed to protect /home/{username}", exc_info=1)
|
logger.warning(f"Failed to protect /home/{username}", exc_info=1)
|
||||||
|
|
||||||
|
@ -986,9 +984,7 @@ def user_group_create(
|
||||||
ldap = _get_ldap_interface()
|
ldap = _get_ldap_interface()
|
||||||
|
|
||||||
# Validate uniqueness of groupname in LDAP
|
# Validate uniqueness of groupname in LDAP
|
||||||
conflict = ldap.get_conflict(
|
conflict = ldap.get_conflict({"cn": groupname}, base_dn="ou=groups")
|
||||||
{"cn": groupname}, base_dn="ou=groups"
|
|
||||||
)
|
|
||||||
if conflict:
|
if conflict:
|
||||||
raise YunohostValidationError("group_already_exist", group=groupname)
|
raise YunohostValidationError("group_already_exist", group=groupname)
|
||||||
|
|
||||||
|
|
|
@ -65,4 +65,3 @@ class YunohostValidationError(YunohostError):
|
||||||
class YunohostAuthenticationError(MoulinetteAuthenticationError):
|
class YunohostAuthenticationError(MoulinetteAuthenticationError):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -116,10 +116,7 @@ def _patch_legacy_php_versions(app_folder):
|
||||||
|
|
||||||
c = (
|
c = (
|
||||||
"sed -i "
|
"sed -i "
|
||||||
+ "".join(
|
+ "".join(f"-e 's@{p}@{r}@g' " for p, r in LEGACY_PHP_VERSION_REPLACEMENTS)
|
||||||
f"-e 's@{p}@{r}@g' "
|
|
||||||
for p, r in LEGACY_PHP_VERSION_REPLACEMENTS
|
|
||||||
)
|
|
||||||
+ "%s" % filename
|
+ "%s" % filename
|
||||||
)
|
)
|
||||||
os.system(c)
|
os.system(c)
|
||||||
|
@ -137,7 +134,11 @@ def _patch_legacy_php_versions_in_settings(app_folder):
|
||||||
settings["phpversion"] = "7.4"
|
settings["phpversion"] = "7.4"
|
||||||
|
|
||||||
# We delete these checksums otherwise the file will appear as manually modified
|
# We delete these checksums otherwise the file will appear as manually modified
|
||||||
list_to_remove = ["checksum__etc_php_7.3_fpm_pool", "checksum__etc_php_7.0_fpm_pool", "checksum__etc_nginx_conf.d"]
|
list_to_remove = [
|
||||||
|
"checksum__etc_php_7.3_fpm_pool",
|
||||||
|
"checksum__etc_php_7.0_fpm_pool",
|
||||||
|
"checksum__etc_nginx_conf.d",
|
||||||
|
]
|
||||||
settings = {
|
settings = {
|
||||||
k: v
|
k: v
|
||||||
for k, v in settings.items()
|
for k, v in settings.items()
|
||||||
|
@ -168,9 +169,15 @@ def _patch_legacy_helpers(app_folder):
|
||||||
"important": False,
|
"important": False,
|
||||||
},
|
},
|
||||||
# Old $1, $2 in backup/restore scripts...
|
# Old $1, $2 in backup/restore scripts...
|
||||||
"app=$2": {"only_for": ["scripts/backup", "scripts/restore"], "important": True},
|
"app=$2": {
|
||||||
|
"only_for": ["scripts/backup", "scripts/restore"],
|
||||||
|
"important": True,
|
||||||
|
},
|
||||||
# Old $1, $2 in backup/restore scripts...
|
# Old $1, $2 in backup/restore scripts...
|
||||||
"backup_dir=$1": {"only_for": ["scripts/backup", "scripts/restore"], "important": True},
|
"backup_dir=$1": {
|
||||||
|
"only_for": ["scripts/backup", "scripts/restore"],
|
||||||
|
"important": True,
|
||||||
|
},
|
||||||
# Old $1, $2 in backup/restore scripts...
|
# Old $1, $2 in backup/restore scripts...
|
||||||
"restore_dir=$1": {"only_for": ["scripts/restore"], "important": True},
|
"restore_dir=$1": {"only_for": ["scripts/restore"], "important": True},
|
||||||
# Old $1, $2 in install scripts...
|
# Old $1, $2 in install scripts...
|
||||||
|
|
Loading…
Add table
Reference in a new issue