1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pyinventory_ynh.git synced 2024-09-03 20:16:09 +02:00

bugfix $YNH_APP_ARG_PATH handling

This commit is contained in:
JensDiemer 2020-12-09 13:31:25 +01:00
parent 1d13378171
commit 6adbe3eaef
4 changed files with 28 additions and 18 deletions

View file

@ -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}' 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}' 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}' 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 ROOT_URLCONF = 'ynh_urls' # /opt/yunohost/pyinventory/ynh_urls.py
@ -92,12 +95,18 @@ CACHES = {
# _____________________________________________________________________________ # _____________________________________________________________________________
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/' if PATH_URL:
STATIC_ROOT = str(FINAL_WWW_PATH / 'static') 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') MEDIA_ROOT = str(FINAL_WWW_PATH / 'media')
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
LOGGING = { LOGGING = {

View file

@ -1,6 +1,12 @@
from django.conf import settings
from django.conf.urls import include from django.conf.urls import include
from django.urls import path from django.urls import path
urlpatterns = [ # settings.PATH_URL is the $YNH_APP_ARG_PATH
path('__PATH_URL__/', include('inventory_project.urls')) 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

View file

@ -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="__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_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="__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="__LOG_FILE__" --replace_string="$log_file" --target_file="$settings"
ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --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" touch "$final_path/local_settings.py"
ynh_urls="$final_path/ynh_urls.py" cp "../conf/ynh_urls.py" "$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"
#================================================= #=================================================
# MIGRATE / COLLECTSTATIC / CREATEADMIN # MIGRATE / COLLECTSTATIC / CREATEADMIN

View file

@ -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="__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_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="__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="__LOG_FILE__" --replace_string="$log_file" --target_file="$settings"
ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --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" touch "$final_path/local_settings.py"
ynh_urls="$final_path/ynh_urls.py" cp "../conf/ynh_urls.py" "$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"
#================================================= #=================================================
# MIGRATE PYINVENTORY # MIGRATE PYINVENTORY