diff --git a/src/migrations/0021_migrate_to_bullseye.py b/src/migrations/0021_migrate_to_bullseye.py index f5e7f518c..7577c852c 100644 --- a/src/migrations/0021_migrate_to_bullseye.py +++ b/src/migrations/0021_migrate_to_bullseye.py @@ -35,19 +35,19 @@ VENV_REQUIREMENTS_SUFFIX = ".requirements_backup_for_bullseye_upgrade.txt" def _get_all_venvs(dir, level=0, maxlevel=3): """ - Returns the list of all python virtual env directories recursively + Returns the list of all python virtual env directories recursively - Arguments: - dir - the directory to scan in - maxlevel - the depth of the recursion - level - do not edit this, used as an iterator + Arguments: + dir - the directory to scan in + maxlevel - the depth of the recursion + level - do not edit this, used as an iterator """ # Using os functions instead of glob, because glob doesn't support hidden folders, and we need recursion with a fixed depth result = [] 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): @@ -60,7 +60,7 @@ def _get_all_venvs(dir, level=0, maxlevel=3): def _backup_pip_freeze_for_python_app_venvs(): """ - Generate a requirements file for all python virtual env located inside /opt/ and /var/www/ + Generate a requirements file for all python virtual env located inside /opt/ and /var/www/ """ venvs = _get_all_venvs("/opt/") + _get_all_venvs("/var/www/") @@ -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 = [ @@ -391,8 +392,8 @@ class MyMigration(Migration): message = m18n.n("migration_0021_general_warning") message = ( - "N.B.: This migration has been tested by the community over the last few months but has only been declared stable recently. If your server hosts critical services and if you are not too confident with debugging possible issues, we recommend you to wait a little bit more while we gather more feedback and polish things up. If on the other hand you are relatively confident with debugging small issues that may arise, you are encouraged to run this migration ;)! You can read about remaining known issues and feedback from the community here: https://forum.yunohost.org/t/20590\n\n" - + message + "N.B.: This migration has been tested by the community over the last few months but has only been declared stable recently. If your server hosts critical services and if you are not too confident with debugging possible issues, we recommend you to wait a little bit more while we gather more feedback and polish things up. If on the other hand you are relatively confident with debugging small issues that may arise, you are encouraged to run this migration ;)! You can read about remaining known issues and feedback from the community here: https://forum.yunohost.org/t/20590\n\n" + + message ) if problematic_apps: diff --git a/src/migrations/0024_rebuild_python_venv.py b/src/migrations/0024_rebuild_python_venv.py index b90a35f60..f39c27c49 100644 --- a/src/migrations/0024_rebuild_python_venv.py +++ b/src/migrations/0024_rebuild_python_venv.py @@ -23,12 +23,12 @@ def extract_app_from_venv_path(venv_path): def _get_all_venvs(dir, level=0, maxlevel=3): """ - Returns the list of all python virtual env directories recursively + Returns the list of all python virtual env directories recursively - Arguments: - dir - the directory to scan in - maxlevel - the depth of the recursion - level - do not edit this, used as an iterator + Arguments: + dir - the directory to scan in + maxlevel - the depth of the recursion + level - do not edit this, used as an iterator """ # Using os functions instead of glob, because glob doesn't support hidden # folders, and we need recursion with a fixed depth @@ -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) diff --git a/src/tools.py b/src/tools.py index 844a2a3ba..abf224c1c 100644 --- a/src/tools.py +++ b/src/tools.py @@ -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 diff --git a/src/user.py b/src/user.py index ce0cea60d..0c5a577d7 100644 --- a/src/user.py +++ b/src/user.py @@ -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