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

Merge branch 'testing' into update

This commit is contained in:
Jens Diemer 2020-12-20 19:00:48 +01:00 committed by GitHub
commit 017cc4f9d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 139 additions and 36 deletions

21
.editorconfig Normal file
View file

@ -0,0 +1,21 @@
# see http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.py]
line_length = 119
[{Makefile,**.mk}]
indent_style = tab
insert_final_newline = false
[*.yml]
indent_style = tab
indent_size = 4

2
.gitignore vendored
View file

@ -1,6 +1,8 @@
.* .*
!.github !.github
!.editorconfig
!.gitignore !.gitignore
__pycache__ __pycache__
secret.txt secret.txt
/local_test/ /local_test/
/poetry.lock

37
Makefile Normal file
View file

@ -0,0 +1,37 @@
SHELL := /bin/bash
all: help
help:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9 -]+:.*?## / {printf "\033[36m%-22s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
check-poetry:
@if [[ "$(shell poetry --version 2>/dev/null)" == *"Poetry"* ]] ; \
then \
echo "Poetry found, ok." ; \
else \
echo 'Please install poetry first, with e.g.:' ; \
echo 'make install-poetry' ; \
exit 1 ; \
fi
install-poetry: ## install or update poetry
pip3 install -U poetry
install: check-poetry ## install PyInventory via poetry
sudo apt install python3-ldap libldap2-dev libsasl2-dev
poetry install
update: install-poetry ## update the sources and installation
poetry update
local-test: check-poetry ## Run local_test.py to run pyinventory_ynh locally
poetry run ./local_test.py
local-diff-settings: ## Run "manage.py diffsettings" with local test
poetry run python3 local_test/opt_yunohost/manage.py diffsettings
##############################################################################
.PHONY: help check-poetry install-poetry install update local-test

View file

