[CI] Format code with Black

This commit is contained in:
yunohost-bot 2022-08-08 16:59:42 +00:00
parent 8a9ed1ed7a
commit 8cef37d704
4 changed files with 68 additions and 37 deletions

View file

@ -47,7 +47,7 @@ def _get_all_venvs(dir, level=0, maxlevel=3):
for file in os.listdir(dir):
path = os.path.join(dir, file)
if os.path.isdir(path):
activatepath = os.path.join(path,"bin", "activate")
activatepath = os.path.join(path, "bin", "activate")
if os.path.isfile(activatepath):
content = read_file(activatepath)
if ("VIRTUAL_ENV" in content) and ("PYTHONHOME" in content):
@ -308,7 +308,6 @@ class MyMigration(Migration):
tools_upgrade(target="system", postupgradecmds=postupgradecmds)
def debian_major_version(self):
# The python module "platform" and lsb_release are not reliable because
# on some setup, they may still return Release=9 even after upgrading to
@ -344,7 +343,9 @@ class MyMigration(Migration):
# Check system is up to date
# (but we don't if 'bullseye' is already in the sources.list ...
# which means maybe a previous upgrade crashed and we're re-running it)
if os.path.exists("/etc/apt/sources.list") and " bullseye " not in read_file("/etc/apt/sources.list"):
if os.path.exists("/etc/apt/sources.list") and " bullseye " not in read_file(
"/etc/apt/sources.list"
):
tools_update(target="system")
upgradable_system_packages = list(_list_upgradable_apt_packages())
upgradable_system_packages = [

View file

@ -37,7 +37,9 @@ def _get_all_venvs(dir, level=0, maxlevel=3):
path = os.path.join(dir, file)
if os.path.isdir(path):
activatepath = os.path.join(path, "bin", "activate")
if os.path.isfile(activatepath) and os.path.isfile(path + VENV_REQUIREMENTS_SUFFIX):
if os.path.isfile(activatepath) and os.path.isfile(
path + VENV_REQUIREMENTS_SUFFIX
):
result.append(path)
continue
if level < maxlevel:
@ -50,6 +52,7 @@ class MyMigration(Migration):
After the update, recreate a python virtual env based on the previously
generated requirements file
"""
ignored_python_apps = [
"calibreweb",
"django-for-runners",
@ -62,7 +65,7 @@ class MyMigration(Migration):
"pgadmin",
"tracim",
"synapse",
"weblate"
"weblate",
]
dependencies = ["migrate_to_bullseye"]
@ -70,7 +73,9 @@ class MyMigration(Migration):
def is_pending(self):
if not self.state:
self.state = tools_migrations_state()["migrations"].get("0024_rebuild_python_venv", "pending")
self.state = tools_migrations_state()["migrations"].get(
"0024_rebuild_python_venv", "pending"
)
return self.state == "pending"
@property
@ -101,18 +106,25 @@ class MyMigration(Migration):
app_corresponding_to_venv = extract_app_from_venv_path(venv)
# Search for ignore apps
if any(app_corresponding_to_venv.startswith(app) for app in self.ignored_python_apps):
if any(
app_corresponding_to_venv.startswith(app)
for app in self.ignored_python_apps
):
ignored_apps.append(app_corresponding_to_venv)
else:
rebuild_apps.append(app_corresponding_to_venv)
msg = m18n.n("migration_0024_rebuild_python_venv_disclaimer_base")
if rebuild_apps:
msg += "\n\n" + m18n.n("migration_0024_rebuild_python_venv_disclaimer_rebuild",
rebuild_apps="\n - " + "\n - ".join(rebuild_apps))
msg += "\n\n" + m18n.n(
"migration_0024_rebuild_python_venv_disclaimer_rebuild",
rebuild_apps="\n - " + "\n - ".join(rebuild_apps),
)
if ignored_apps:
msg += "\n\n" + m18n.n("migration_0024_rebuild_python_venv_disclaimer_ignored",
ignored_apps="\n - " + "\n - ".join(ignored_apps))
msg += "\n\n" + m18n.n(
"migration_0024_rebuild_python_venv_disclaimer_ignored",
ignored_apps="\n - " + "\n - ".join(ignored_apps),
)
return msg
@ -124,25 +136,43 @@ class MyMigration(Migration):
app_corresponding_to_venv = extract_app_from_venv_path(venv)
# Search for ignore apps
if any(app_corresponding_to_venv.startswith(app) for app in self.ignored_python_apps):
if any(
app_corresponding_to_venv.startswith(app)
for app in self.ignored_python_apps
):
rm(venv + VENV_REQUIREMENTS_SUFFIX)
logger.info(m18n.n("migration_0024_rebuild_python_venv_broken_app", app=app_corresponding_to_venv))
logger.info(
m18n.n(
"migration_0024_rebuild_python_venv_broken_app",
app=app_corresponding_to_venv,
)
)
continue
logger.info(m18n.n("migration_0024_rebuild_python_venv_in_progress", app=app_corresponding_to_venv))
logger.info(
m18n.n(
"migration_0024_rebuild_python_venv_in_progress",
app=app_corresponding_to_venv,
)
)
# Recreate the venv
rm(venv, recursive=True)
callbacks = (
lambda l: logger.debug("+ " + l.rstrip() + "\r"),
lambda l: logger.warning(l.rstrip())
lambda l: logger.warning(l.rstrip()),
)
call_async_output(["python", "-m", "venv", venv], callbacks)
status = call_async_output([
f"{venv}/bin/pip", "install", "-r",
venv + VENV_REQUIREMENTS_SUFFIX], callbacks)
status = call_async_output(
[f"{venv}/bin/pip", "install", "-r", venv + VENV_REQUIREMENTS_SUFFIX],
callbacks,
)
if status != 0:
logger.error(m18n.n("migration_0024_rebuild_python_venv_failed",
app=app_corresponding_to_venv))
logger.error(
m18n.n(
"migration_0024_rebuild_python_venv_failed",
app=app_corresponding_to_venv,
)
)
else:
rm(venv + VENV_REQUIREMENTS_SUFFIX)

View file

@ -73,7 +73,7 @@ def tools_adminpw(new_password, check_strength=True):
from yunohost.user import _hash_user_password
from yunohost.utils.password import (
assert_password_is_strong_enough,
assert_password_is_compatible
assert_password_is_compatible,
)
import spwd
@ -203,7 +203,7 @@ def tools_postinstall(
from yunohost.utils.dns import is_yunohost_dyndns_domain
from yunohost.utils.password import (
assert_password_is_strong_enough,
assert_password_is_compatible
assert_password_is_compatible,
)
from yunohost.domain import domain_main_domain
import psutil

View file

@ -145,7 +145,7 @@ def user_create(
from yunohost.hook import hook_callback
from yunohost.utils.password import (
assert_password_is_strong_enough,
assert_password_is_compatible
assert_password_is_compatible,
)
from yunohost.utils.ldap import _get_ldap_interface
@ -371,7 +371,7 @@ def user_update(
from yunohost.app import app_ssowatconf
from yunohost.utils.password import (
assert_password_is_strong_enough,
assert_password_is_compatible
assert_password_is_compatible,
)
from yunohost.utils.ldap import _get_ldap_interface
from yunohost.hook import hook_callback