diff --git a/.editorconfig b/.editorconfig index 0f4b35f..94ac6c2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,7 @@ trim_trailing_whitespace = true insert_final_newline = true [*.py] -line_length = 119 +max_line_length = 120 [{Makefile,**.mk}] indent_style = tab @@ -18,4 +18,3 @@ insert_final_newline = false [*.yml] indent_style = tab -indent_size = 4 diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 6c67a3e..2b9263d 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -27,6 +27,11 @@ jobs: with: python-version: '${{ matrix.python-version }}' + - uses: actions/cache@v2 + with: + path: ~/.cache/ + key: dot-cache-files + - name: 'Install package' run: | pip3 install poetry diff --git a/README.md b/README.md index 1bd90d4..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,195 +0,0 @@ -# PyInventory for YunoHost - -[![Integration level](https://dash.yunohost.org/integration/pyinventory.svg)](https://dash.yunohost.org/appci/app/pyinventory) [![CI Pipeline](https://ci-apps.yunohost.org/ci/badges/pyinventory.status.svg)](https://ci-apps.yunohost.org/ci/apps/pyinventory/) [![Maintain status](https://ci-apps.yunohost.org/ci/badges/pyinventory.maintain.svg)](https://dash.yunohost.org/appci/app/pyinventory) - -[![pytest](https://github.com/YunoHost-Apps/pyinventory_ynh/actions/workflows/pytest.yml/badge.svg?branch=master)](https://github.com/YunoHost-Apps/pyinventory_ynh/actions/workflows/pytest.yml) [![YunoHost apps package linter](https://github.com/YunoHost-Apps/pyinventory_ynh/actions/workflows/package_linter.yml/badge.svg)](https://github.com/YunoHost-Apps/pyinventory_ynh/actions/workflows/package_linter.yml) [![Coverage Status on codecov.io](https://codecov.io/gh/YunoHost-Apps/pyinventory_ynh/branch/master/graph/badge.svg)](https://codecov.io/gh/YunoHost-Apps/pyinventory_ynh) - -[![Install PyInventory with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=pyinventory) - -> *This package allows you to install PyInventory quickly and simply on a YunoHost server. -If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* - -Pull requests welcome ;) - -## Overview - -[PyInventory](https://github.com/jedie/PyInventory) is a libre web-based management to catalog things including state and location etc. using [Python](https://www.python.org/)/[Django](https://www.djangoproject.com/). - -This package for YunoHost used [django-yunohost-integration](https://github.com/YunoHost-Apps/django_yunohost_integration) - -## Screenshots - -More screenshots are here: [jedie.github.io/tree/master/screenshots/PyInventory](https://github.com/jedie/jedie.github.io/blob/master/screenshots/PyInventory/README.creole) - ----- - -![PyInventory v0.2.0](https://raw.githubusercontent.com/jedie/jedie.github.io/master/screenshots/PyInventory/PyInventory%20v0.2.0%20screenshot%201.png) - ----- - -![PyInventory v0.1.0 screenshot 2](https://raw.githubusercontent.com/jedie/jedie.github.io/master/screenshots/PyInventory/PyInventory%20v0.1.0%20screenshot%202.png) - ----- - -![PyInventory v0.11.0 screenshot memo](https://raw.githubusercontent.com/jedie/jedie.github.io/master/screenshots/PyInventory/PyInventory%20v0.11.0%20screenshot%20memo%201.png) - ----- - -![PyInventory v0.1.0 screenshot 3](https://raw.githubusercontent.com/jedie/jedie.github.io/master/screenshots/PyInventory/PyInventory%20v0.1.0%20screenshot%203.png) - ----- - -More screenshots are here: [jedie.github.io/tree/master/screenshots/PyInventory](https://github.com/jedie/jedie.github.io/blob/master/screenshots/PyInventory/README.creole) - -## Settings and upgrades - -Almost everything related to PyInventory's configuration is handled in a `"../conf/settings.py"` file. -You can edit the file `/opt/yunohost/pyinventory/local_settings.py` to enable or disable features. - -Test sending emails: - -```bash -ssh admin@yourdomain.tld -root@yunohost:~# cd /opt/yunohost/pyinventory/ -root@yunohost:/opt/yunohost/pyinventory# source venv/bin/activate -(venv) root@yunohost:/opt/yunohost/pyinventory# ./manage.py sendtestemail --admins -``` - -Background info: Error mails are send to all [settings.ADMINS](https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-ADMINS). By default the YunoHost admin is inserted here. -To check current ADMINS run: - -```bash -(venv) root@yunohost:/opt/yunohost/pyinventory# ./manage.py sendtestemail --admins -``` - -If you prefere to send error emails to a extrnal email address, just do something like this: - -```bash -echo "ADMINS = (('Your Name', 'example@domain.tld'),)" >> /opt/yunohost/pyinventory/local_settings.py -``` - -To check the effective settings, run this: -```bash -(venv) root@yunohost:/opt/yunohost/pyinventory# ./manage.py diffsettings -``` - - -# Miscellaneous - - -## SSO authentication - -[SSOwat](https://github.com/YunoHost/SSOwat) is fully supported via [django-yunohost-integration](https://github.com/YunoHost-Apps/django_yunohost_integration): - -* First user (`$YNH_APP_ARG_ADMIN`) will be created as Django's super user -* All new users will be created as normal users -* Login via SSO is fully supported -* User Email, First / Last name will be updated from SSO data - - -## Links - - * Report a bug about this package: https://github.com/YunoHost-Apps/pyinventory_ynh - * Report a bug about PyInventory itself: https://github.com/jedie/PyInventory - * YunoHost website: https://yunohost.org/ - ---- - -# Developer info - -## package installation / debugging - -Please send your pull request to https://github.com/YunoHost-Apps/pyinventory_ynh - -Try 'main' branch, e.g.: -```bash -sudo yunohost app install https://github.com/YunoHost-Apps/pyinventory_ynh/tree/master --debug -or -sudo yunohost app upgrade pyinventory -u https://github.com/YunoHost-Apps/pyinventory_ynh/tree/master --debug -``` - -Try 'testing' branch, e.g.: -```bash -sudo yunohost app install https://github.com/YunoHost-Apps/pyinventory_ynh/tree/testing --debug -or -sudo yunohost app upgrade pyinventory -u https://github.com/YunoHost-Apps/pyinventory_ynh/tree/testing --debug -``` - -To remove call e.g.: -```bash -sudo yunohost app remove pyinventory -``` - -Backup / remove / restore cycle, e.g.: -```bash -yunohost backup create --apps pyinventory -yunohost backup list -archives: - - pyinventory-pre-upgrade1 - - 20201223-163434 -yunohost app remove pyinventory -yunohost backup restore 20201223-163434 --apps pyinventory -``` - -Debug installation, e.g.: -```bash -root@yunohost:~# ls -la /var/www/pyinventory/ -total 18 -drwxr-xr-x 4 root root 4 Dec 8 08:36 . -drwxr-xr-x 6 root root 6 Dec 8 08:36 .. -drwxr-xr-x 2 root root 2 Dec 8 08:36 media -drwxr-xr-x 7 root root 8 Dec 8 08:40 static - -root@yunohost:~# ls -la /opt/yunohost/pyinventory/ -total 58 -drwxr-xr-x 5 pyinventory pyinventory 11 Dec 8 08:39 . -drwxr-xr-x 3 root root 3 Dec 8 08:36 .. --rw-r--r-- 1 pyinventory pyinventory 460 Dec 8 08:39 gunicorn.conf.py --rw-r--r-- 1 pyinventory pyinventory 0 Dec 8 08:39 local_settings.py --rwxr-xr-x 1 pyinventory pyinventory 274 Dec 8 08:39 manage.py --rw-r--r-- 1 pyinventory pyinventory 171 Dec 8 08:39 secret.txt -drwxr-xr-x 6 pyinventory pyinventory 6 Dec 8 08:37 venv --rw-r--r-- 1 pyinventory pyinventory 115 Dec 8 08:39 wsgi.py --rw-r--r-- 1 pyinventory pyinventory 4737 Dec 8 08:39 settings.py - -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.2 (Django v2.2.17) -DJANGO_SETTINGS_MODULE='settings' -PROJECT_PATH:/opt/yunohost/pyinventory/venv/lib/python3.7/site-packages -BASE_PATH:/opt/yunohost/pyinventory -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:~# systemctl reload-or-restart pyinventory -root@yunohost:~# journalctl --unit=pyinventory --follow -``` - -## local test - -For quicker developing of PyInventory in the context of YunoHost app, -it's possible to run the Django developer server with the settings -and urls made for YunoHost installation. - -e.g.: -```bash -~$ git clone https://github.com/YunoHost-Apps/pyinventory_ynh.git -~$ cd pyinventory_ynh/ -~/pyinventory_ynh$ make -install-poetry install or update poetry -install install PyInventory via poetry -update update the sources and installation -local-test Run local_test.py to run pyinventory_ynh locally -~/pyinventory_ynh$ make install-poetry -~/pyinventory_ynh$ make install -~/pyinventory_ynh$ make local-test -``` - -Notes: - -* SQlite database will be used -* A super user with username `test` and password `test` is created -* The page is available under `http://127.0.0.1:8000/app_path/` diff --git a/conf/settings.py b/conf/settings.py index 750ba08..b2f60cb 100644 --- a/conf/settings.py +++ b/conf/settings.py @@ -75,8 +75,8 @@ MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': '__APP__', - 'USER': '__APP__', + 'NAME': '__DB_NAME__', + 'USER': '__DB_USER__', 'PASSWORD': '__DB_PWD__', 'HOST': '127.0.0.1', 'PORT': '5432', # Default Postgres Port diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..f889519 --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1,15 @@ +[PyInventory](https://github.com/jedie/PyInventory) is a libre web-based management to catalog things including state and location etc. using [Python](https://www.python.org/)/[Django](https://www.djangoproject.com/). + +[![Integration level](https://dash.yunohost.org/integration/pyinventory.svg)](https://dash.yunohost.org/appci/app/pyinventory) [![CI Pipeline](https://ci-apps.yunohost.org/ci/badges/pyinventory.status.svg)](https://ci-apps.yunohost.org/ci/apps/pyinventory/) [![Maintain status](https://ci-apps.yunohost.org/ci/badges/pyinventory.maintain.svg)](https://dash.yunohost.org/appci/app/pyinventory) + +[![pytest](https://github.com/YunoHost-Apps/pyinventory_ynh/actions/workflows/pytest.yml/badge.svg?branch=master)](https://github.com/YunoHost-Apps/pyinventory_ynh/actions/workflows/pytest.yml) [![YunoHost apps package linter](https://github.com/YunoHost-Apps/pyinventory_ynh/actions/workflows/package_linter.yml/badge.svg)](https://github.com/YunoHost-Apps/pyinventory_ynh/actions/workflows/package_linter.yml) [![Coverage Status on codecov.io](https://codecov.io/gh/YunoHost-Apps/pyinventory_ynh/branch/master/graph/badge.svg)](https://codecov.io/gh/YunoHost-Apps/pyinventory_ynh) + +![pyinventory @ PyPi](https://img.shields.io/pypi/v/pyinventory?label=pyinventory%20%40%20PyPi) +![Python Versions](https://img.shields.io/pypi/pyversions/pyinventory) +![License GPL V3+](https://img.shields.io/pypi/l/pyinventory) + +Pull requests welcome ;) + +This package for YunoHost used [django-yunohost-integration](https://github.com/YunoHost-Apps/django_yunohost_integration) + +More screenshots are here: jedie.github.io/tree/master/screenshots/PyInventory diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..850e785 --- /dev/null +++ b/doc/DISCLAIMER.md @@ -0,0 +1,152 @@ +## Settings and upgrades + +Almost everything related to PyInventory's configuration is handled in a `"../conf/settings.py"` file. +You can edit the file `/opt/yunohost/pyinventory/local_settings.py` to enable or disable features. + +Test sending emails: + +```bash +ssh admin@yourdomain.tld +root@yunohost:~# cd /opt/yunohost/pyinventory/ +root@yunohost:/opt/yunohost/pyinventory# source venv/bin/activate +(venv) root@yunohost:/opt/yunohost/pyinventory# ./manage.py sendtestemail --admins +``` + +Background info: Error mails are send to all [settings.ADMINS](https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-ADMINS). By default the YunoHost admin is inserted here. +To check current ADMINS run: + +```bash +(venv) root@yunohost:/opt/yunohost/pyinventory# ./manage.py sendtestemail --admins +``` + +If you prefere to send error emails to a extrnal email address, just do something like this: + +```bash +echo "ADMINS = (('Your Name', 'example@domain.tld'),)" >> /opt/yunohost/pyinventory/local_settings.py +``` + +To check the effective settings, run this: +```bash +(venv) root@yunohost:/opt/yunohost/pyinventory# ./manage.py diffsettings +``` + + +# Miscellaneous + + +## SSO authentication + +[SSOwat](https://github.com/YunoHost/SSOwat) is fully supported via [django-yunohost-integration](https://github.com/YunoHost-Apps/django_yunohost_integration): + +* First user (`$YNH_APP_ARG_ADMIN`) will be created as Django's super user +* All new users will be created as normal users +* Login via SSO is fully supported +* User Email, First / Last name will be updated from SSO data + + +## Links + + * Report a bug about this package: https://github.com/YunoHost-Apps/pyinventory_ynh + * Report a bug about PyInventory itself: https://github.com/jedie/PyInventory + * YunoHost website: https://yunohost.org/ + +--- + +# Developer info + +## package installation / debugging + +Please send your pull request to https://github.com/YunoHost-Apps/pyinventory_ynh + +Try 'main' branch, e.g.: +```bash +sudo yunohost app install https://github.com/YunoHost-Apps/pyinventory_ynh/tree/master --debug +or +sudo yunohost app upgrade pyinventory -u https://github.com/YunoHost-Apps/pyinventory_ynh/tree/master --debug +``` + +Try 'testing' branch, e.g.: +```bash +sudo yunohost app install https://github.com/YunoHost-Apps/pyinventory_ynh/tree/testing --debug +or +sudo yunohost app upgrade pyinventory -u https://github.com/YunoHost-Apps/pyinventory_ynh/tree/testing --debug +``` + +To remove call e.g.: +```bash +sudo yunohost app remove pyinventory +``` + +Backup / remove / restore cycle, e.g.: +```bash +yunohost backup create --apps pyinventory +yunohost backup list +archives: + - pyinventory-pre-upgrade1 + - 20201223-163434 +yunohost app remove pyinventory +yunohost backup restore 20201223-163434 --apps pyinventory +``` + +Debug installation, e.g.: +```bash +root@yunohost:~# ls -la /var/www/pyinventory/ +total 18 +drwxr-xr-x 4 root root 4 Dec 8 08:36 . +drwxr-xr-x 6 root root 6 Dec 8 08:36 .. +drwxr-xr-x 2 root root 2 Dec 8 08:36 media +drwxr-xr-x 7 root root 8 Dec 8 08:40 static + +root@yunohost:~# ls -la /opt/yunohost/pyinventory/ +total 58 +drwxr-xr-x 5 pyinventory pyinventory 11 Dec 8 08:39 . +drwxr-xr-x 3 root root 3 Dec 8 08:36 .. +-rw-r--r-- 1 pyinventory pyinventory 460 Dec 8 08:39 gunicorn.conf.py +-rw-r--r-- 1 pyinventory pyinventory 0 Dec 8 08:39 local_settings.py +-rwxr-xr-x 1 pyinventory pyinventory 274 Dec 8 08:39 manage.py +-rw-r--r-- 1 pyinventory pyinventory 171 Dec 8 08:39 secret.txt +drwxr-xr-x 6 pyinventory pyinventory 6 Dec 8 08:37 venv +-rw-r--r-- 1 pyinventory pyinventory 115 Dec 8 08:39 wsgi.py +-rw-r--r-- 1 pyinventory pyinventory 4737 Dec 8 08:39 settings.py + +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.2 (Django v2.2.17) +DJANGO_SETTINGS_MODULE='settings' +PROJECT_PATH:/opt/yunohost/pyinventory/venv/lib/python3.7/site-packages +BASE_PATH:/opt/yunohost/pyinventory +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:~# systemctl reload-or-restart pyinventory +root@yunohost:~# journalctl --unit=pyinventory --follow +``` + +## local test + +For quicker developing of PyInventory in the context of YunoHost app, +it's possible to run the Django developer server with the settings +and urls made for YunoHost installation. + +e.g.: +```bash +~$ git clone https://github.com/YunoHost-Apps/pyinventory_ynh.git +~$ cd pyinventory_ynh/ +~/pyinventory_ynh$ make +install-poetry install or update poetry +install install PyInventory via poetry +update update the sources and installation +local-test Run local_test.py to run pyinventory_ynh locally +~/pyinventory_ynh$ make install-poetry +~/pyinventory_ynh$ make install +~/pyinventory_ynh$ make local-test +``` + +Notes: + +* SQlite database will be used +* A super user with username `test` and password `test` is created +* The page is available under `http://127.0.0.1:8000/app_path/` diff --git a/doc/screenshots/gitkeep b/doc/screenshots/gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/screenshots/pyinventory_v010_screenshot_2.png b/doc/screenshots/pyinventory_v010_screenshot_2.png new file mode 100644 index 0000000..ef2b0e2 Binary files /dev/null and b/doc/screenshots/pyinventory_v010_screenshot_2.png differ diff --git a/doc/screenshots/pyinventory_v010_screenshot_3.png b/doc/screenshots/pyinventory_v010_screenshot_3.png new file mode 100644 index 0000000..f912499 Binary files /dev/null and b/doc/screenshots/pyinventory_v010_screenshot_3.png differ diff --git a/doc/screenshots/pyinventory_v0110_screenshot_memo_1.png b/doc/screenshots/pyinventory_v0110_screenshot_memo_1.png new file mode 100644 index 0000000..fff235e Binary files /dev/null and b/doc/screenshots/pyinventory_v0110_screenshot_memo_1.png differ diff --git a/doc/screenshots/pyinventory_v020_screenshot_1.png b/doc/screenshots/pyinventory_v020_screenshot_1.png new file mode 100644 index 0000000..2b21e2b Binary files /dev/null and b/doc/screenshots/pyinventory_v020_screenshot_1.png differ diff --git a/manifest.json b/manifest.json index b299c3c..83fe4db 100644 --- a/manifest.json +++ b/manifest.json @@ -7,6 +7,11 @@ }, "version": "0.14.0~ynh1", "url": "https://github.com/jedie/PyInventory", + "upstream": { + "license": "GPL-3.0", + "website": "https://github.com/jedie/PyInventory", + "code": "https://github.com/jedie/PyInventory" + }, "license": "GPL-3.0", "maintainer": { "name": "Jens Diemer", @@ -14,7 +19,7 @@ }, "previous_maintainers": [], "requirements": { - "yunohost": ">= 4.0" + "yunohost": ">= 4.4" }, "multi_instance": true, "services": [ @@ -24,8 +29,7 @@ "install" : [ { "name": "domain", - "type": "domain", - "example": "domain.org" + "type": "domain" }, { "name": "path", @@ -35,9 +39,8 @@ }, { "name": "admin", - "type": "user", - "example": "johndoe" - } - ] + "type": "user" + } + ] } } diff --git a/poetry.lock b/poetry.lock index b17ada9..741822c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -464,6 +464,14 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "editorconfig" +version = "0.12.3" +description = "EditorConfig File Locator and Interpreter for Python" +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "et-xmlfile" version = "1.1.0" @@ -1123,7 +1131,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = ">=3.7,<4.0.0" -content-hash = "476528099d63f6382ff7d45a8cbabf9636fcc58b21fa82aa5687218df43a8a8b" +content-hash = "55a6bb103d5ba4398f3a8968b32297d65abee31751e3bcc2989eb883663bddc0" [metadata.files] asgiref = [ @@ -1336,6 +1344,10 @@ django-yunohost-integration = [ docopt = [ {file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"}, ] +editorconfig = [ + {file = "EditorConfig-0.12.3-py3-none-any.whl", hash = "sha256:6b0851425aa875b08b16789ee0eeadbd4ab59666e9ebe728e526314c4a2e52c1"}, + {file = "EditorConfig-0.12.3.tar.gz", hash = "sha256:57f8ce78afcba15c8b18d46b5170848c88d56fd38f05c2ec60dbbfcb8996e89e"}, +] et-xmlfile = [ {file = "et_xmlfile-1.1.0-py3-none-any.whl", hash = "sha256:a2ba85d1d6a74ef63837eed693bcb89c3f752169b0e3e7ae5b16ca5e1b3deada"}, {file = "et_xmlfile-1.1.0.tar.gz", hash = "sha256:8eb9e2bc2f8c97e37a2dc85a09ecdcdec9d8a396530a6d5a33b30b9a92da0c5c"}, diff --git a/pyproject.toml b/pyproject.toml index 344d4ba..832c5d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ authors = ["JensDiemer "] license = "GPL" [tool.poetry.dependencies] +# Keep Python 3.7 until Yunohost contains a newer Python Version ;) python = ">=3.7,<4.0.0" pyinventory = {version = ">=0.14.0", extras = ["psycopg2-source"]} @@ -28,9 +29,10 @@ pytest-isort = "*" coveralls = "*" flynt = "*" pyupgrade = "*" +EditorConfig = "*" # https://github.com/editorconfig/editorconfig-core-py [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" @@ -100,7 +102,7 @@ addopts = """ legacy_tox_ini = """ [tox] isolated_build = True -envlist = py39,py38,py37 +envlist = px310,py39,py38,py37 skip_missing_interpreters = True [testenv] diff --git a/scripts/install b/scripts/install index 21093ae..d568634 100755 --- a/scripts/install +++ b/scripts/install @@ -142,6 +142,8 @@ settings="$final_path/settings.py" cp "../conf/settings.py" "$settings" ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$settings" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$settings" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$settings" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$settings" ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="$settings" ynh_replace_string --match_string="__ADMINMAIL__" --replace_string="$admin_mail" --target_file="$settings" diff --git a/scripts/upgrade b/scripts/upgrade index cae4641..4bd17b5 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,7 +21,11 @@ domain=$(ynh_app_setting_get --app="$app" --key=domain) path_url=$(ynh_app_setting_get --app="$app" --key=path) port=$(ynh_app_setting_get --app="$app" --key=port) + db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd) +db_name=$(ynh_sanitize_dbid --db_name="$app") +db_user=$db_name + admin_mail=$(ynh_user_get_info "$admin" mail) redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db) @@ -130,6 +134,8 @@ ynh_backup_if_checksum_is_different --file="$settings" cp "../conf/settings.py" "$settings" ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$settings" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$settings" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$settings" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$settings" ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="$settings" ynh_replace_string --match_string="__ADMINMAIL__" --replace_string="$admin_mail" --target_file="$settings" diff --git a/tests/test_project_setup.py b/tests/test_project_setup.py index e48f9c5..98e50c2 100644 --- a/tests/test_project_setup.py +++ b/tests/test_project_setup.py @@ -4,7 +4,8 @@ import shutil import subprocess from pathlib import Path -from bx_py_utils.path import assert_is_file +from django_tools.serve_media_app.utils import clean_filename +from django_tools.unittest_utils.assertments import assert_is_dir, assert_is_file import inventory @@ -23,8 +24,12 @@ def assert_file_contains_string(file_path, string): def test_version(): version = inventory.__version__ - assert_file_contains_string(file_path=Path(PACKAGE_ROOT, 'pyproject.toml'), string=f'version = "{version}~ynh') - assert_file_contains_string(file_path=Path(PACKAGE_ROOT, 'manifest.json'), string=f'"version": "{version}~ynh') + assert_file_contains_string( + file_path=Path(PACKAGE_ROOT, 'pyproject.toml'), string=f'version = "{version}~ynh' + ) + assert_file_contains_string( + file_path=Path(PACKAGE_ROOT, 'manifest.json'), string=f'"version": "{version}~ynh' + ) def poetry_check_output(*args): @@ -32,7 +37,7 @@ def poetry_check_output(*args): output = subprocess.check_output( (poerty_bin,) + args, - universal_newlines=True, + text=True, env=os.environ, stderr=subprocess.STDOUT, cwd=str(PACKAGE_ROOT), @@ -57,8 +62,28 @@ def test_requirements_txt(): diff = '\n'.join( difflib.unified_diff( - current_content.splitlines(), output.splitlines(), fromfile=str(requirements_txt), tofile='FRESH EXPORT' + current_content.splitlines(), + output.splitlines(), + fromfile=str(requirements_txt), + tofile='FRESH EXPORT', ) ) print(diff) assert diff == '', f'{requirements_txt} is not up-to-date! (Hint: call: "make update")' + + +def test_screenshot_filenames(): + """ + https://forum.yunohost.org/t/yunohost-bot-cant-handle-spaces-in-screenshots/19483 + """ + screenshot_path = PACKAGE_ROOT / 'doc' / 'screenshots' + assert_is_dir(screenshot_path) + renamed = [] + for file_path in screenshot_path.iterdir(): + file_name = file_path.name + cleaned_name = clean_filename(file_name) + if cleaned_name != file_name: + new_path = file_path.with_name(cleaned_name) + file_path.rename(new_path) + renamed.append(f'{file_name!r} renamed to {cleaned_name!r}') + assert not renamed, f'Bad screenshots file names found: {", ".join(renamed)}'