From 1d133781713317481e4d30ac2e76fb793911b0fa Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 9 Dec 2020 12:05:24 +0100 Subject: [PATCH 1/3] Use own urls.py to support $YNH_APP_ARG_PATH --- README.md | 6 ++++-- conf/ynh_pyinventory_settings.py | 4 ++++ conf/ynh_urls.py | 6 ++++++ manifest.json | 12 +++++++++++- scripts/_common.sh | 4 ++-- scripts/install | 6 ++++++ scripts/upgrade | 6 ++++++ 7 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 conf/ynh_urls.py diff --git a/README.md b/README.md index 6719244..e4b4976 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ drwxr-xr-x 6 pyinventory pyinventory 6 Dec 8 08:37 venv root@yunohost:~# cd /opt/yunohost/pyinventory/ root@yunohost:/opt/yunohost/pyinventory# source venv/bin/activate (venv) root@yunohost:/opt/yunohost/pyinventory# ./manage.py check -PyInventory v0.8.1rc1 (Django v2.2.17) +PyInventory v0.8.1rc2 (Django v2.2.17) DJANGO_SETTINGS_MODULE='ynh_pyinventory_settings' PROJECT_PATH:/opt/yunohost/pyinventory/venv/lib/python3.7/site-packages BASE_PATH:/opt/yunohost/pyinventory @@ -99,5 +99,7 @@ System check identified no issues (0 silenced). root@yunohost:~# tail -f /var/log/pyinventory/pyinventory.log root@yunohost:~# cat /etc/systemd/system/pyinventory.service -root@yunohost:~# ynh_systemd_action --service_name="pyinventory" --action="restart" + +root@yunohost:~# systemctl reload-or-restart pyinventory +root@yunohost:~# journalctl --unit=pyinventory --follow ``` \ No newline at end of file diff --git a/conf/ynh_pyinventory_settings.py b/conf/ynh_pyinventory_settings.py index dfab0db..c3728b0 100644 --- a/conf/ynh_pyinventory_settings.py +++ b/conf/ynh_pyinventory_settings.py @@ -28,6 +28,10 @@ assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}' # ----------------------------------------------------------------------------- +ROOT_URLCONF = 'ynh_urls' # /opt/yunohost/pyinventory/ynh_urls.py + +# ----------------------------------------------------------------------------- + ADMINS = ( ('__ADMIN__', '__ADMINMAIL__'), ) diff --git a/conf/ynh_urls.py b/conf/ynh_urls.py new file mode 100644 index 0000000..6b6fd78 --- /dev/null +++ b/conf/ynh_urls.py @@ -0,0 +1,6 @@ +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 diff --git a/manifest.json b/manifest.json index a081c8a..0035b61 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": { "en": "Web based management to catalog things including state and location etc." }, - "version": "0.8.1rc1~ynh2", + "version": "0.8.1rc2~ynh1", "url": "https://github.com/jedie/PyInventory", "license": "GPL-3.0", "maintainer": { @@ -31,6 +31,16 @@ }, "example": "domain.org" }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for PyInventory", + "fr": "Choisissez un chemin pour PyInventory" + }, + "example": "/pyinventory", + "default": "/pyinventory" + }, { "name": "admin", "type": "user", diff --git a/scripts/_common.sh b/scripts/_common.sh index 8db757c..bf76472 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= domain=$YNH_APP_ARG_DOMAIN -path_url="/" +path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME @@ -28,7 +28,7 @@ pkg_dependencies="build-essential python3-dev python3-pip python3-virtualenv vir postgresql postgresql-contrib" # PyInventory's version for PIP and settings file -pyinventory_version="0.8.1rc1" +pyinventory_version="0.8.1rc2" #================================================= diff --git a/scripts/install b/scripts/install index c4b20fa..80f17d2 100755 --- a/scripts/install +++ b/scripts/install @@ -125,6 +125,7 @@ cp "../conf/gunicorn.conf.py" "$gunicorn_conf" ynh_replace_string --match_string="__FINAL_HOME_PATH__" --replace_string="$final_path" --target_file="$gunicorn_conf" ynh_replace_string --match_string="__LOG_FILE__" --replace_string="$log_file" --target_file="$gunicorn_conf" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$gunicorn_conf" +ynh_store_file_checksum --file="$gunicorn_conf" cp ../conf/manage.py "$final_path/manage.py" chmod +x "$final_path/manage.py" @@ -151,6 +152,11 @@ 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" + #================================================= # MIGRATE / COLLECTSTATIC / CREATEADMIN #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 8c27a58..296e375 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -140,6 +140,12 @@ 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" + #================================================= # MIGRATE PYINVENTORY #================================================= From 6adbe3eaef29de63a00db9a2ef2481317c65a3f7 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 9 Dec 2020 13:31:25 +0100 Subject: [PATCH 2/3] 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 From a14b8beeb0d5558a01df39103b2ce6f33357f2b4 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 9 Dec 2020 13:36:30 +0100 Subject: [PATCH 3/3] Bump version to 0.8.1rc3~ynh1 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 0035b61..93f8c95 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": { "en": "Web based management to catalog things including state and location etc." }, - "version": "0.8.1rc2~ynh1", + "version": "0.8.1rc3~ynh1", "url": "https://github.com/jedie/PyInventory", "license": "GPL-3.0", "maintainer": {