@ -1,9 +1,9 @@
# PyInventory for YunoHost # PyInventory for YunoHost
[![Integration level](https://dash.yunohost.org/integration/pyinventory.svg)](https://dash.yunohost.org/appci/app/pyinventory) ![](https://ci-apps.yunohost.org/ci/badges/pyinventory.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/pyinventory.maintain.svg) [![Integration level](https://dash.yunohost.org/integration/pyinventory.svg)](https://dash.yunohost.org/appci/app/pyinventory) ![](https://ci-apps.yunohost.org/ci/badges/pyinventory.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/pyinventory.maintain.svg)
[![Install PyInventory with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=pyinventory) [![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. > *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.* If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
Pull requests welcome ;) Pull requests welcome ;)
@ -106,20 +106,18 @@ For quicker developing of PyInventory in the context of YunoHost app,
it's possible to run the Django developer server with the settings it's possible to run the Django developer server with the settings
and urls made for YunoHost installation. and urls made for YunoHost installation.
For this, just run `local_test.py` in a PyInventory virtualenv.
e.g.: e.g.:
```bash ```bash
~$ git clone https://github.com/jedie/PyInventory.git
~$ git clone https://github.com/YunoHost-Apps/pyinventory_ynh.git ~$ git clone https://github.com/YunoHost-Apps/pyinventory_ynh.git
~$ cd PyInventory/ ~$ cd pyinventory_ynh/
~/PyInventory$ make install ~/pyinventory_ynh$ make
~/PyInventory$ poetry shell install-poetry install or update poetry
(pyinventory-yd_5sxYx-py3.8) ~/PyInventory$ cd ../pyinventory_ynh/ install install PyInventory via poetry
(pyinventory-yd_5sxYx-py3.8) ~/pyinventory_ynh$ ./local_test.py update update the sources and installation
... local-test Run local_test.py to run pyinventory_ynh locally
Django version 2.2.17, using settings 'ynh_pyinventory_settings' ~/pyinventory_ynh$ make install-poetry
Starting development server at http://127.0.0.1:8000/ ~/pyinventory_ynh$ make install
~/pyinventory_ynh$ make local-test
``` ```
Notes: Notes:

View file

@ -145,6 +145,15 @@ else:
STATIC_ROOT = str(FINAL_WWW_PATH / 'static') STATIC_ROOT = str(FINAL_WWW_PATH / 'static')
MEDIA_ROOT = str(FINAL_WWW_PATH / 'media') MEDIA_ROOT = str(FINAL_WWW_PATH / 'media')
# _____________________________________________________________________________
# django-ckeditor
CKEDITOR_BASEPATH = STATIC_URL + 'ckeditor/ckeditor/'
# _____________________________________________________________________________
# Django-dbbackup
DBBACKUP_STORAGE_OPTIONS['location']=str(FINAL_HOME_PATH / 'backups')
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -184,6 +193,6 @@ LOGGING = {
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
try: try:
from .local_settings import * # noqa from local_settings import * # noqa
except ImportError: except ImportError:
pass pass

View file

@ -1,16 +1,25 @@
from django.conf import settings from django.conf import settings
from django.conf.urls import include from django.conf.urls import include, static
from django.contrib import admin
from django.urls import path from django.urls import path
from django.views.generic import RedirectView
# settings.PATH_URL is the $YNH_APP_ARG_PATH # settings.PATH_URL is the $YNH_APP_ARG_PATH
if settings.PATH_URL: if settings.PATH_URL:
# Prefix all urls with "PATH_URL":
urlpatterns = [ urlpatterns = [
# XXX: Hack - the MEDIA_URL contains the "PATH_URL" already: path(f'{settings.PATH_URL}/admin/', admin.site.urls),
path(settings.MEDIA_URL.lstrip('/'), include('django_tools.serve_media_app.urls')),
# Prefix all urls with "PATH_URL": path(f'{settings.PATH_URL}/', RedirectView.as_view(pattern_name='admin:index')),
path(f'{settings.PATH_URL}/', include('inventory_project.urls'))
path(f'{settings.PATH_URL}/ckeditor/', include('ckeditor_uploader.urls')),
# MEDIA_URL contains the "PATH_URL" already:
path(settings.MEDIA_URL.lstrip('/'), include('django_tools.serve_media_app.urls')),
] ]
if settings.SERVE_FILES:
urlpatterns += static.static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
else: else:
# Installed to domain root, without a path prefix? # Installed to domain root, without a path prefix
# Just use the default project urls.py
from inventory_project.urls import urlpatterns # noqa from inventory_project.urls import urlpatterns # noqa

View file

@ -130,6 +130,10 @@ def main():
# conf/ynh_urls.py -> local_test/ynh_urls.py # conf/ynh_urls.py -> local_test/ynh_urls.py
copy_patch(src_file=URLS_FILE, replaces=REPLACES) copy_patch(src_file=URLS_FILE, replaces=REPLACES)
with Path(FINAL_HOME_PATH / 'local_settings.py').open('w') as f:
f.write('# Only for local test run\n')
f.write('SERVE_FILES=True # used in src/inventory_project/urls.py\n')
# call "local_test/manage.py" via subprocess: # call "local_test/manage.py" via subprocess:
call_manage_py('check --deploy') call_manage_py('check --deploy')
call_manage_py('migrate --no-input') call_manage_py('migrate --no-input')

17
pyproject.toml Normal file
View file

@ -0,0 +1,17 @@
[tool.poetry]
name = "pyinventory_ynh"
version = "0.8.1~ynh7"
description = "Test pyinventory_ynh via local_test.py"
authors = ["JensDiemer <git@jensdiemer.de>"]
license = "GPL"
[tool.poetry.dependencies]
python = ">=3.7,<4.0.0"
pyinventory = "*"
django-auth-ldap = "*"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

View file

@ -24,10 +24,18 @@ new_path=$YNH_APP_NEW_PATH
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression --message="Loading installation settings..."
domain=$(ynh_app_setting_get --app="$app" --key=domain)
path_url=$(ynh_app_setting_get --app="$app" --key=path)
admin=$(ynh_app_setting_get --app="$app" --key=admin)
is_public=$(ynh_app_setting_get --app="$app" --key=is_public)
public_path=$(ynh_app_setting_get --app="$app" --key=public_path) 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)
is_public=$(ynh_app_setting_get --app="$app" --key=is_public) log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
port=$(ynh_app_setting_get --app="$app" --key=port) port=$(ynh_app_setting_get --app="$app" --key=port)
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
admin_mail=$(ynh_user_get_info "$admin" mail)
redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
@ -109,26 +117,24 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Modify PyInventory's config file..." ynh_script_progression --message="Modify PyInventory's config file..."
# save old settings file
settings="$final_path/ynh_pyinventory_settings.py" settings="$final_path/ynh_pyinventory_settings.py"
ynh_backup_if_checksum_is_different --file="$settings" ynh_backup_if_checksum_is_different --file="$settings"
# Change the path in the nginx config file cp "../conf/ynh_pyinventory_settings.py" "$settings"
if [ $change_path -eq 1 ]
then
ynh_replace_string --match_string="URL_PREFIX = \"${old_path%/}\"" --replace_string="URL_PREFIX = \"${new_path%/}\"" --target_file="$settings"
fi
# Change the domain for nginx ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$settings"
if [ $change_domain -eq 1 ] ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$settings"
then ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="$settings"
# replace SERVER_EMAIL ynh_replace_string --match_string="__ADMINMAIL__" --replace_string="$admin_mail" --target_file="$settings"
ynh_replace_string --match_string="noreply@$old_domain" --replace_string="noreply@$new_domain" --target_file="$settings" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$settings"
# replace SITE_DOMAIN ynh_replace_string --match_string="__FINAL_HOME_PATH__" --replace_string="$final_path" --target_file="$settings"
ynh_replace_string --match_string="SITE_DOMAIN = \"$old_domain\"" --replace_string="SITE_DOMAIN = \"$new_domain\"" --target_file="$settings" ynh_replace_string --match_string="__FINAL_WWW_PATH__" --replace_string="$public_path" --target_file="$settings"
# replace ALLOWED_HOSTS ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$settings"
ynh_replace_string --match_string="ALLOWED_HOSTS = \[\"$old_domain\"\]" --replace_string="ALLOWED_HOSTS = \[\"$new_domain\"\]" --target_file="$settings" ynh_replace_string --match_string="__LOG_FILE__" --replace_string="$log_file" --target_file="$settings"
fi ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$settings"
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$settings" ynh_store_file_checksum --file="$settings"
#================================================= #=================================================