From 6adbe3eaef29de63a00db9a2ef2481317c65a3f7 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 9 Dec 2020 13:31:25 +0100 Subject: [PATCH] bugfix $YNH_APP_ARG_PATH handling --- conf/ynh_pyinventory_settings.py | 21 +++++++++++++++------ conf/ynh_urls.py | 12 +++++++++--- scripts/install | 6 ++---- scripts/upgrade | 7 ++----- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/conf/ynh_pyinventory_settings.py b/conf/ynh_pyinventory_settings.py index c3728b0..8b1bee1 100644 --- a/conf/ynh_pyinventory_settings.py +++ b/conf/ynh_pyinventory_settings.py @@ -17,15 +17,18 @@ DEBUG = False # ----------------------------------------------------------------------------- -FINAL_HOME_PATH = __Path('__FINAL_HOME_PATH__') +FINAL_HOME_PATH = __Path('__FINAL_HOME_PATH__') # /opt/yunohost/$app assert FINAL_HOME_PATH.is_dir(), f'Directory not exists: {FINAL_HOME_PATH}' -FINAL_WWW_PATH = __Path('__FINAL_WWW_PATH__') +FINAL_WWW_PATH = __Path('__FINAL_WWW_PATH__') # /var/www/$app assert FINAL_WWW_PATH.is_dir(), f'Directory not exists: {FINAL_WWW_PATH}' -LOG_FILE = __Path('__LOG_FILE__') +LOG_FILE = __Path('__LOG_FILE__') # /var/log/$app//pyinventory.log assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}' +PATH_URL = '__PATH_URL__' # $YNH_APP_ARG_PATH +PATH_URL = PATH_URL.strip('/') + # ----------------------------------------------------------------------------- ROOT_URLCONF = 'ynh_urls' # /opt/yunohost/pyinventory/ynh_urls.py @@ -92,12 +95,18 @@ CACHES = { # _____________________________________________________________________________ # Static files (CSS, JavaScript, Images) -STATIC_URL = '/static/' -STATIC_ROOT = str(FINAL_WWW_PATH / 'static') +if PATH_URL: + STATIC_URL = f'/{PATH_URL}/static/' + MEDIA_URL = f'/{PATH_URL}/media/' +else: + # Installed to domain root, without a path prefix? + STATIC_URL = '/static/' + MEDIA_URL = '/media/' -MEDIA_URL = '/media/' +STATIC_ROOT = str(FINAL_WWW_PATH / 'static') MEDIA_ROOT = str(FINAL_WWW_PATH / 'media') + # ----------------------------------------------------------------------------- LOGGING = { diff --git a/conf/ynh_urls.py b/conf/ynh_urls.py index 6b6fd78..a48847f 100644 --- a/conf/ynh_urls.py +++ b/conf/ynh_urls.py @@ -1,6 +1,12 @@ +from django.conf import settings from django.conf.urls import include from django.urls import path -urlpatterns = [ - path('__PATH_URL__/', include('inventory_project.urls')) -] \ No newline at end of file +# settings.PATH_URL is the $YNH_APP_ARG_PATH +if settings.PATH_URL: + urlpatterns = [ + path(f'{settings.PATH_URL}/', include('inventory_project.urls')) + ] +else: + # Installed to domain root, without a path prefix? + from inventory_project.urls import urlpatterns # noqa diff --git a/scripts/install b/scripts/install index 80f17d2..5158caf 100755 --- a/scripts/install +++ b/scripts/install @@ -142,6 +142,7 @@ ynh_replace_string --match_string="__ADMINMAIL__" --replace_string="$admin_mail" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$settings" ynh_replace_string --match_string="__FINAL_HOME_PATH__" --replace_string="$final_path" --target_file="$settings" ynh_replace_string --match_string="__FINAL_WWW_PATH__" --replace_string="$public_path" --target_file="$settings" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$settings" ynh_replace_string --match_string="__LOG_FILE__" --replace_string="$log_file" --target_file="$settings" ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$settings" @@ -152,10 +153,7 @@ ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" touch "$final_path/local_settings.py" -ynh_urls="$final_path/ynh_urls.py" -cp "../conf/ynh_urls.py" "$ynh_urls" -ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$ynh_urls" -ynh_store_file_checksum --file="$ynh_urls" +cp "../conf/ynh_urls.py" "$final_path/ynh_urls.py" #================================================= # MIGRATE / COLLECTSTATIC / CREATEADMIN diff --git a/scripts/upgrade b/scripts/upgrade index 296e375..66fbf55 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -132,6 +132,7 @@ ynh_replace_string --match_string="__ADMINMAIL__" --replace_string="$admin_mail" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$settings" ynh_replace_string --match_string="__FINAL_HOME_PATH__" --replace_string="$final_path" --target_file="$settings" ynh_replace_string --match_string="__FINAL_WWW_PATH__" --replace_string="$public_path" --target_file="$settings" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$settings" ynh_replace_string --match_string="__LOG_FILE__" --replace_string="$log_file" --target_file="$settings" ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$settings" @@ -140,11 +141,7 @@ ynh_store_file_checksum --file="$settings" touch "$final_path/local_settings.py" -ynh_urls="$final_path/ynh_urls.py" -ynh_backup_if_checksum_is_different --file="$ynh_urls" -cp "../conf/ynh_urls.py" "$ynh_urls" -ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$ynh_urls" -ynh_store_file_checksum --file="$ynh_urls" +cp "../conf/ynh_urls.py" "$final_path/ynh_urls.py" #================================================= # MIGRATE PYINVENTORY