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
8a9ed1ed7a
commit
8cef37d704
4 changed files with 68 additions and 37 deletions
|
@ -35,19 +35,19 @@ VENV_REQUIREMENTS_SUFFIX = ".requirements_backup_for_bullseye_upgrade.txt"
|
||||||
|
|
||||||
def _get_all_venvs(dir, level=0, maxlevel=3):
|
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:
|
Arguments:
|
||||||
dir - the directory to scan in
|
dir - the directory to scan in
|
||||||
maxlevel - the depth of the recursion
|
maxlevel - the depth of the recursion
|
||||||
level - do not edit this, used as an iterator
|
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
|
# Using os functions instead of glob, because glob doesn't support hidden folders, and we need recursion with a fixed depth
|
||||||
result = []
|
result = []
|
||||||
for file in os.listdir(dir):
|
for file in os.listdir(dir):
|
||||||
path = os.path.join(dir, file)
|
path = os.path.join(dir, file)
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
activatepath = os.path.join(path,"bin", "activate")
|
activatepath = os.path.join(path, "bin", "activate")
|
||||||
if os.path.isfile(activatepath):
|
if os.path.isfile(activatepath):
|
||||||
content = read_file(activatepath)
|
content = read_file(activatepath)
|
||||||
if ("VIRTUAL_ENV" in content) and ("PYTHONHOME" in content):
|
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():
|
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/")
|
venvs = _get_all_venvs("/opt/") + _get_all_venvs("/var/www/")
|
||||||
|
@ -308,7 +308,6 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
tools_upgrade(target="system", postupgradecmds=postupgradecmds)
|
tools_upgrade(target="system", postupgradecmds=postupgradecmds)
|
||||||
|
|
||||||
|
|
||||||
def debian_major_version(self):
|
def debian_major_version(self):
|
||||||
# The python module "platform" and lsb_release are not reliable because
|
# The python module "platform" and lsb_release are not reliable because
|
||||||
# on some setup, they may still return Release=9 even after upgrading to
|
# 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
|
# Check system is up to date
|
||||||
# (but we don't if 'bullseye' is already in the sources.list ...
|
# (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)
|
# 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")
|
tools_update(target="system")
|
||||||
upgradable_system_packages = list(_list_upgradable_apt_packages())
|
upgradable_system_packages = list(_list_upgradable_apt_packages())
|
||||||
upgradable_system_packages = [
|
upgradable_system_packages = [
|
||||||
|
@ -391,8 +392,8 @@ class MyMigration(Migration):
|
||||||
message = m18n.n("migration_0021_general_warning")
|
message = m18n.n("migration_0021_general_warning")
|
||||||
|
|
||||||
message = (
|
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"
|
"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
|
+ message
|
||||||
)
|
)
|
||||||
|
|
||||||
if problematic_apps:
|
if problematic_apps:
|
||||||
|
|
|
@ -23,12 +23,12 @@ def extract_app_from_venv_path(venv_path):
|
||||||
|
|
||||||
def _get_all_venvs(dir, level=0, maxlevel=3):
|
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:
|
Arguments:
|
||||||
dir - the directory to scan in
|
dir - the directory to scan in
|
||||||
maxlevel - the depth of the recursion
|
maxlevel - the depth of the recursion
|
||||||
level - do not edit this, used as an iterator
|
level - do not edit this, used as an iterator
|
||||||
"""
|
"""
|
||||||
# Using os functions instead of glob, because glob doesn't support hidden
|
# Using os functions instead of glob, because glob doesn't support hidden
|
||||||
# folders, and we need recursion with a fixed depth
|
# 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)
|
path = os.path.join(dir, file)
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
activatepath = os.path.join(path, "bin", "activate")
|
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)
|
result.append(path)
|
||||||
continue
|
continue
|
||||||
if level < maxlevel:
|
if level < maxlevel:
|
||||||
|
@ -50,6 +52,7 @@ class MyMigration(Migration):
|
||||||
After the update, recreate a python virtual env based on the previously
|
After the update, recreate a python virtual env based on the previously
|
||||||
generated requirements file
|
generated requirements file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ignored_python_apps = [
|
ignored_python_apps = [
|
||||||
"calibreweb",
|
"calibreweb",
|
||||||
"django-for-runners",
|
"django-for-runners",
|
||||||
|
@ -62,7 +65,7 @@ class MyMigration(Migration):
|
||||||
"pgadmin",
|
"pgadmin",
|
||||||
"tracim",
|
"tracim",
|
||||||
"synapse",
|
"synapse",
|
||||||
"weblate"
|
"weblate",
|
||||||
]
|
]
|
||||||
|
|
||||||
dependencies = ["migrate_to_bullseye"]
|
dependencies = ["migrate_to_bullseye"]
|
||||||
|
@ -70,7 +73,9 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
def is_pending(self):
|
def is_pending(self):
|
||||||
if not self.state:
|
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"
|
return self.state == "pending"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -101,18 +106,25 @@ class MyMigration(Migration):
|
||||||
app_corresponding_to_venv = extract_app_from_venv_path(venv)
|
app_corresponding_to_venv = extract_app_from_venv_path(venv)
|
||||||
|
|
||||||
# Search for ignore apps
|
# 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)
|
ignored_apps.append(app_corresponding_to_venv)
|
||||||
else:
|
else:
|
||||||
rebuild_apps.append(app_corresponding_to_venv)
|
rebuild_apps.append(app_corresponding_to_venv)
|
||||||
|
|
||||||
msg = m18n.n("migration_0024_rebuild_python_venv_disclaimer_base")
|
msg = m18n.n("migration_0024_rebuild_python_venv_disclaimer_base")
|
||||||
if rebuild_apps:
|
if rebuild_apps:
|
||||||
msg += "\n\n" + m18n.n("migration_0024_rebuild_python_venv_disclaimer_rebuild",
|
msg += "\n\n" + m18n.n(
|
||||||
rebuild_apps="\n - " + "\n - ".join(rebuild_apps))
|
"migration_0024_rebuild_python_venv_disclaimer_rebuild",
|
||||||
|
rebuild_apps="\n - " + "\n - ".join(rebuild_apps),
|
||||||
|
)
|
||||||
if ignored_apps:
|
if ignored_apps:
|
||||||
msg += "\n\n" + m18n.n("migration_0024_rebuild_python_venv_disclaimer_ignored",
|
msg += "\n\n" + m18n.n(
|
||||||
ignored_apps="\n - " + "\n - ".join(ignored_apps))
|
"migration_0024_rebuild_python_venv_disclaimer_ignored",
|
||||||
|
ignored_apps="\n - " + "\n - ".join(ignored_apps),
|
||||||
|
)
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
@ -124,25 +136,43 @@ class MyMigration(Migration):
|
||||||
app_corresponding_to_venv = extract_app_from_venv_path(venv)
|
app_corresponding_to_venv = extract_app_from_venv_path(venv)
|
||||||
|
|
||||||
# Search for ignore apps
|
# 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)
|
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
|
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
|
# Recreate the venv
|
||||||
rm(venv, recursive=True)
|
rm(venv, recursive=True)
|
||||||
callbacks = (
|
callbacks = (
|
||||||
lambda l: logger.debug("+ " + l.rstrip() + "\r"),
|
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)
|
call_async_output(["python", "-m", "venv", venv], callbacks)
|
||||||
status = call_async_output([
|
status = call_async_output(
|
||||||
f"{venv}/bin/pip", "install", "-r",
|
[f"{venv}/bin/pip", "install", "-r", venv + VENV_REQUIREMENTS_SUFFIX],
|
||||||
venv + VENV_REQUIREMENTS_SUFFIX], callbacks)
|
callbacks,
|
||||||
|
)
|
||||||
if status != 0:
|
if status != 0:
|
||||||
logger.error(m18n.n("migration_0024_rebuild_python_venv_failed",
|
logger.error(
|
||||||
app=app_corresponding_to_venv))
|
m18n.n(
|
||||||
|
"migration_0024_rebuild_python_venv_failed",
|
||||||
|
app=app_corresponding_to_venv,
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
rm(venv + VENV_REQUIREMENTS_SUFFIX)
|
rm(venv + VENV_REQUIREMENTS_SUFFIX)
|
||||||
|
|
|
@ -73,7 +73,7 @@ def tools_adminpw(new_password, check_strength=True):
|
||||||
from yunohost.user import _hash_user_password
|
from yunohost.user import _hash_user_password
|
||||||
from yunohost.utils.password import (
|
from yunohost.utils.password import (
|
||||||
assert_password_is_strong_enough,
|
assert_password_is_strong_enough,
|
||||||
assert_password_is_compatible
|
assert_password_is_compatible,
|
||||||
)
|
)
|
||||||
import spwd
|
import spwd
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ def tools_postinstall(
|
||||||
from yunohost.utils.dns import is_yunohost_dyndns_domain
|
from yunohost.utils.dns import is_yunohost_dyndns_domain
|
||||||
from yunohost.utils.password import (
|
from yunohost.utils.password import (
|
||||||
assert_password_is_strong_enough,
|
assert_password_is_strong_enough,
|
||||||
assert_password_is_compatible
|
assert_password_is_compatible,
|
||||||
)
|
)
|
||||||
from yunohost.domain import domain_main_domain
|
from yunohost.domain import domain_main_domain
|
||||||
import psutil
|
import psutil
|
||||||
|
|
|
@ -145,7 +145,7 @@ def user_create(
|
||||||
from yunohost.hook import hook_callback
|
from yunohost.hook import hook_callback
|
||||||
from yunohost.utils.password import (
|
from yunohost.utils.password import (
|
||||||
assert_password_is_strong_enough,
|
assert_password_is_strong_enough,
|
||||||
assert_password_is_compatible
|
assert_password_is_compatible,
|
||||||
)
|
)
|
||||||
from yunohost.utils.ldap import _get_ldap_interface
|
from yunohost.utils.ldap import _get_ldap_interface
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ def user_update(
|
||||||
from yunohost.app import app_ssowatconf
|
from yunohost.app import app_ssowatconf
|
||||||
from yunohost.utils.password import (
|
from yunohost.utils.password import (
|
||||||
assert_password_is_strong_enough,
|
assert_password_is_strong_enough,
|
||||||
assert_password_is_compatible
|
assert_password_is_compatible,
|
||||||
)
|
)
|
||||||
from yunohost.utils.ldap import _get_ldap_interface
|
from yunohost.utils.ldap import _get_ldap_interface
|
||||||
from yunohost.hook import hook_callback
|
from yunohost.hook import hook_callback
|
||||||
|
|
Loading…
Add table
Reference in a new issue