Doc-strings and formatting

This commit is contained in:
theo@manjaro 2022-07-22 16:15:31 +02:00
parent 3fea05c4d6
commit 22fc36e16e

View file

@ -33,7 +33,16 @@ N_NEXT_YUNOHOST = 11
VENV_REQUIREMENTS_SUFFIX = "_req.txt" VENV_REQUIREMENTS_SUFFIX = "_req.txt"
VENV_IGNORE = "ynh_migration_no_regen" VENV_IGNORE = "ynh_migration_no_regen"
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
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 # 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):
@ -51,7 +60,11 @@ def _get_all_venvs(dir,level=0,maxlevel=3):
result += _get_all_venvs(path, level=level + 1) result += _get_all_venvs(path, level=level + 1)
return result return result
def _generate_requirements(): def _generate_requirements():
"""
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/")
for venv in venvs: for venv in venvs:
@ -60,6 +73,9 @@ def _generate_requirements():
def _rebuild_venvs(): def _rebuild_venvs():
"""
After the update, recreate a python virtual env based on the previously generated requirements file
"""
venvs = _get_all_venvs("/opt/") + _get_all_venvs("/var/www/") venvs = _get_all_venvs("/opt/") + _get_all_venvs("/var/www/")
for venv in venvs: for venv in venvs: