[CI] Format code with Black

This commit is contained in:
yunohost-bot 2023-02-15 21:37:05 +00:00
parent 13c4687c7b
commit 069b782f07
7 changed files with 53 additions and 23 deletions

View file

@ -2,9 +2,10 @@ import ast
import datetime import datetime
import subprocess import subprocess
version = open("../debian/changelog").readlines()[0].split()[1].strip("()"), version = (open("../debian/changelog").readlines()[0].split()[1].strip("()"),)
today = datetime.datetime.now().strftime("%d/%m/%Y") today = datetime.datetime.now().strftime("%d/%m/%Y")
def get_current_commit(): def get_current_commit():
p = subprocess.Popen( p = subprocess.Popen(
"git rev-parse --verify HEAD", "git rev-parse --verify HEAD",
@ -16,10 +17,13 @@ def get_current_commit():
current_commit = stdout.strip().decode("utf-8") current_commit = stdout.strip().decode("utf-8")
return current_commit return current_commit
current_commit = get_current_commit() current_commit = get_current_commit()
print(f"""--- print(
f"""---
title: App resources title: App resources
template: docs template: docs
taxonomy: taxonomy:
@ -30,7 +34,8 @@ routes:
Doc auto-generated by [this script](https://github.com/YunoHost/yunohost/blob/{current_commit}/doc/generate_resource_doc.py) on {today} (YunoHost version {version}) Doc auto-generated by [this script](https://github.com/YunoHost/yunohost/blob/{current_commit}/doc/generate_resource_doc.py) on {today} (YunoHost version {version})
""") """
)
fname = "../src/utils/resources.py" fname = "../src/utils/resources.py"
@ -40,12 +45,15 @@ content = open(fname).read()
# in which we cant really 'import' the file because it will trigger a bunch of moulinette/yunohost imports... # in which we cant really 'import' the file because it will trigger a bunch of moulinette/yunohost imports...
tree = ast.parse(content) tree = ast.parse(content)
ResourceClasses = [c for c in tree.body if isinstance(c, ast.ClassDef) and c.bases and c.bases[0].id == 'AppResource'] ResourceClasses = [
c
for c in tree.body
if isinstance(c, ast.ClassDef) and c.bases and c.bases[0].id == "AppResource"
]
ResourceDocString = {} ResourceDocString = {}
for c in ResourceClasses: for c in ResourceClasses:
assert c.body[1].targets[0].id == "type" assert c.body[1].targets[0].id == "type"
resource_id = c.body[1].value.value resource_id = c.body[1].value.value
docstring = ast.get_docstring(c) docstring = ast.get_docstring(c)

View file

@ -2593,7 +2593,7 @@ def _check_manifest_requirements(
yield ( yield (
"arch", "arch",
arch_requirement in ["all", "?"] or arch in arch_requirement, arch_requirement in ["all", "?"] or arch in arch_requirement,
{"current": arch, "required": ', '.join(arch_requirement)}, {"current": arch, "required": ", ".join(arch_requirement)},
"app_arch_not_supported", # i18n: app_arch_not_supported "app_arch_not_supported", # i18n: app_arch_not_supported
) )
@ -2678,9 +2678,7 @@ def _guess_webapp_path_requirement(app_folder: str) -> str:
if len(domain_questions) == 1 and len(path_questions) == 1: if len(domain_questions) == 1 and len(path_questions) == 1:
return "domain_and_path" return "domain_and_path"
if len(domain_questions) == 1 and len(path_questions) == 0: if len(domain_questions) == 1 and len(path_questions) == 0:
if manifest.get("packaging_format", 0) < 2: if manifest.get("packaging_format", 0) < 2:
# This is likely to be a full-domain app... # This is likely to be a full-domain app...
# Confirm that this is a full-domain app This should cover most cases # Confirm that this is a full-domain app This should cover most cases
@ -2691,7 +2689,9 @@ def _guess_webapp_path_requirement(app_folder: str) -> str:
# Full-domain apps typically declare something like path_url="/" or path=/ # Full-domain apps typically declare something like path_url="/" or path=/
# and use ynh_webpath_register or yunohost_app_checkurl inside the install script # and use ynh_webpath_register or yunohost_app_checkurl inside the install script
install_script_content = read_file(os.path.join(app_folder, "scripts/install")) install_script_content = read_file(
os.path.join(app_folder, "scripts/install")
)
if re.search( if re.search(
r"\npath(_url)?=[\"']?/[\"']?", install_script_content r"\npath(_url)?=[\"']?/[\"']?", install_script_content
@ -2701,7 +2701,9 @@ def _guess_webapp_path_requirement(app_folder: str) -> str:
else: else:
# For packaging v2 apps, check if there's a permission with url being a string # For packaging v2 apps, check if there's a permission with url being a string
perm_resource = manifest.get("resources", {}).get("permissions") perm_resource = manifest.get("resources", {}).get("permissions")
if perm_resource is not None and isinstance(perm_resource.get("main", {}).get("url"), str): if perm_resource is not None and isinstance(
perm_resource.get("main", {}).get("url"), str
):
return "full_domain" return "full_domain"
return "?" return "?"

View file

@ -941,7 +941,14 @@ class RestoreManager:
# Use a dummy password which is not gonna be saved anywhere # Use a dummy password which is not gonna be saved anywhere
# because the next thing to happen should be that a full restore of the LDAP db will happen # because the next thing to happen should be that a full restore of the LDAP db will happen
tools_postinstall(domain, "tmpadmin", "Tmp Admin", password=random_ascii(70), ignore_dyndns=True, overwrite_root_password=False) tools_postinstall(
domain,
"tmpadmin",
"Tmp Admin",
password=random_ascii(70),
ignore_dyndns=True,
overwrite_root_password=False,
)
def clean(self): def clean(self):
""" """
@ -1190,7 +1197,7 @@ class RestoreManager:
except Exception as e: except Exception as e:
raise YunohostError( raise YunohostError(
f"The following critical error happened during restoration: {e}", f"The following critical error happened during restoration: {e}",
raw_msg=True raw_msg=True,
) )
finally: finally:
self.clean() self.clean()

View file

@ -593,7 +593,9 @@ def _get_registrar_config_section(domain):
registrar_list = read_toml(DOMAIN_REGISTRAR_LIST_PATH) registrar_list = read_toml(DOMAIN_REGISTRAR_LIST_PATH)
registrar_credentials = registrar_list.get(registrar) registrar_credentials = registrar_list.get(registrar)
if registrar_credentials is None: if registrar_credentials is None:
logger.warning(f"Registrar {registrar} unknown / Should be added to YunoHost's registrar_list.toml by the development team!") logger.warning(
f"Registrar {registrar} unknown / Should be added to YunoHost's registrar_list.toml by the development team!"
)
registrar_credentials = {} registrar_credentials = {}
for credential, infos in registrar_credentials.items(): for credential, infos in registrar_credentials.items():
infos["default"] = infos.get("default", "") infos["default"] = infos.get("default", "")

View file

@ -53,12 +53,14 @@ class MyMigration(Migration):
if not new_admin_user: if not new_admin_user:
for user in all_users: for user in all_users:
aliases = user_info(user).get("mail-aliases", []) aliases = user_info(user).get("mail-aliases", [])
if any(alias.startswith(f"admin@{main_domain}") for alias in aliases) \ if any(
or any(alias.startswith(f"postmaster@{main_domain}") for alias in aliases): alias.startswith(f"admin@{main_domain}") for alias in aliases
) or any(
alias.startswith(f"postmaster@{main_domain}") for alias in aliases
):
new_admin_user = user new_admin_user = user
break break
self.ldap_migration_started = True self.ldap_migration_started = True
if new_admin_user: if new_admin_user:

View file

@ -1359,7 +1359,9 @@ class GroupQuestion(Question):
super().__init__(question, context) super().__init__(question, context)
self.choices = list(user_group_list(short=True, include_primary_groups=False)["groups"]) self.choices = list(
user_group_list(short=True, include_primary_groups=False)["groups"]
)
def _human_readable_group(g): def _human_readable_group(g):
# i18n: visitors # i18n: visitors

View file

@ -182,7 +182,10 @@ class AppResource:
tmpdir = _make_tmp_workdir_for_app(app=self.app) tmpdir = _make_tmp_workdir_for_app(app=self.app)
env_ = _make_environment_for_app_script( env_ = _make_environment_for_app_script(
self.app, workdir=tmpdir, action=f"{action}_{self.type}", include_app_settings=True, self.app,
workdir=tmpdir,
action=f"{action}_{self.type}",
include_app_settings=True,
) )
env_.update(env) env_.update(env)
@ -306,7 +309,7 @@ class PermissionsResource(AppResource):
): ):
raise YunohostError( raise YunohostError(
"URL for the 'main' permission should be '/' for webapps (or undefined/None for non-webapps). Note that / refers to the install url of the app, i.e $domain.tld/$path/", "URL for the 'main' permission should be '/' for webapps (or undefined/None for non-webapps). Note that / refers to the install url of the app, i.e $domain.tld/$path/",
raw_msg=True raw_msg=True,
) )
super().__init__({"permissions": properties}, *args, **kwargs) super().__init__({"permissions": properties}, *args, **kwargs)
@ -474,12 +477,16 @@ class SystemuserAppResource(AppResource):
if check_output(f"getent passwd {self.app} &>/dev/null || true").strip(): if check_output(f"getent passwd {self.app} &>/dev/null || true").strip():
os.system(f"deluser {self.app} >/dev/null") os.system(f"deluser {self.app} >/dev/null")
if check_output(f"getent passwd {self.app} &>/dev/null || true").strip(): if check_output(f"getent passwd {self.app} &>/dev/null || true").strip():
raise YunohostError(f"Failed to delete system user for {self.app}", raw_msg=True) raise YunohostError(
f"Failed to delete system user for {self.app}", raw_msg=True
)
if check_output(f"getent group {self.app} &>/dev/null || true").strip(): if check_output(f"getent group {self.app} &>/dev/null || true").strip():
os.system(f"delgroup {self.app} >/dev/null") os.system(f"delgroup {self.app} >/dev/null")
if check_output(f"getent group {self.app} &>/dev/null || true").strip(): if check_output(f"getent group {self.app} &>/dev/null || true").strip():
raise YunohostError(f"Failed to delete system user for {self.app}", raw_msg=True) raise YunohostError(
f"Failed to delete system user for {self.app}", raw_msg=True
)
# FIXME : better logging and error handling, add stdout/stderr from the deluser/delgroup commands... # FIXME : better logging and error handling, add stdout/stderr from the deluser/delgroup commands...
@ -748,7 +755,7 @@ class AptDependenciesAppResource(AppResource):
): ):
raise YunohostError( raise YunohostError(
"In apt resource in the manifest: 'extras' repo should have the keys 'repo', 'key' and 'packages' defined and be strings", "In apt resource in the manifest: 'extras' repo should have the keys 'repo', 'key' and 'packages' defined and be strings",
raw_msg=True raw_msg=True,
) )
super().__init__(properties, *args, **kwargs) super().__init__(properties, *args, **kwargs)
@ -866,7 +873,7 @@ class PortsResource(AppResource):
if self._port_is_used(port_value): if self._port_is_used(port_value):
raise YunohostValidationError( raise YunohostValidationError(
f"Port {port_value} is already used by another process or app.", f"Port {port_value} is already used by another process or app.",
raw_msg=True raw_msg=True,
) )
else: else:
while self._port_is_used(port_value): while self._port_is_used(port_value):