diff --git a/conf/gunicorn.conf.py b/conf/gunicorn.conf.py index bcab967..f49a397 100644 --- a/conf/gunicorn.conf.py +++ b/conf/gunicorn.conf.py @@ -17,4 +17,4 @@ accesslog = '__LOG_FILE__' errorlog = '__LOG_FILE__' # https://docs.gunicorn.org/en/latest/settings.html#pidfile -pidfile = '__FINAL_HOME_PATH__/gunicorn.pid' +pidfile = '__FINALPATH__/gunicorn.pid' diff --git a/conf/manage.py b/conf/manage.py index 9962cbd..ec26808 100755 --- a/conf/manage.py +++ b/conf/manage.py @@ -1,4 +1,4 @@ -#!__FINAL_HOME_PATH__/venv/bin/python +#!__FINALPATH__/venv/bin/python import os import sys diff --git a/conf/settings.py b/conf/settings.py index 114b29d..f2f3539 100644 --- a/conf/settings.py +++ b/conf/settings.py @@ -2,7 +2,7 @@ ################################################################################ # Please do not modify this file, it will be reset at the next update. -# You can edit the file __FINAL_HOME_PATH__/local_settings.py and add/modify the settings you need. +# You can edit the file __FINALPATH__/local_settings.py and add/modify the settings you need. # The parameters you add in local_settings.py will overwrite these, # but you can use the options and documentation in this file to find out what can be done. @@ -19,11 +19,8 @@ DEBUG = False # Don't turn DEBUG on in production! # ----------------------------------------------------------------------------- -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__') # /var/www/$app -assert FINAL_WWW_PATH.is_dir(), f'Directory not exists: {FINAL_WWW_PATH}' +FINALPATH = __Path('__FINALPATH__') # /var/www/$app +assert FINALPATH.is_dir(), f'Directory not exists: {FINALPATH}' LOG_FILE = __Path('__LOG_FILE__') # /var/log/$app/django_example_ynh.log assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}' @@ -36,7 +33,7 @@ PATH_URL = PATH_URL.strip('/') # Function that will be called to finalize a user profile: YNH_SETUP_USER = 'setup_user.setup_project_user' -SECRET_KEY = __get_or_create_secret(FINAL_HOME_PATH / 'secret.txt') # /opt/yunohost/$app/secret.txt +SECRET_KEY = __get_or_create_secret(FINALPATH / 'secret.txt') # /opt/yunohost/$app/secret.txt # INSTALLED_APPS.append('') @@ -106,8 +103,8 @@ else: STATIC_URL = '/static/' MEDIA_URL = '/media/' -STATIC_ROOT = str(FINAL_WWW_PATH / 'static') -MEDIA_ROOT = str(FINAL_WWW_PATH / 'media') +STATIC_ROOT = str(FINALPATH / 'static') +MEDIA_ROOT = str(FINALPATH / 'media') # ----------------------------------------------------------------------------- diff --git a/conf/urls.py b/conf/urls.py index d4c6133..e76b15e 100644 --- a/conf/urls.py +++ b/conf/urls.py @@ -1,12 +1,36 @@ +""" + urls.py + ~~~~~~~ + + Note: This is not a good example how your urls.py can look like. + Because this setup is just an example without a real Python application. + + Look at real examples, here: + + * https://github.com/YunoHost-Apps/django-fritzconnection_ynh/blob/master/conf/urls.py + * https://github.com/YunoHost-Apps/django-for-runners_ynh/blob/testing/conf/urls.py + * https://github.com/YunoHost-Apps/pyinventory_ynh/blob/testing/conf/urls.py + +""" + + from django.conf import settings from django.contrib import admin from django.urls import path + from django_yunohost_integration.views import request_media_debug_view -# settings.PATH_URL is the $YNH_APP_ARG_PATH -# Prefix all urls with "PATH_URL": -urlpatterns = [ - path(f'{settings.PATH_URL}/', admin.site.urls), - path(f'{settings.PATH_URL}/debug/', request_media_debug_view), -] +if settings.PATH_URL: + # settings.PATH_URL is the $YNH_APP_ARG_PATH + # Prefix all urls with "PATH_URL": + urlpatterns = [ + path(f'{settings.PATH_URL}/', admin.site.urls), + path(f'{settings.PATH_URL}/debug/', request_media_debug_view), + ] +else: + # Installed to domain root, without a path prefix + urlpatterns = [ + path('/', admin.site.urls), + path('/debug/', request_media_debug_view), + ] diff --git a/pyproject.toml b/pyproject.toml index c826f28..9ce7b39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,7 @@ line_length = 100 atomic=true profile='black' skip_glob=["*/htmlcov/*","*/migrations/*"] -known_first_party=[] +known_first_party=['django_yunohost_integration'] line_length=100 lines_after_imports=2 diff --git a/scripts/_common.sh b/scripts/_common.sh index b95ce9c..3d25ad6 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -15,8 +15,7 @@ app=$YNH_APP_INSTANCE_NAME # SET CONSTANTS #================================================= -public_path=/var/www/$app -final_path=/opt/yunohost/$app +final_path=/var/www/$app log_path=/var/log/$app log_file="${log_path}/django_example_ynh.log" diff --git a/scripts/backup b/scripts/backup index 308ba1c..f24714a 100755 --- a/scripts/backup +++ b/scripts/backup @@ -18,7 +18,7 @@ ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -public_path=$(ynh_app_setting_get --app="$app" --key=public_path) +final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app="$app" --key=final_path) db_name=$(ynh_app_setting_get --app="$app" --key=db_name) @@ -34,7 +34,7 @@ ynh_print_info --message="Declaring files to be backed up..." #================================================= ynh_backup --src_path="$final_path" -ynh_backup --src_path="$public_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/change_url b/scripts/change_url index b119369..3d29b34 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -25,7 +25,7 @@ new_path=$YNH_APP_NEW_PATH ynh_script_progression --message="Loading installation settings..." admin=$(ynh_app_setting_get --app="$app" --key=admin) -public_path=$(ynh_app_setting_get --app="$app" --key=public_path) +final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app="$app" --key=final_path) log_path=$(ynh_app_setting_get --app="$app" --key=log_path) @@ -94,7 +94,7 @@ then domain="$old_domain" path_url="$new_path" # Create a dedicated nginx config - ynh_add_nginx_config "public_path" "port" + ynh_add_nginx_config "final_path" "port" fi # Change the domain for nginx diff --git a/scripts/install b/scripts/install index a808194..c7ac1ec 100755 --- a/scripts/install +++ b/scripts/install @@ -20,7 +20,7 @@ ynh_abort_if_errors ynh_script_progression --message="Validating installation parameters..." # Path for e.g. "static" files, served by nginx: -test ! -e "$public_path" || ynh_die --message="This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Path for own config files, e.g.: Django's settings.py: test ! -e "$final_path" || ynh_die --message="This path already contains a folder" @@ -28,7 +28,7 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde # Register (book) web path ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url" -mkdir -p "$public_path/media" "$public_path/static" +mkdir -p "$final_path/media" "$final_path/static" mkdir -p "$final_path" mkdir -p "$log_path" @@ -40,7 +40,7 @@ touch "${log_file}" ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app="$app" --key=admin --value="$admin" -ynh_app_setting_set --app="$app" --key=public_path --value="$public_path" +ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" ynh_app_setting_set --app="$app" --key=log_path --value="$log_file" @@ -92,7 +92,7 @@ ynh_script_progression --message="Configuring nginx web server..." # Create a dedicated nginx config # https://github.com/YunoHost/yunohost/blob/dev/data/helpers.d/nginx -ynh_add_nginx_config "public_path" "port" +ynh_add_nginx_config "final_path" "port" #================================================= # CREATE DEDICATED USER @@ -186,11 +186,11 @@ yunohost service add $app --description="Web based management to catalog things" # Set permissions to app files chown -R "$app:" "$log_path" -chown -R "$app:www-data" "$public_path" +chown -R "$app:www-data" "$final_path" chown -R "$app:" "$final_path" chmod o-rwx "$log_path" -chmod o-rwx "$public_path" +chmod o-rwx "$final_path" chmod o-rwx "$final_path" #================================================= diff --git a/scripts/remove b/scripts/remove index 5e630a4..213b7ba 100755 --- a/scripts/remove +++ b/scripts/remove @@ -17,7 +17,7 @@ ynh_script_progression --message="Loading installation settings..." domain=$(ynh_app_setting_get --app="$app" --key=domain) db_name=$(ynh_app_setting_get --app="$app" --key=db_name) db_user=$db_name -public_path=$(ynh_app_setting_get --app="$app" --key=public_path) +final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app="$app" --key=final_path) #================================================= @@ -68,7 +68,7 @@ ynh_exec_warn_less ynh_remove_app_dependencies ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely -ynh_secure_remove --file="$public_path" +ynh_secure_remove --file="$final_path" ynh_secure_remove --file="$final_path" #================================================= diff --git a/scripts/restore b/scripts/restore index 02ccd11..fcc7dbb 100755 --- a/scripts/restore +++ b/scripts/restore @@ -20,7 +20,7 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Loading settings..." -public_path=$(ynh_app_setting_get --app="$app" --key=public_path) +final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app="$app" --key=final_path) db_name=$(ynh_app_setting_get --app="$app" --key=db_name) db_user=$db_name @@ -50,7 +50,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file --origin_path="$public_path" +ynh_restore_file --origin_path="$final_path" ynh_restore_file --origin_path="$final_path" touch "$final_path/local_settings.py" @@ -68,7 +68,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell #================================================= # Restore permissions on app files -chown -R "$app:www-data" "$public_path" +chown -R "$app:www-data" "$final_path" chown -R "$app:" "$final_path" #================================================= @@ -144,11 +144,11 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" # Set permissions to app files chown -R "$app:" "$log_path" -chown -R "$app:www-data" "$public_path" +chown -R "$app:www-data" "$final_path" chown -R "$app:" "$final_path" chmod o-rwx "$log_path" -chmod o-rwx "$public_path" +chmod o-rwx "$final_path" chmod o-rwx "$final_path" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index de9ec43..5ef4cc0 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers ynh_script_progression --message="Loading installation settings..." admin=$(ynh_app_setting_get --app="$app" --key=admin) -public_path=$(ynh_app_setting_get --app="$app" --key=public_path) +final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app="$app" --key=final_path) log_path=$(ynh_app_setting_get --app="$app" --key=log_path) @@ -68,7 +68,7 @@ ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config # https://github.com/YunoHost/yunohost/blob/dev/data/helpers.d/nginx -ynh_add_nginx_config "public_path" "port" +ynh_add_nginx_config "final_path" "port" #================================================= # SPECIFIC UPGRADE @@ -178,11 +178,11 @@ yunohost service add $app --description="Web based management to catalog things" # Set permissions to app files chown -R "$app:" "$log_path" -chown -R "$app:www-data" "$public_path" +chown -R "$app:www-data" "$final_path" chown -R "$app:" "$final_path" chmod o-rwx "$log_path" -chmod o-rwx "$public_path" +chmod o-rwx "$final_path" chmod o-rwx "$final_path" #================================================= diff --git a/tests/test_django_project.py b/tests/test_django_project.py index ca51772..5cd787a 100644 --- a/tests/test_django_project.py +++ b/tests/test_django_project.py @@ -20,8 +20,9 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase): def test_settings(self): assert settings.PATH_URL == 'app_path' - assert str(settings.FINAL_HOME_PATH).endswith('/local_test/opt_yunohost') - assert str(settings.FINAL_WWW_PATH).endswith('/local_test/var_www') + # TODO: Switch to: assert str(settings.FINALPATH).endswith('/local_test/var_www') + assert str(settings.FINALPATH).endswith('/local_test/opt_yunohost') + assert str(settings.LOG_FILE).endswith('/local_test/var_log_django_example_ynh.log') assert settings.ROOT_URLCONF == 'urls'