From 15a0a3a184d1a49abb56f7caeb1b4d0b66768ebd Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 15 Sep 2018 02:12:16 +0200 Subject: [PATCH 01/59] setup.py optimization and debian packaging --- .gitlab-ci.yml | 67 ++++++++++++++++--- matemat/__init__.py | 2 +- matemat/__main__.py | 15 +++-- package/debian/matemat/DEBIAN/changelog | 5 ++ package/debian/matemat/DEBIAN/compat | 1 + package/debian/matemat/DEBIAN/control | 11 +++ package/debian/matemat/DEBIAN/copyright | 16 +++++ package/debian/matemat/DEBIAN/matemat.links | 1 + package/debian/matemat/DEBIAN/postinst | 22 ++++++ package/debian/matemat/DEBIAN/rules | 3 + .../usr/lib/systemd/system/matemat.service | 10 +++ Dockerfile => package/docker/Dockerfile | 4 +- requirements.txt | 4 +- setup.py | 32 +++++++-- 14 files changed, 167 insertions(+), 26 deletions(-) create mode 100644 package/debian/matemat/DEBIAN/changelog create mode 100644 package/debian/matemat/DEBIAN/compat create mode 100644 package/debian/matemat/DEBIAN/control create mode 100644 package/debian/matemat/DEBIAN/copyright create mode 100644 package/debian/matemat/DEBIAN/matemat.links create mode 100755 package/debian/matemat/DEBIAN/postinst create mode 100755 package/debian/matemat/DEBIAN/rules create mode 100644 package/debian/matemat/usr/lib/systemd/system/matemat.service rename Dockerfile => package/docker/Dockerfile (84%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6e1f340..9dc1e6e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,31 +6,80 @@ stages: - build - staging + + +before_script: +- export MATEMAT_VERSION=$(python -c 'from matemat import __version__; print(__version__)') + + + test: stage: test script: - - pip3 install -r requirements.txt - - sudo -u matemat python3 -m coverage run --rcfile=setup.cfg -m unittest discover matemat - - sudo -u matemat python3 -m coverage combine - - sudo -u matemat python3 -m coverage report --rcfile=setup.cfg + - pip3 install -u . + - sudo -u matemat python3.7 -m coverage run --rcfile=setup.cfg -m unittest discover matemat + - sudo -u matemat python3.7 -m coverage combine + - sudo -u matemat python3.7 -m coverage report --rcfile=setup.cfg codestyle: stage: test script: - - pip3 install -r requirements.txt + - pip3 install -u . - sudo -u matemat pycodestyle matemat -build: + + +build_docker: stage: build script: - - docker build -t "registry.gitlab.com/s3lph/matemat:$(git rev-parse HEAD)" . - - docker tag "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/matemat:latest-$([[ $CI_COMMIT_REF_NAME == "master" ]] && echo stable || echo staging)" + - docker build -t "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" package/docker + - docker tag "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_REF_NAME" - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN registry.gitlab.com - docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" - - docker push registry.gitlab.com/s3lph/matemat:latest-$([[ $CI_COMMIT_REF_NAME == "master" ]] && echo stable || echo staging) + - docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_REF_NAME" only: - staging - master + - tags + +build_wheel: + stage: build + script: + - python3.7 setup.py egg_info --tag-build "+$CI_COMMIT_SHA" --tag-date bdist_wheel + - python3.7 setup.py egg_info --tag-build "+$CI_COMMIT_REF_NAME" --tag-date bdist_wheel + artifacts: + paths: + - "dist/*.whl" + only: + - staging + - master + - tags + +# This is only useful once Debian either defaults python3 to 3.7 or provides python3.7- packages +# for the needed dependencies... But it SHOULD work... +#build_deb: +# stage: build +# script: +# - cp -r static/ package/debian/matemat/usr/lib/matemat/static/ +# - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ +# - python3.7 setup.py egg_info -d -b +master install --root=package/debian/matemat/ --prefix=/usr --optimize=1 +# - export PYTHON_BIN=$(which python3) +# - cd package/debian +# - mv matemat/usr/lib/python3.7/{site,dist}-packages +# - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat +# - rm -r matemat/usr/bin +# - find . -type f -exec sed -re "s#${PYTHON_BIN}#/usr/bin/python3.7#g" -i {} \; +# - dpkg-deb --build matemat +# - mv matemat.deb "matemat_${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1_all.deb" +# artifacts: +# paths: +# - "package/debian/*.deb" +# only: +# - staging +# - master +# - tags + + staging: stage: staging diff --git a/matemat/__init__.py b/matemat/__init__.py index a3332a5..373d726 100644 --- a/matemat/__init__.py +++ b/matemat/__init__.py @@ -1,2 +1,2 @@ -__version__ = '2.0' +__version__ = '0.1' diff --git a/matemat/__main__.py b/matemat/__main__.py index 8876386..b10f837 100644 --- a/matemat/__main__.py +++ b/matemat/__main__.py @@ -3,14 +3,15 @@ from typing import Any, Dict, Iterable, Union import sys +from matemat.webserver import MatematWebserver from matemat.webserver import parse_config_file -if __name__ == '__main__': - # Those imports are actually needed, as they implicitly register pagelets. - # noinspection PyUnresolvedReferences - from matemat.webserver.pagelets import * - from matemat.webserver import MatematWebserver +# Those imports are actually needed, as they implicitly register pagelets. +# noinspection PyUnresolvedReferences +from matemat.webserver.pagelets import * + +def main(): # Use config file name from command line, if present configfile: Union[str, Iterable[str]] = '/etc/matemat.conf' if len(sys.argv) > 1: @@ -21,3 +22,7 @@ if __name__ == '__main__': # Start the web server MatematWebserver(**config).start() + + +if __name__ == '__main__': + main() diff --git a/package/debian/matemat/DEBIAN/changelog b/package/debian/matemat/DEBIAN/changelog new file mode 100644 index 0000000..8b78df4 --- /dev/null +++ b/package/debian/matemat/DEBIAN/changelog @@ -0,0 +1,5 @@ +matemat (0.1-1) UNRELEASED; urgency=medium + + * Initial release. + + -- s3lph Wed, 12 Sep 2018 02:04:12 +0000 diff --git a/package/debian/matemat/DEBIAN/compat b/package/debian/matemat/DEBIAN/compat new file mode 100644 index 0000000..9a03714 --- /dev/null +++ b/package/debian/matemat/DEBIAN/compat @@ -0,0 +1 @@ +10 \ No newline at end of file diff --git a/package/debian/matemat/DEBIAN/control b/package/debian/matemat/DEBIAN/control new file mode 100644 index 0000000..08cbd9b --- /dev/null +++ b/package/debian/matemat/DEBIAN/control @@ -0,0 +1,11 @@ +Package: matemat +Version: 0.1 +Maintainer: s3lph +Section: web +Priority: extra +Architecture: all +Depends: python3 >= 3.7, python3-jinja2, python3-magic, python3-pil +Description: A soda machine stock-keeping webservice + A web service for automated stock-keeping of a soda machine written in Python. + It provides a touch-input-friendly user interface (as most input happens through the + soda machine's touch screen). diff --git a/package/debian/matemat/DEBIAN/copyright b/package/debian/matemat/DEBIAN/copyright new file mode 100644 index 0000000..a38a9a5 --- /dev/null +++ b/package/debian/matemat/DEBIAN/copyright @@ -0,0 +1,16 @@ +Copyright 2018 s3lph + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package/debian/matemat/DEBIAN/matemat.links b/package/debian/matemat/DEBIAN/matemat.links new file mode 100644 index 0000000..e789bc0 --- /dev/null +++ b/package/debian/matemat/DEBIAN/matemat.links @@ -0,0 +1 @@ +/usr/lib/matemat/static/upload /var/lib/matemat/upload \ No newline at end of file diff --git a/package/debian/matemat/DEBIAN/postinst b/package/debian/matemat/DEBIAN/postinst new file mode 100755 index 0000000..dcf706d --- /dev/null +++ b/package/debian/matemat/DEBIAN/postinst @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +if [[ "$1" == "configure" ]]; then + + if ! getent group matemat >/dev/null; then + addgroup --quiet --system matemat + fi + + if ! getent passwd matemat >/dev/null; then + adduser --quiet --system --create-home --ingroup matemat --home /var/lib/matemat --shell /usr/sbin/nologin \ + matemat + fi + + chown matemat:matemat -R /var/lib/matemat + find /var/lib/matemat -type d -exec chmod 0750 {} + find /var/lib/matemat -type f -exec chmod 0640 {} + + setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/matemat + +fi diff --git a/package/debian/matemat/DEBIAN/rules b/package/debian/matemat/DEBIAN/rules new file mode 100755 index 0000000..cbe925d --- /dev/null +++ b/package/debian/matemat/DEBIAN/rules @@ -0,0 +1,3 @@ +#!/usr/bin/make -f +%: + dh $@ diff --git a/package/debian/matemat/usr/lib/systemd/system/matemat.service b/package/debian/matemat/usr/lib/systemd/system/matemat.service new file mode 100644 index 0000000..ae2283f --- /dev/null +++ b/package/debian/matemat/usr/lib/systemd/system/matemat.service @@ -0,0 +1,10 @@ +[Unit] +Description=matemat +After=networking.target + +[Service] +Exec=/usr/lib/matemat/matemat /etc/matemat.conf /usr/lib/matemat/matemat.conf +User=matemat + +[Install] +WantedBy=multi-user.target diff --git a/Dockerfile b/package/docker/Dockerfile similarity index 84% rename from Dockerfile rename to package/docker/Dockerfile index 7338327..fae8463 100644 --- a/Dockerfile +++ b/package/docker/Dockerfile @@ -1,10 +1,10 @@ FROM python:3.7-alpine -ADD . / +ADD ../.. / RUN mkdir -p /var/matemat/db /var/matemat/upload \ && apk --update add libmagic zlib jpeg zlib-dev jpeg-dev build-base \ - && pip3 install -r /requirements.txt \ + && pip3 install -u . \ && apk del zlib-dev jpeg-dev build-base \ && rm -rf /var/cache/apk /root/.cache/pip diff --git a/requirements.txt b/requirements.txt index 0da0f5a..9c558e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1 @@ -file-magic -jinja2 -Pillow +. diff --git a/setup.py b/setup.py index 0fc605f..265db5c 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,32 @@ -from setuptools import setup +from setuptools import setup, find_packages + +from matemat import __version__ setup( name='matemat', - version='2.0', - packages=['matemat'], - url='', - license='', + version=__version__, + url='https://gitlab.com/s3lph/matemat', + license='MIT', author='s3lph', author_email='', - description='Replacement for the original Ruby matemat software.' + description='Soda machine stock-keeping webservice', + long_description=''' +A web service for automated stock-keeping of a soda machine written in Python. +It provides a touch-input-friendly user interface (as most input happens through the +soda machine's touch screen). +''', + + packages=find_packages(exclude=['*.test']), + python_requires='>=3.7', + install_requires=[ + 'file-magic', + 'jinja2', + 'Pillow' + ], + test_loader='unittest:TestLoader', + entry_points={ + 'console_scripts': [ + 'matemat = matemat.__main__:main' + ] + } ) From f79112f84fe04daf746c07c7df076f7c18e677d5 Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 21:31:11 +0200 Subject: [PATCH 02/59] Added build setup for archlinux. Let's test! --- .gitlab-ci.yml | 26 ++++++++++++++++++- package/archlinux/PKGBUILD | 23 ++++++++++++++++ package/archlinux/matemat.install | 24 +++++++++++++++++ .../usr/lib/systemd/system/matemat.service | 10 +++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 package/archlinux/PKGBUILD create mode 100755 package/archlinux/matemat.install create mode 100644 package/archlinux/matemat/usr/lib/systemd/system/matemat.service diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9dc1e6e..2f90422 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,6 +51,7 @@ build_wheel: paths: - "dist/*.whl" only: + - deployment - staging - master - tags @@ -67,7 +68,7 @@ build_wheel: # - cd package/debian # - mv matemat/usr/lib/python3.7/{site,dist}-packages # - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat -# - rm -r matemat/usr/bin +# - rm -rf matemat/usr/bin # - find . -type f -exec sed -re "s#${PYTHON_BIN}#/usr/bin/python3.7#g" -i {} \; # - dpkg-deb --build matemat # - mv matemat.deb "matemat_${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1_all.deb" @@ -79,6 +80,29 @@ build_wheel: # - master # - tags +build_archlinux: + stage: build + image: base/devel:latest # Use an archlinux image instead of the customized debian image. + script: + - cp -r static/ package/archlinux/matemat/usr/lib/matemat/static/ + - cp -r templates/ package/archlinux/matemat/usr/lib/matemat/templates/ + - python3.7 setup.py egg_info -d -b +master install --root=package/archlinux/matemat/ --prefix=/usr --optimize=1 + - export PYTHON_BIN=$(which python3) + - cd package/archlinux + - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat + - rm -rf matemat/usr/bin + - find . -type f -exec sed -re "s#${PYTHON_BIN}#/usr/bin/python3.7#g" -i {} \; + - makepkg -s MATEMAT_VERSION=${MATEMAT_VERSION} + - mv matemat-${MATEMAT_VERSION}-1-any.pkg.tar.xz "matemat-${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1-any.pkg.tar.xz" + artifacts: + paths: + - "package/archlinux/*.pkg.tar.xz" + only: + - deployment + - staging + - master + - tags + staging: diff --git a/package/archlinux/PKGBUILD b/package/archlinux/PKGBUILD new file mode 100644 index 0000000..9fd4bf7 --- /dev/null +++ b/package/archlinux/PKGBUILD @@ -0,0 +1,23 @@ + +# Maintainer: s3lph + +pkgname=matemat +pkgver=${MATEMAT_VERSION} +pkgrel=1 +arch=('any') + +pkgdesc='A soda machine stock-keeping webservice' +url='https://gitlab.com/s3lph/matemat' +licence=('MIT') + +depends=( + 'python3>=3.7' + 'python-jinja' + 'python-pillow' + 'python-magic' + 'file' +) + +install=$pkgname.install + +pkgdir=matemat/ diff --git a/package/archlinux/matemat.install b/package/archlinux/matemat.install new file mode 100755 index 0000000..7595190 --- /dev/null +++ b/package/archlinux/matemat.install @@ -0,0 +1,24 @@ + +post_install() { + + set -e + + if [[ "$1" == "configure" ]]; then + + if ! getent group matemat >/dev/null; then + groupadd --system matemat + fi + + if ! getent passwd matemat >/dev/null; then + useradd --system --create-home --gid matemat --home-dir /var/lib/matemat --shell /usr/bin/nologin matemat + fi + + chown matemat:matemat -R /var/lib/matemat + find /var/lib/matemat -type d -exec chmod 0750 {} + find /var/lib/matemat -type f -exec chmod 0640 {} + + setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/matemat + + fi + +} diff --git a/package/archlinux/matemat/usr/lib/systemd/system/matemat.service b/package/archlinux/matemat/usr/lib/systemd/system/matemat.service new file mode 100644 index 0000000..ae2283f --- /dev/null +++ b/package/archlinux/matemat/usr/lib/systemd/system/matemat.service @@ -0,0 +1,10 @@ +[Unit] +Description=matemat +After=networking.target + +[Service] +Exec=/usr/lib/matemat/matemat /etc/matemat.conf /usr/lib/matemat/matemat.conf +User=matemat + +[Install] +WantedBy=multi-user.target From b59b5a3dbad1e88dc9148a4b5625e2ad1627a9c1 Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 21:35:35 +0200 Subject: [PATCH 03/59] Fixed a wrong pip flag. --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2f90422..0fd1fa7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ before_script: test: stage: test script: - - pip3 install -u . + - pip3 install -e . - sudo -u matemat python3.7 -m coverage run --rcfile=setup.cfg -m unittest discover matemat - sudo -u matemat python3.7 -m coverage combine - sudo -u matemat python3.7 -m coverage report --rcfile=setup.cfg @@ -24,7 +24,7 @@ test: codestyle: stage: test script: - - pip3 install -u . + - pip3 install -e . - sudo -u matemat pycodestyle matemat From c607b26c0a110507f0d2fd8000c8c91f4340b7be Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 21:46:41 +0200 Subject: [PATCH 04/59] Fixed gitignore and added missing files --- .gitignore | 2 +- .gitlab-ci.yml | 5 ++- package/archlinux/matemat/etc/matemat.conf | 32 +++++++++++++++++++ .../matemat/usr/lib/matemat/matemat.conf | 11 +++++++ package/debian/matemat/etc/matemat.conf | 32 +++++++++++++++++++ .../matemat/usr/lib/matemat/matemat.conf | 11 +++++++ 6 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 package/archlinux/matemat/etc/matemat.conf create mode 100644 package/archlinux/matemat/usr/lib/matemat/matemat.conf create mode 100644 package/debian/matemat/etc/matemat.conf create mode 100644 package/debian/matemat/usr/lib/matemat/matemat.conf diff --git a/.gitignore b/.gitignore index ea15acd..5bda33f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ *.sqlite3 *.db static/upload/ -**/matemat.conf +./matemat.conf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0fd1fa7..417ff54 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -84,14 +84,13 @@ build_archlinux: stage: build image: base/devel:latest # Use an archlinux image instead of the customized debian image. script: + - pacman -Sy python - cp -r static/ package/archlinux/matemat/usr/lib/matemat/static/ - cp -r templates/ package/archlinux/matemat/usr/lib/matemat/templates/ - - python3.7 setup.py egg_info -d -b +master install --root=package/archlinux/matemat/ --prefix=/usr --optimize=1 - - export PYTHON_BIN=$(which python3) + - python3 setup.py egg_info -d -b +master install --root=package/archlinux/matemat/ --prefix=/usr --optimize=1 - cd package/archlinux - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin - - find . -type f -exec sed -re "s#${PYTHON_BIN}#/usr/bin/python3.7#g" -i {} \; - makepkg -s MATEMAT_VERSION=${MATEMAT_VERSION} - mv matemat-${MATEMAT_VERSION}-1-any.pkg.tar.xz "matemat-${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1-any.pkg.tar.xz" artifacts: diff --git a/package/archlinux/matemat/etc/matemat.conf b/package/archlinux/matemat/etc/matemat.conf new file mode 100644 index 0000000..1339a49 --- /dev/null +++ b/package/archlinux/matemat/etc/matemat.conf @@ -0,0 +1,32 @@ +[Matemat] + +# The IP address to listen on +Address=:: +# The TCP port to listen on +Port=80 + +# The log level, one of NONE, DEBUG, INFO, WARNING, ERROR, CRITICAL +LogLevel=DEBUG + +[Pagelets] + +# Name of the Matemat instance, shown in the web app +InstanceName=Matemat + +# +# Configure SMTP credentials +# +# SmtpFrom=matemat@example.com +# SmtpSubj=Matemat Receipt +# SmtpHost=exmaple.com +# SmtpPort=587 +# SmtpUser=matemat@example.com +# SmtpPass=supersecurepassword + +# +# Enable to allow users to receive receipts via email +# +# SmtpSendReceipts=1 + +# Add static HTTP headers in this section +# [HttpHeaders] diff --git a/package/archlinux/matemat/usr/lib/matemat/matemat.conf b/package/archlinux/matemat/usr/lib/matemat/matemat.conf new file mode 100644 index 0000000..5c34f56 --- /dev/null +++ b/package/archlinux/matemat/usr/lib/matemat/matemat.conf @@ -0,0 +1,11 @@ +[Matemat] + +StaticPath=/usr/lib/matemat/static +TemplatePath=/usr/lib/matemat/templates + +LogTarget=stdout + +[Pagelets] + +UploadDir=/var/lib/matemat/upload +DatabaseFile=/var/lib/matemat/matemat.db diff --git a/package/debian/matemat/etc/matemat.conf b/package/debian/matemat/etc/matemat.conf new file mode 100644 index 0000000..1339a49 --- /dev/null +++ b/package/debian/matemat/etc/matemat.conf @@ -0,0 +1,32 @@ +[Matemat] + +# The IP address to listen on +Address=:: +# The TCP port to listen on +Port=80 + +# The log level, one of NONE, DEBUG, INFO, WARNING, ERROR, CRITICAL +LogLevel=DEBUG + +[Pagelets] + +# Name of the Matemat instance, shown in the web app +InstanceName=Matemat + +# +# Configure SMTP credentials +# +# SmtpFrom=matemat@example.com +# SmtpSubj=Matemat Receipt +# SmtpHost=exmaple.com +# SmtpPort=587 +# SmtpUser=matemat@example.com +# SmtpPass=supersecurepassword + +# +# Enable to allow users to receive receipts via email +# +# SmtpSendReceipts=1 + +# Add static HTTP headers in this section +# [HttpHeaders] diff --git a/package/debian/matemat/usr/lib/matemat/matemat.conf b/package/debian/matemat/usr/lib/matemat/matemat.conf new file mode 100644 index 0000000..5c34f56 --- /dev/null +++ b/package/debian/matemat/usr/lib/matemat/matemat.conf @@ -0,0 +1,11 @@ +[Matemat] + +StaticPath=/usr/lib/matemat/static +TemplatePath=/usr/lib/matemat/templates + +LogTarget=stdout + +[Pagelets] + +UploadDir=/var/lib/matemat/upload +DatabaseFile=/var/lib/matemat/matemat.db From 586842358299c582fcdbed1873c34355a7f6c1bc Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 21:50:37 +0200 Subject: [PATCH 05/59] Added pacman --noconfirm. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 417ff54..51a1884 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -84,7 +84,7 @@ build_archlinux: stage: build image: base/devel:latest # Use an archlinux image instead of the customized debian image. script: - - pacman -Sy python + - pacman -Sy --noconfirm python - cp -r static/ package/archlinux/matemat/usr/lib/matemat/static/ - cp -r templates/ package/archlinux/matemat/usr/lib/matemat/templates/ - python3 setup.py egg_info -d -b +master install --root=package/archlinux/matemat/ --prefix=/usr --optimize=1 From bffd31fe81056a75d47919b0539c39b3ad6eb0da Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 21:54:15 +0200 Subject: [PATCH 06/59] Added some missing archlinux dependencies --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 51a1884..f0798e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -84,7 +84,7 @@ build_archlinux: stage: build image: base/devel:latest # Use an archlinux image instead of the customized debian image. script: - - pacman -Sy --noconfirm python + - pacman -Sy --noconfirm python python-setuptools python-pip python-wheel - cp -r static/ package/archlinux/matemat/usr/lib/matemat/static/ - cp -r templates/ package/archlinux/matemat/usr/lib/matemat/templates/ - python3 setup.py egg_info -d -b +master install --root=package/archlinux/matemat/ --prefix=/usr --optimize=1 From 9439c76f308c730e36f793feee61f98341881a50 Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 21:57:41 +0200 Subject: [PATCH 07/59] Drop privileges for makepkg. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f0798e7..dc0964a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -91,7 +91,7 @@ build_archlinux: - cd package/archlinux - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin - - makepkg -s MATEMAT_VERSION=${MATEMAT_VERSION} + - sudo -u nobody makepkg --syncdeps MATEMAT_VERSION=${MATEMAT_VERSION} - mv matemat-${MATEMAT_VERSION}-1-any.pkg.tar.xz "matemat-${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1-any.pkg.tar.xz" artifacts: paths: From d3ee2b95a72294eb3ddbeccc1418050e3025f6e1 Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 22:10:01 +0200 Subject: [PATCH 08/59] Hopefully fixed PKGBUILD. --- .gitlab-ci.yml | 3 ++- package/archlinux/PKGBUILD | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dc0964a..6391f3b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -91,7 +91,8 @@ build_archlinux: - cd package/archlinux - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin - - sudo -u nobody makepkg --syncdeps MATEMAT_VERSION=${MATEMAT_VERSION} + - sed -re "s/__VERSION__/${MATEMAT_VERSION}/g" -i PKGBUILD + - sudo -u nobody makepkg --syncdeps - mv matemat-${MATEMAT_VERSION}-1-any.pkg.tar.xz "matemat-${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1-any.pkg.tar.xz" artifacts: paths: diff --git a/package/archlinux/PKGBUILD b/package/archlinux/PKGBUILD index 9fd4bf7..adac785 100644 --- a/package/archlinux/PKGBUILD +++ b/package/archlinux/PKGBUILD @@ -2,7 +2,7 @@ # Maintainer: s3lph pkgname=matemat -pkgver=${MATEMAT_VERSION} +pkgver=__VERSION__ pkgrel=1 arch=('any') From beef77f3688f1e85e7e0a494618e0f0f2f43584c Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 22:15:05 +0200 Subject: [PATCH 09/59] Fixed matemat version fetch. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6391f3b..973f99c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ stages: before_script: -- export MATEMAT_VERSION=$(python -c 'from matemat import __version__; print(__version__)') +- export MATEMAT_VERSION=$(python -c 'import matemat; print(matemat.__version__)') From f3c8e140adde15c5f648165e3d6d5621b889a875 Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 22:18:30 +0200 Subject: [PATCH 10/59] Added debug output to build jobs --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 973f99c..0ffb4d8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,6 +10,7 @@ stages: before_script: - export MATEMAT_VERSION=$(python -c 'import matemat; print(matemat.__version__)') +- echo ${MATEMAT_VERSION} @@ -91,6 +92,8 @@ build_archlinux: - cd package/archlinux - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin + - echo ${MATEMAT_VERSION} + - ls - sed -re "s/__VERSION__/${MATEMAT_VERSION}/g" -i PKGBUILD - sudo -u nobody makepkg --syncdeps - mv matemat-${MATEMAT_VERSION}-1-any.pkg.tar.xz "matemat-${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1-any.pkg.tar.xz" From e5e51acfb4da9765602fc951f2d780895d5ec897 Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 22:21:44 +0200 Subject: [PATCH 11/59] Fixed missing MATEMAT_VERSION env var. --- .gitlab-ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0ffb4d8..da43306 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,6 @@ stages: before_script: - export MATEMAT_VERSION=$(python -c 'import matemat; print(matemat.__version__)') -- echo ${MATEMAT_VERSION} @@ -86,14 +85,13 @@ build_archlinux: image: base/devel:latest # Use an archlinux image instead of the customized debian image. script: - pacman -Sy --noconfirm python python-setuptools python-pip python-wheel + - export MATEMAT_VERSION=$(python -c 'import matemat; print(matemat.__version__)') - cp -r static/ package/archlinux/matemat/usr/lib/matemat/static/ - cp -r templates/ package/archlinux/matemat/usr/lib/matemat/templates/ - python3 setup.py egg_info -d -b +master install --root=package/archlinux/matemat/ --prefix=/usr --optimize=1 - cd package/archlinux - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin - - echo ${MATEMAT_VERSION} - - ls - sed -re "s/__VERSION__/${MATEMAT_VERSION}/g" -i PKGBUILD - sudo -u nobody makepkg --syncdeps - mv matemat-${MATEMAT_VERSION}-1-any.pkg.tar.xz "matemat-${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1-any.pkg.tar.xz" From 974d8fc9f1bc1a8942d3b434c4f0e3b1bbb48859 Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 22:25:47 +0200 Subject: [PATCH 12/59] Fixed: Makepkg can't install dependencies as nobody. --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index da43306..211851a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -84,7 +84,7 @@ build_archlinux: stage: build image: base/devel:latest # Use an archlinux image instead of the customized debian image. script: - - pacman -Sy --noconfirm python python-setuptools python-pip python-wheel + - pacman -Sy --noconfirm python python-setuptools python-pip python-wheel python-jinja python-pillow python-magic file - export MATEMAT_VERSION=$(python -c 'import matemat; print(matemat.__version__)') - cp -r static/ package/archlinux/matemat/usr/lib/matemat/static/ - cp -r templates/ package/archlinux/matemat/usr/lib/matemat/templates/ @@ -93,7 +93,7 @@ build_archlinux: - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin - sed -re "s/__VERSION__/${MATEMAT_VERSION}/g" -i PKGBUILD - - sudo -u nobody makepkg --syncdeps + - sudo -u nobody makepkg - mv matemat-${MATEMAT_VERSION}-1-any.pkg.tar.xz "matemat-${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1-any.pkg.tar.xz" artifacts: paths: From 94841da8758976b57fc813685b342b38dd213f1d Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 22:28:41 +0200 Subject: [PATCH 13/59] Fixed: Python package name. --- package/archlinux/PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/archlinux/PKGBUILD b/package/archlinux/PKGBUILD index adac785..4815d86 100644 --- a/package/archlinux/PKGBUILD +++ b/package/archlinux/PKGBUILD @@ -11,7 +11,7 @@ url='https://gitlab.com/s3lph/matemat' licence=('MIT') depends=( - 'python3>=3.7' + 'python' 'python-jinja' 'python-pillow' 'python-magic' From eb6c2b3f6538eec7b7a319b7c859dbb57ce9af6e Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 19 Oct 2018 23:48:36 +0200 Subject: [PATCH 14/59] Fixed system integration (especially systemd + capabilities. --- .gitlab-ci.yml | 2 +- package/archlinux/PKGBUILD | 10 ++++-- package/archlinux/matemat.install | 35 +++++++++---------- .../usr/lib/systemd/system/matemat.service | 4 ++- .../usr/lib/systemd/system/matemat.service | 4 ++- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 211851a..27071e2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -93,7 +93,7 @@ build_archlinux: - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin - sed -re "s/__VERSION__/${MATEMAT_VERSION}/g" -i PKGBUILD - - sudo -u nobody makepkg + - sudo -u nobody makepkg -c - mv matemat-${MATEMAT_VERSION}-1-any.pkg.tar.xz "matemat-${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1-any.pkg.tar.xz" artifacts: paths: diff --git a/package/archlinux/PKGBUILD b/package/archlinux/PKGBUILD index 4815d86..d062d49 100644 --- a/package/archlinux/PKGBUILD +++ b/package/archlinux/PKGBUILD @@ -2,7 +2,7 @@ # Maintainer: s3lph pkgname=matemat -pkgver=__VERSION__ +pkgver=0.1 pkgrel=1 arch=('any') @@ -18,6 +18,12 @@ depends=( 'file' ) +backup=( + 'etc/matemat.conf' +) + install=$pkgname.install -pkgdir=matemat/ +package() { + cp -r ../matemat/* ../pkg/matemat/ +} diff --git a/package/archlinux/matemat.install b/package/archlinux/matemat.install index 7595190..8a33b84 100755 --- a/package/archlinux/matemat.install +++ b/package/archlinux/matemat.install @@ -1,24 +1,23 @@ post_install() { - set -e - - if [[ "$1" == "configure" ]]; then - - if ! getent group matemat >/dev/null; then - groupadd --system matemat - fi - - if ! getent passwd matemat >/dev/null; then - useradd --system --create-home --gid matemat --home-dir /var/lib/matemat --shell /usr/bin/nologin matemat - fi - - chown matemat:matemat -R /var/lib/matemat - find /var/lib/matemat -type d -exec chmod 0750 {} - find /var/lib/matemat -type f -exec chmod 0640 {} - - setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/matemat - + if ! getent group matemat >/dev/null; then + groupadd --system matemat fi + if ! getent passwd matemat >/dev/null; then + useradd --system --create-home --gid matemat --home-dir /var/lib/matemat --shell /usr/bin/nologin matemat + fi + + chown matemat:matemat -R /var/lib/matemat + find /var/lib/matemat -type d -exec chmod 0750 {} \; + find /var/lib/matemat -type f -exec chmod 0640 {} \; + +} + +pre_remove() { + + systemctl stop matemat.service + userdel matemat + } diff --git a/package/archlinux/matemat/usr/lib/systemd/system/matemat.service b/package/archlinux/matemat/usr/lib/systemd/system/matemat.service index ae2283f..6656268 100644 --- a/package/archlinux/matemat/usr/lib/systemd/system/matemat.service +++ b/package/archlinux/matemat/usr/lib/systemd/system/matemat.service @@ -3,8 +3,10 @@ Description=matemat After=networking.target [Service] -Exec=/usr/lib/matemat/matemat /etc/matemat.conf /usr/lib/matemat/matemat.conf +ExecStart=/usr/bin/python -m matemat /etc/matemat.conf /usr/lib/matemat/matemat.conf User=matemat +AmbientCapabilities=CAP_NET_BIND_SERVICE +NoNewPrivileges=true [Install] WantedBy=multi-user.target diff --git a/package/debian/matemat/usr/lib/systemd/system/matemat.service b/package/debian/matemat/usr/lib/systemd/system/matemat.service index ae2283f..3dba957 100644 --- a/package/debian/matemat/usr/lib/systemd/system/matemat.service +++ b/package/debian/matemat/usr/lib/systemd/system/matemat.service @@ -3,8 +3,10 @@ Description=matemat After=networking.target [Service] -Exec=/usr/lib/matemat/matemat /etc/matemat.conf /usr/lib/matemat/matemat.conf +ExecStart=/usr/bin/python3 -m matemat /etc/matemat.conf /usr/lib/matemat/matemat.conf User=matemat +AmbientCapabilities=CAP_NET_BIND_SERVICE +NoNewPrivileges=true [Install] WantedBy=multi-user.target From 960a1c85177b957f4cd316a1e4f37609401b6718 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 15:59:53 +0100 Subject: [PATCH 15/59] Removed setcap from debian postinst script --- package/debian/matemat/DEBIAN/postinst | 2 -- 1 file changed, 2 deletions(-) diff --git a/package/debian/matemat/DEBIAN/postinst b/package/debian/matemat/DEBIAN/postinst index dcf706d..ceeed0c 100755 --- a/package/debian/matemat/DEBIAN/postinst +++ b/package/debian/matemat/DEBIAN/postinst @@ -17,6 +17,4 @@ if [[ "$1" == "configure" ]]; then find /var/lib/matemat -type d -exec chmod 0750 {} find /var/lib/matemat -type f -exec chmod 0640 {} - setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/matemat - fi From ea57485cfb6cd2292b45fd8bcd0880ecc71c3300 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 18:28:28 +0100 Subject: [PATCH 16/59] Back to Python 3.6 for the sake of Debian packaging (initial test!) --- .gitlab-ci.yml | 59 +++++++++-------- README.md | 2 +- matemat/db/facade.py | 3 +- matemat/db/primitives/Product.py | 17 ++--- matemat/db/primitives/Receipt.py | 27 ++++++-- matemat/db/primitives/ReceiptPreference.py | 2 +- matemat/db/primitives/Transaction.py | 76 ++++++++++++++++++---- matemat/db/primitives/User.py | 32 +++++---- matemat/db/wrapper.py | 3 +- matemat/webserver/requestargs.py | 7 +- setup.py | 2 +- testing/Dockerfile | 4 +- 12 files changed, 148 insertions(+), 86 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 27071e2..ab5e86d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ --- -image: s3lph/matemat-ci:20180802-02 +image: s3lph/matemat-ci:20181103-01 stages: - test @@ -17,9 +17,9 @@ test: stage: test script: - pip3 install -e . - - sudo -u matemat python3.7 -m coverage run --rcfile=setup.cfg -m unittest discover matemat - - sudo -u matemat python3.7 -m coverage combine - - sudo -u matemat python3.7 -m coverage report --rcfile=setup.cfg + - sudo -u matemat python3.6 -m coverage run --rcfile=setup.cfg -m unittest discover matemat + - sudo -u matemat python3.6 -m coverage combine + - sudo -u matemat python3.6 -m coverage report --rcfile=setup.cfg codestyle: stage: test @@ -45,8 +45,8 @@ build_docker: build_wheel: stage: build script: - - python3.7 setup.py egg_info --tag-build "+$CI_COMMIT_SHA" --tag-date bdist_wheel - - python3.7 setup.py egg_info --tag-build "+$CI_COMMIT_REF_NAME" --tag-date bdist_wheel + - python3.6 setup.py egg_info --tag-build "+$CI_COMMIT_SHA" --tag-date bdist_wheel + - python3.6 setup.py egg_info --tag-build "+$CI_COMMIT_REF_NAME" --tag-date bdist_wheel artifacts: paths: - "dist/*.whl" @@ -56,29 +56,28 @@ build_wheel: - master - tags -# This is only useful once Debian either defaults python3 to 3.7 or provides python3.7- packages -# for the needed dependencies... But it SHOULD work... -#build_deb: -# stage: build -# script: -# - cp -r static/ package/debian/matemat/usr/lib/matemat/static/ -# - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ -# - python3.7 setup.py egg_info -d -b +master install --root=package/debian/matemat/ --prefix=/usr --optimize=1 -# - export PYTHON_BIN=$(which python3) -# - cd package/debian -# - mv matemat/usr/lib/python3.7/{site,dist}-packages -# - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat -# - rm -rf matemat/usr/bin -# - find . -type f -exec sed -re "s#${PYTHON_BIN}#/usr/bin/python3.7#g" -i {} \; -# - dpkg-deb --build matemat -# - mv matemat.deb "matemat_${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1_all.deb" -# artifacts: -# paths: -# - "package/debian/*.deb" -# only: -# - staging -# - master -# - tags +build_deb: + stage: build + script: + - cp -r static/ package/debian/matemat/usr/lib/matemat/static/ + - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ + - python3.6 setup.py egg_info -d -b +master install --root=package/debian/matemat/ --prefix=/usr --optimize=1 + - export PYTHON_BIN=$(which python3) + - cd package/debian + - mv matemat/usr/lib/python3.6/{site,dist}-packages + - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat + - rm -rf matemat/usr/bin + - find . -type f -exec sed -re "s#${PYTHON_BIN}#/usr/bin/python3.6#g" -i {} \; + - dpkg-deb --build matemat + - mv matemat.deb "matemat_${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1_all.deb" + artifacts: + paths: + - "package/debian/*.deb" + only: + - 27-deployment + - staging + - master + - tags build_archlinux: stage: build @@ -99,7 +98,7 @@ build_archlinux: paths: - "package/archlinux/*.pkg.tar.xz" only: - - deployment + - 27-deployment - staging - master - tags diff --git a/README.md b/README.md index 1d75157..2902bfa 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This project intends to provide a well-tested and maintainable alternative to ## Dependencies -- Python 3 (>=3.7) +- Python 3 (>=3.6) - Python dependencies: - file-magic - jinja2 diff --git a/matemat/db/facade.py b/matemat/db/facade.py index 1c8061f..c32df0a 100644 --- a/matemat/db/facade.py +++ b/matemat/db/facade.py @@ -1,5 +1,4 @@ -from __future__ import annotations from typing import Any, Dict, List, Optional, Tuple, Type import crypt @@ -39,7 +38,7 @@ class MatematDatabase(object): """ self.db: DatabaseWrapper = DatabaseWrapper(filename) - def __enter__(self) -> MatematDatabase: + def __enter__(self) -> 'MatematDatabase': # Pass context manager stuff through to the database wrapper self.db.__enter__() return self diff --git a/matemat/db/primitives/Product.py b/matemat/db/primitives/Product.py index 18b5003..c543630 100644 --- a/matemat/db/primitives/Product.py +++ b/matemat/db/primitives/Product.py @@ -1,22 +1,19 @@ -from dataclasses import dataclass - - -@dataclass class Product: """ Representation of a product offered by the Matemat, with a name, prices for users, and the number of items currently in stock. - :param id: The product ID in the database. + :param _id: The product ID in the database. :param name: The product's name. :param price_member: The price of a unit of this product for users marked as "members". :param price_non_member: The price of a unit of this product for users NOT marked as "members". :param stock: The number of items of this product currently in stock. """ - id: int - name: str - price_member: int - price_non_member: int - stock: int + def __init__(self, _id: int, name: str, price_member: int, price_non_member: int, stock: int) -> None: + self.id: int = _id + self.name: str = name + self.price_member: int = price_member + self.price_non_member: int = price_non_member + self.stock: int = stock diff --git a/matemat/db/primitives/Receipt.py b/matemat/db/primitives/Receipt.py index 2ddbe12..29f5d4b 100644 --- a/matemat/db/primitives/Receipt.py +++ b/matemat/db/primitives/Receipt.py @@ -1,17 +1,30 @@ from typing import List -from dataclasses import dataclass from datetime import datetime from matemat.db.primitives import User, Transaction -@dataclass class Receipt: + """ + Representation of a receipt for a user and a given timespan. - id: int - transactions: List[Transaction] - user: User - from_date: datetime - to_date: datetime + :param _id: The receipt ID in the database. + :param transactions: The list of transactions on this receipt. + :param user: The user for whom this receipt was issued. + :param from_date: The beginning of the time span this receipt covers. + :param to_date: The end of the time span this receipt covers. + """ + + def __init__(self, + _id: int, + transactions: List[Transaction], + user: User, + from_date: datetime, + to_date: datetime) -> None: + self.id: int = _id + self.transactions: List[Transaction] = transactions + self.user: User = user + self.from_date: datetime = from_date + self.to_date: datetime = to_date diff --git a/matemat/db/primitives/ReceiptPreference.py b/matemat/db/primitives/ReceiptPreference.py index fb15f18..8afaab5 100644 --- a/matemat/db/primitives/ReceiptPreference.py +++ b/matemat/db/primitives/ReceiptPreference.py @@ -11,7 +11,7 @@ class ReceiptPreference(Enum): A user's preference for the frequency of receiving receipts. """ - def __new__(cls, *args, **kwargs): + def __new__(cls, *args, **kwargs) -> 'ReceiptPreference': e = object.__new__(cls) # The enum's internal value e._value_: int = args[0] diff --git a/matemat/db/primitives/Transaction.py b/matemat/db/primitives/Transaction.py index 964b835..c2777ea 100644 --- a/matemat/db/primitives/Transaction.py +++ b/matemat/db/primitives/Transaction.py @@ -1,6 +1,5 @@ from typing import Optional -from dataclasses import dataclass from datetime import datetime @@ -8,14 +7,23 @@ from matemat.db.primitives import User from matemat.util.currency_format import format_chf -@dataclass(frozen=True) class Transaction: + """ + Representation of a generic transaction involving an user and an amount of money. - id: int - user: User - value: int - old_balance: int - date: datetime + :param _id: The transaction ID in the database. + :param user: The user affected by this transaction. + :param value: The monetary value of this transaction. + :param old_balance: The balance on the user's account before this transaction. + :param date: The date of this transaction. + """ + + def __init__(self, _id: int, user: User, value: int, old_balance: int, date: datetime) -> None: + self.id: int = _id + self.user: User = user + self.value: int = value + self.old_balance: int = old_balance + self.date: datetime = date @property def receipt_date(self) -> str: @@ -38,29 +46,71 @@ class Transaction: return None -@dataclass(frozen=True) class Consumption(Transaction): + """ + Representation of a consumption involving an user, a product and an amount of money. - product: str + :param _id: The transaction ID in the database. + :param user: The user affected by this transaction. + :param value: The (negative) price of the product that was bought. + :param old_balance: The balance on the user's account before this transaction. + :param date: The date of this transaction. + :param product: The name of the product that was bought. + """ + + def __init__(self, _id: int, user: User, value: int, old_balance: int, date: datetime, product: str) -> None: + super().__init__(_id, user, value, old_balance, date) + self.product: str = product @property def receipt_description(self) -> str: return self.product -@dataclass(frozen=True) class Deposit(Transaction): + """ + Representation of a deposit involving an user and an amount of money. + + :param _id: The transaction ID in the database. + :param user: The user affected by this transaction. + :param value: The amount of money that was deposited on the account. + :param old_balance: The balance on the user's account before this transaction. + :param date: The date of this transaction. + """ + + def __init__(self, _id: int, user: User, value: int, old_balance: int, date: datetime) -> None: + super().__init__(_id, user, value, old_balance, date) @property def receipt_description(self) -> str: return 'Deposit' -@dataclass(frozen=True) class Modification(Transaction): + """ + Representation of a administrative account balance modification. Involves the affected user, the agent that + performed the modification and optionally a message for the reason of the modification. - agent: str - reason: Optional[str] + :param _id: The transaction ID in the database. + :param user: The user affected by this transaction. + :param value: The amount of money that was deposited on the account. + :param old_balance: The balance on the user's account before this transaction. + :param date: The date of this transaction. + :param agent: The username of the agent performing the modification. + :param reason: The reason for this modification, as provided by the agent. + """ + + def __init__(self, + _id: int, + user: User, + value: int, + old_balance: int, + date: datetime, + agent: str, + reason: Optional[str]) -> None: + super().__init__(_id, user, value, old_balance, date) + self.agent: str = agent + self.reason: Optional[str] = reason @property def receipt_description(self) -> str: diff --git a/matemat/db/primitives/User.py b/matemat/db/primitives/User.py index 3bf25cc..01f8032 100644 --- a/matemat/db/primitives/User.py +++ b/matemat/db/primitives/User.py @@ -1,30 +1,36 @@ from typing import Optional -from dataclasses import dataclass from matemat.db.primitives.ReceiptPreference import ReceiptPreference -@dataclass class User: """ Representation of a user registered with the Matemat, with a name, e-mail address (optional), whether the user is a member of the organization the Matemat instance is used in, whether the user is an administrator, and the user's account balance. - :param id: The user ID in the database. - :param username: The user's name. + :param _id: The user ID in the database. + :param name: The user's name. :param balance: The balance of the user's account. :param email: The user's e-mail address (optional). - :param admin: Whether the user is an administrator. - :param member: Whether the user is a member. + :param is_admin: Whether the user is an administrator. + :param is_member: Whether the user is a member. :param receipt_pref: The user's preference on how often to receive transaction receipts. """ - id: int - name: str - balance: int - email: Optional[str] = None - is_admin: bool = False - is_member: bool = False - receipt_pref: ReceiptPreference = ReceiptPreference.NONE + def __init__(self, + _id: int, + name: str, + balance: int, + email: Optional[str] = None, + is_admin: bool = False, + is_member: bool = False, + receipt_pref: ReceiptPreference = ReceiptPreference.NONE) -> None: + self.id: int = _id + self.name: str = name + self.balance: int = balance + self.email: Optional[str] = email + self.is_admin: bool = is_admin + self.is_member: bool = is_member + self.receipt_pref: ReceiptPreference = receipt_pref diff --git a/matemat/db/wrapper.py b/matemat/db/wrapper.py index 4460680..3ba5797 100644 --- a/matemat/db/wrapper.py +++ b/matemat/db/wrapper.py @@ -1,5 +1,4 @@ -from __future__ import annotations from typing import Any, Optional import sqlite3 @@ -49,7 +48,7 @@ class DatabaseWrapper(object): self._filename: str = filename self._sqlite_db: Optional[sqlite3.Connection] = None - def __enter__(self) -> DatabaseWrapper: + def __enter__(self) -> 'DatabaseWrapper': self.connect() return self diff --git a/matemat/webserver/requestargs.py b/matemat/webserver/requestargs.py index 6ce11ef..373db90 100644 --- a/matemat/webserver/requestargs.py +++ b/matemat/webserver/requestargs.py @@ -1,5 +1,4 @@ -from __future__ import annotations from typing import Dict, Iterator, List, Tuple, Union @@ -25,7 +24,7 @@ class RequestArguments(object): """ self.__container: Dict[str, RequestArgument] = dict() - def __getitem__(self, key: str) -> RequestArgument: + def __getitem__(self, key: str) -> 'RequestArgument': """ Retrieve the argument for the given name, creating it on the fly, if it doesn't exist. @@ -41,7 +40,7 @@ class RequestArguments(object): # Return the argument for the name return self.__container[key] - def __getattr__(self, key: str) -> RequestArgument: + def __getattr__(self, key: str) -> 'RequestArgument': """ Syntactic sugar for accessing values with a name that can be used in Python attributes. The value will be returned as an immutable view. @@ -279,7 +278,7 @@ class RequestArgument(object): # Yield an immutable scalar view for each (ctype, value) element in the array yield _View(self.__name, v) - def __getitem__(self, index: Union[int, slice]) -> RequestArgument: + def __getitem__(self, index: Union[int, slice]) -> 'RequestArgument': """ Index the argument with either an int or a slice. The returned values are represented as immutable RequestArgument views. diff --git a/setup.py b/setup.py index 265db5c..6c2d005 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ soda machine's touch screen). ''', packages=find_packages(exclude=['*.test']), - python_requires='>=3.7', + python_requires='>=3.6', install_requires=[ 'file-magic', 'jinja2', diff --git a/testing/Dockerfile b/testing/Dockerfile index a67d602..6b9cfab 100644 --- a/testing/Dockerfile +++ b/testing/Dockerfile @@ -1,6 +1,6 @@ # There is no buster image yet and stretch doesn't have a docker package. So let's just "upgrade" the image to buster. -FROM python:3.7-stretch +FROM python:3.6-stretch RUN sed -re 's/stretch/buster/g' -i /etc/apt/sources.list \ && useradd -d /home/matemat -m matemat \ @@ -9,7 +9,7 @@ RUN sed -re 's/stretch/buster/g' -i /etc/apt/sources.list \ && chown matemat:matemat -R /var/matemat/upload \ && apt-get update -qy \ && apt-get install -y --no-install-recommends file sudo openssh-client git docker.io build-essential \ - && python3.7 -m pip install coverage wheel pycodestyle mypy \ + && python3.6 -m pip install coverage wheel pycodestyle mypy \ && rm -rf /var/lib/apt/lists/* WORKDIR /home/matemat From b8cbb265b8ee4153ac2af9322618bdece2502d3f Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 19:20:30 +0100 Subject: [PATCH 17/59] Implemented __eq__ and __hash__ for the database primitives --- matemat/db/primitives/Product.py | 12 +++++++++ matemat/db/primitives/Receipt.py | 12 +++++++++ matemat/db/primitives/Transaction.py | 39 ++++++++++++++++++++++++++++ matemat/db/primitives/User.py | 14 ++++++++++ 4 files changed, 77 insertions(+) diff --git a/matemat/db/primitives/Product.py b/matemat/db/primitives/Product.py index c543630..ed196d4 100644 --- a/matemat/db/primitives/Product.py +++ b/matemat/db/primitives/Product.py @@ -17,3 +17,15 @@ class Product: self.price_member: int = price_member self.price_non_member: int = price_non_member self.stock: int = stock + + def __eq__(self, other) -> bool: + if not isinstance(other, Product): + return False + return self.id == other.id and \ + self.name == other.name and \ + self.price_member == other.price_member and \ + self.price_non_member == other.price_non_member and \ + self.stock == other.stock + + def __hash__(self) -> int: + return hash((self.id, self.name, self.price_member, self.price_non_member, self.stock)) diff --git a/matemat/db/primitives/Receipt.py b/matemat/db/primitives/Receipt.py index 29f5d4b..f11320a 100644 --- a/matemat/db/primitives/Receipt.py +++ b/matemat/db/primitives/Receipt.py @@ -28,3 +28,15 @@ class Receipt: self.user: User = user self.from_date: datetime = from_date self.to_date: datetime = to_date + + def __eq__(self, other) -> bool: + if not isinstance(other, Receipt): + return False + return self.id == other.id and \ + self.transactions == other.transactions and \ + self.user == other.user and \ + self.from_date == other.from_date and \ + self.to_date == other.to_date + + def __hash__(self) -> int: + return hash((self.id, self.transactions, self.user, self.from_date, self.to_date)) diff --git a/matemat/db/primitives/Transaction.py b/matemat/db/primitives/Transaction.py index c2777ea..061f65f 100644 --- a/matemat/db/primitives/Transaction.py +++ b/matemat/db/primitives/Transaction.py @@ -45,6 +45,18 @@ class Transaction: def receipt_message(self) -> Optional[str]: return None + def __eq__(self, other) -> bool: + if not isinstance(other, Transaction): + return False + return self.id == other.id and \ + self.user == other.user and \ + self.value == other.value and \ + self.old_balance == other.old_balance and \ + self.date == other.date + + def __hash__(self) -> int: + return hash((self.id, self.user, self.value, self.old_balance, self.date)) + class Consumption(Transaction): """ @@ -66,6 +78,15 @@ class Consumption(Transaction): def receipt_description(self) -> str: return self.product + def __eq__(self, other) -> bool: + if not isinstance(other, Consumption): + return False + return super().__eq__(other) and \ + self.product == other.product + + def __hash__(self) -> int: + return hash((super().__hash__(), self.product)) + class Deposit(Transaction): """ @@ -85,6 +106,14 @@ class Deposit(Transaction): def receipt_description(self) -> str: return 'Deposit' + def __eq__(self, other) -> bool: + if not isinstance(other, Deposit): + return False + return super().__eq__(other) + + def __hash__(self) -> int: + return super().__hash__() + class Modification(Transaction): """ @@ -122,3 +151,13 @@ class Modification(Transaction): return None else: return f'Reason: «{self.reason}»' + + def __eq__(self, other) -> bool: + if not isinstance(other, Modification): + return False + return super().__eq__(other) and \ + self.agent == other.agent and \ + self.reason == other.reason + + def __hash__(self) -> int: + return hash((super().__hash__(), self.agent, self.reason)) diff --git a/matemat/db/primitives/User.py b/matemat/db/primitives/User.py index 01f8032..ce203d7 100644 --- a/matemat/db/primitives/User.py +++ b/matemat/db/primitives/User.py @@ -34,3 +34,17 @@ class User: self.is_admin: bool = is_admin self.is_member: bool = is_member self.receipt_pref: ReceiptPreference = receipt_pref + + def __eq__(self, other) -> bool: + if not isinstance(other, User): + return False + return self.id == other.id and \ + self.name == other.name and \ + self.balance == other.balance and \ + self.email == other.email and \ + self.is_admin == other.is_admin and \ + self.is_member == other.is_member and \ + self.receipt_pref == other.receipt_pref + + def __hash__(self) -> int: + return hash((self.id, self.name, self.balance, self.email, self.is_admin, self.is_member, self.receipt_pref)) From 061fd0b85af223005f1d58e290db6faa5bee7cdc Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 19:22:22 +0100 Subject: [PATCH 18/59] Fixed Python dependency in debian/control --- package/debian/matemat/DEBIAN/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/debian/matemat/DEBIAN/control b/package/debian/matemat/DEBIAN/control index 08cbd9b..5bdb3e4 100644 --- a/package/debian/matemat/DEBIAN/control +++ b/package/debian/matemat/DEBIAN/control @@ -4,7 +4,7 @@ Maintainer: s3lph Section: web Priority: extra Architecture: all -Depends: python3 >= 3.7, python3-jinja2, python3-magic, python3-pil +Depends: python3 >= 3.6, python3-jinja2, python3-magic, python3-pil Description: A soda machine stock-keeping webservice A web service for automated stock-keeping of a soda machine written in Python. It provides a touch-input-friendly user interface (as most input happens through the From fe1f52a954aeee47cf3f777414d2dc55f9c63438 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 19:28:15 +0100 Subject: [PATCH 19/59] Updated Python version in the documentation. --- doc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc b/doc index 411880a..492df95 160000 --- a/doc +++ b/doc @@ -1 +1 @@ -Subproject commit 411880ae72b3a2204fed4b945bdb3a15d3ece364 +Subproject commit 492df9502bb44a9fb5214c135172222f6392ba24 From 726b4a93703d7b4a040a527be60e4f4c37975f48 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 21:22:25 +0100 Subject: [PATCH 20/59] Remplaced a calendar function not available in Python 3.6 --- matemat/util/monthdelta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matemat/util/monthdelta.py b/matemat/util/monthdelta.py index 49c1fa0..78cbd28 100644 --- a/matemat/util/monthdelta.py +++ b/matemat/util/monthdelta.py @@ -20,7 +20,7 @@ def add_months(d: datetime, months: int) -> datetime: days: int = 0 # Iterate the months between the passed date and the target month for i in range(months): - days += calendar.monthlen(*nextmonth) + days += calendar.monthrange(*nextmonth)[1] nextmonth = calendar.nextmonth(*nextmonth) # Set the day of month temporarily to 1, then add the day offset to reach the 1st of the target month newdate: datetime = d.replace(day=1) + timedelta(days=days) From eaab46b7286c9efeb613139939ea4f5d3f4665b8 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 21:27:17 +0100 Subject: [PATCH 21/59] Replaced yet a calendar function not available in Python 3.6 --- matemat/util/monthdelta.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/matemat/util/monthdelta.py b/matemat/util/monthdelta.py index 78cbd28..b93e2ab 100644 --- a/matemat/util/monthdelta.py +++ b/matemat/util/monthdelta.py @@ -21,9 +21,12 @@ def add_months(d: datetime, months: int) -> datetime: # Iterate the months between the passed date and the target month for i in range(months): days += calendar.monthrange(*nextmonth)[1] - nextmonth = calendar.nextmonth(*nextmonth) + if nextmonth[1] == 12: + nextmonth = nextmonth[0] + 1, 1 + else: + nextmonth = nextmonth[0], nextmonth[1] + 1 # Set the day of month temporarily to 1, then add the day offset to reach the 1st of the target month newdate: datetime = d.replace(day=1) + timedelta(days=days) # Re-set the day of month to the intended value, but capped by the max. day in the target month - newdate = newdate.replace(day=min(d.day, calendar.monthlen(newdate.year, newdate.month))) + newdate = newdate.replace(day=min(d.day, calendar.monthrange(newdate.year, newdate.month)[1])) return newdate From 3e006228e17b56678f0448df4d7e345e12473256 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 21:28:24 +0100 Subject: [PATCH 22/59] Fixed the build_wheel task, renamed build_deb to build_debian --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ab5e86d..06b205a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,12 +51,12 @@ build_wheel: paths: - "dist/*.whl" only: - - deployment + - 27-deployment - staging - master - tags -build_deb: +build_debian: stage: build script: - cp -r static/ package/debian/matemat/usr/lib/matemat/static/ From 252e8d73d6500cf85089fca16a21bd349f3c4c51 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 21:40:10 +0100 Subject: [PATCH 23/59] Fixed debian/control dependency string --- package/debian/matemat/DEBIAN/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/debian/matemat/DEBIAN/control b/package/debian/matemat/DEBIAN/control index 5bdb3e4..6c64cfe 100644 --- a/package/debian/matemat/DEBIAN/control +++ b/package/debian/matemat/DEBIAN/control @@ -4,7 +4,7 @@ Maintainer: s3lph Section: web Priority: extra Architecture: all -Depends: python3 >= 3.6, python3-jinja2, python3-magic, python3-pil +Depends: python3 (>= 3.6), python3-jinja2, python3-magic, python3-pil Description: A soda machine stock-keeping webservice A web service for automated stock-keeping of a soda machine written in Python. It provides a touch-input-friendly user interface (as most input happens through the From 2fdae8fc89d72094c826d131e1326206e1e61fd7 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 3 Nov 2018 21:45:47 +0100 Subject: [PATCH 24/59] gitlab-ci: Fixed debian package directory permissions --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 06b205a..ff40b95 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,6 +64,7 @@ build_debian: - python3.6 setup.py egg_info -d -b +master install --root=package/debian/matemat/ --prefix=/usr --optimize=1 - export PYTHON_BIN=$(which python3) - cd package/debian + - chmod 0755 -R matemat/DEBIAN - mv matemat/usr/lib/python3.6/{site,dist}-packages - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin From 2e92d1c1ab8cb07d2134334f5a671f066f156315 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 02:35:33 +0100 Subject: [PATCH 25/59] Testing automated release, simplified packaging stage --- .gitlab-ci.yml | 32 +++++++---- CHANGELOG.md | 17 ++++++ package/release.py | 137 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 12 deletions(-) create mode 100644 CHANGELOG.md create mode 100755 package/release.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ff40b95..880eb01 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ image: s3lph/matemat-ci:20181103-01 stages: - test - build -- staging +- deploy @@ -45,15 +45,15 @@ build_docker: build_wheel: stage: build script: - - python3.6 setup.py egg_info --tag-build "+$CI_COMMIT_SHA" --tag-date bdist_wheel - - python3.6 setup.py egg_info --tag-build "+$CI_COMMIT_REF_NAME" --tag-date bdist_wheel + - python3.6 setup.py egg_info bdist_wheel + - cd dist + - sha256sum *.whl > SHA256SUMS artifacts: paths: - "dist/*.whl" + - dist/SHA256SUMS only: - 27-deployment - - staging - - master - tags build_debian: @@ -70,14 +70,14 @@ build_debian: - rm -rf matemat/usr/bin - find . -type f -exec sed -re "s#${PYTHON_BIN}#/usr/bin/python3.6#g" -i {} \; - dpkg-deb --build matemat - - mv matemat.deb "matemat_${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1_all.deb" + - mv matemat.deb "matemat_${MATEMAT_VERSION}-1_all.deb" + - sha256sum *.deb > SHA256SUMS artifacts: paths: - "package/debian/*.deb" + - package/debian/SHA256SUMS only: - 27-deployment - - staging - - master - tags build_archlinux: @@ -94,20 +94,19 @@ build_archlinux: - rm -rf matemat/usr/bin - sed -re "s/__VERSION__/${MATEMAT_VERSION}/g" -i PKGBUILD - sudo -u nobody makepkg -c - - mv matemat-${MATEMAT_VERSION}-1-any.pkg.tar.xz "matemat-${MATEMAT_VERSION}+${CI_COMMIT_REF_NAME}-1-any.pkg.tar.xz" + - sha256sum *.pkg.tar.xz > SHA256SUMS artifacts: paths: - "package/archlinux/*.pkg.tar.xz" + - package/archlinux/SHA256SUMS only: - 27-deployment - - staging - - master - tags staging: - stage: staging + stage: deploy script: - eval $(ssh-agent -s) - ssh-add - <<<"$STAGING_SSH_PRIVATE_KEY" @@ -117,3 +116,12 @@ staging: url: https://matemat.kernelpanic.lol/ only: - staging + + + +release: + stage: deploy + script: + - python package/release.py + only: + - tags diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a8aa755 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,17 @@ +# Matemat Changelog + + +## Version 0.1 + +This is only a test for the release CI task - please ignore. + +The packages attached to this release have not been tested. + +### Changes + + +- Added CI release task. +- Went back to Python 3.6 for Debian packaging. + + + diff --git a/package/release.py b/package/release.py new file mode 100755 index 0000000..65b6599 --- /dev/null +++ b/package/release.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 + +from typing import Any, Dict, Optional, Tuple + +import os +import sys +import json +import urllib.request +import http.client +from urllib.error import HTTPError + + +def parse_changelog(tag: str) -> Optional[str]: + release_changelog: str = '' + with open('CHANGELOG.md', 'r') as f: + in_target: bool = False + done: bool = False + for line in f.readlines(): + if in_target: + if f'' in line: + done = True + break + release_changelog += line + elif f'' in line: + in_target = True + continue + if not done: + return None + return release_changelog + + +def fetch_single_shafile(url: str) -> str: + req = urllib.request.Request(url) + try: + resp: http.client.HTTPResponse = urllib.request.urlopen(req) + except HTTPError as e: + print(e.read().decode()) + sys.exit(1) + resp_data: bytes = resp.readline() + shafile: str = resp_data.decode() + filename: str = shafile.strip().split(' ')[-1].strip() + return filename + + +def fetch_wheel_url(base_url: str) -> Optional[Tuple[str, str]]: + wheel_sha_url: str = f'{base_url}/dist/SHA256SUMS?job=build_wheel' + wheel_filename: str = fetch_single_shafile(wheel_sha_url) + wheel_url: str = f'{base_url}/dist/{wheel_filename}?job=build_wheel' + return wheel_url, wheel_sha_url + + +def fetch_debian_url(base_url: str) -> Optional[Tuple[str, str]]: + debian_sha_url: str = f'{base_url}/package/debian/SHA256SUMS?job=build_debian' + debian_filename: str = fetch_single_shafile(debian_sha_url) + debian_url: str = f'{base_url}/package/debian/{debian_filename}?job=build_debian' + return debian_url, debian_sha_url + + +def fetch_arch_url(base_url: str) -> Optional[Tuple[str, str]]: + arch_sha_url: str = f'{base_url}/package/archlinux/SHA256SUMS?job=build_archlinux' + arch_filename: str = fetch_single_shafile(arch_sha_url) + arch_url: str = f'{base_url}/package/archlinux/{arch_filename}?job=build_archlinux' + return arch_url, arch_sha_url + + +def main(): + api_token: Optional[str] = os.getenv('GITLAB_API_TOKEN') + release_tag: Optional[str] = os.getenv('CI_COMMIT_TAG') + project_name: Optional[str] = os.getenv('CI_PROJECT_PATH') + project_id: Optional[str] = os.getenv('CI_PROJECT_ID') + if api_token is None: + print('GITLAB_API_TOKEN is not set.', file=sys.stderr) + sys.exit(1) + if release_tag is None: + print('CI_COMMIT_TAG is not set.', file=sys.stderr) + sys.exit(1) + if project_name is None: + print('CI_PROJECT_PATH is not set.', file=sys.stderr) + sys.exit(1) + if project_id is None: + print('CI_PROJECT_ID is not set.', file=sys.stderr) + sys.exit(1) + + changelog: Optional[str] = parse_changelog(release_tag) + if changelog is None: + print('Changelog could not be parsed.', file=sys.stderr) + sys.exit(1) + + base_url: str = f'https://gitlab.com/{project_name}/-/jobs/artifacts/{release_tag}/raw' + + wheel_url, wheel_sha_url = fetch_wheel_url(base_url) + debian_url, debian_sha_url = fetch_wheel_url(base_url) + arch_url, arch_sha_url = fetch_wheel_url(base_url) + + augmented_changelog = f'''{changelog.strip()} + +### Download + +- [Python Wheel]({wheel_url}) ([sha256]({wheel_sha_url})) +- [Debian Package]({debian_url}) ([sha256]({debian_sha_url})) +- [Arch Linux Package]({arch_url}) ([sha256]({arch_sha_url}))''' + + encoder = json.encoder.JSONEncoder() + decoder = json.decoder.JSONDecoder() + post_body: str = encoder.encode({'description': augmented_changelog}) + + gitlab_release_api_url: str = \ + f'https://gitlab.com/api/v4/projects/{project_id}/repository/tags/{release_tag}/release' + headers: Dict[str, str] = { + 'Private-Token': api_token + } + + request = urllib.request.Request( + gitlab_release_api_url, + post_body.encode('utf-8'), + headers=headers, + method='POST' + ) + try: + response: http.client.HTTPResponse = urllib.request.urlopen(request) + except HTTPError as e: + print(e.read().decode()) + sys.exit(1) + response_bytes: bytes = response.read() + response_str: str = response_bytes.decode() + response_data: Dict[str, Any] = decoder.decode(response_str) + + if response_data['tag_name'] != release_tag: + print('Something went wrong...', file=sys.stderr) + print(response_str, file=sys.stderr) + sys.exit(1) + + print(response_data['description']) + + +if __name__ == '__main__': + main() From cc34d72c73b311fb37fd100575f28b87fd7fc42f Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 02:51:57 +0100 Subject: [PATCH 26/59] Fixed docker build task --- .gitlab-ci.yml | 5 ++++- package/release.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 880eb01..6c49973 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,12 +32,15 @@ codestyle: build_docker: stage: build script: - - docker build -t "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" package/docker + - docker build -t "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" -f package/docker/Dockerfile . - docker tag "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_REF_NAME" + - '[[ -n "$CI_COMMIT_TAG" ]] && docker tag "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_TAG"' - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN registry.gitlab.com - docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" - docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_REF_NAME" + - '[[ -n "$CI_COMMIT_TAG" ]] && docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_TAG"' only: + - 27-deployment - staging - master - tags diff --git a/package/release.py b/package/release.py index 65b6599..263b674 100755 --- a/package/release.py +++ b/package/release.py @@ -98,7 +98,8 @@ def main(): - [Python Wheel]({wheel_url}) ([sha256]({wheel_sha_url})) - [Debian Package]({debian_url}) ([sha256]({debian_sha_url})) -- [Arch Linux Package]({arch_url}) ([sha256]({arch_sha_url}))''' +- [Arch Linux Package]({arch_url}) ([sha256]({arch_sha_url})) +- Docker image: registry.gitlab.com/{project_name}:{release_tag}''' encoder = json.encoder.JSONEncoder() decoder = json.decoder.JSONDecoder() From 87db033a8963c43316b36201379f387d7424af07 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 02:55:33 +0100 Subject: [PATCH 27/59] Fixed dockerfile --- package/docker/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package/docker/Dockerfile b/package/docker/Dockerfile index fae8463..9190083 100644 --- a/package/docker/Dockerfile +++ b/package/docker/Dockerfile @@ -1,12 +1,13 @@ FROM python:3.7-alpine -ADD ../.. / +ADD . / RUN mkdir -p /var/matemat/db /var/matemat/upload \ && apk --update add libmagic zlib jpeg zlib-dev jpeg-dev build-base \ && pip3 install -u . \ && apk del zlib-dev jpeg-dev build-base \ - && rm -rf /var/cache/apk /root/.cache/pip + && rm -rf /var/cache/apk /root/.cache/pip \ + && rm -rf /package EXPOSE 80/tcp CMD [ "/run.sh" ] From 5da394733498bf2cbc4f276fc25aeb43797098de Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 02:58:18 +0100 Subject: [PATCH 28/59] Fixed dockerfile, v2 --- package/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/docker/Dockerfile b/package/docker/Dockerfile index 9190083..d85e4f4 100644 --- a/package/docker/Dockerfile +++ b/package/docker/Dockerfile @@ -4,7 +4,7 @@ FROM python:3.7-alpine ADD . / RUN mkdir -p /var/matemat/db /var/matemat/upload \ && apk --update add libmagic zlib jpeg zlib-dev jpeg-dev build-base \ - && pip3 install -u . \ + && pip3 install -e . \ && apk del zlib-dev jpeg-dev build-base \ && rm -rf /var/cache/apk /root/.cache/pip \ && rm -rf /package From a163bce7817f25364ccab6a77c5def5a042cdd7c Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 03:11:42 +0100 Subject: [PATCH 29/59] Fixed CI script; failed on untagged commit --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6c49973..254a17b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,11 +34,11 @@ build_docker: script: - docker build -t "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" -f package/docker/Dockerfile . - docker tag "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_REF_NAME" - - '[[ -n "$CI_COMMIT_TAG" ]] && docker tag "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_TAG"' + - if [[ -n "$CI_COMMIT_TAG" ]]; then docker tag "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_TAG"; fi - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN registry.gitlab.com - docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_SHA" - docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_REF_NAME" - - '[[ -n "$CI_COMMIT_TAG" ]] && docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_TAG"' + - if [[ -n "$CI_COMMIT_TAG" ]]; then docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_TAG"; fi only: - 27-deployment - staging From 566d1efdd6cebc39d52707b9749eeaf72419d26a Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 10:26:55 +0100 Subject: [PATCH 30/59] Updated release script to use job-id based urls, as tags do not work --- package/release.py | 65 +++++++++++++++----- touchkey.html | 147 --------------------------------------------- 2 files changed, 49 insertions(+), 163 deletions(-) delete mode 100644 touchkey.html diff --git a/package/release.py b/package/release.py index 263b674..44dd32b 100755 --- a/package/release.py +++ b/package/release.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -from typing import Any, Dict, Optional, Tuple +from typing import Any, Dict, List, Optional, Tuple import os import sys @@ -10,6 +10,10 @@ import http.client from urllib.error import HTTPError +encoder = json.encoder.JSONEncoder() +decoder = json.decoder.JSONDecoder() + + def parse_changelog(tag: str) -> Optional[str]: release_changelog: str = '' with open('CHANGELOG.md', 'r') as f: @@ -29,6 +33,28 @@ def parse_changelog(tag: str) -> Optional[str]: return release_changelog +def fetch_job_ids(project_id: int, pipeline_id: int, api_token: str) -> Dict[str, str]: + url: str = f'https://gitlab.com/api/v4/projects/{project_id}/pipelines/{pipeline_id}/jobs' + headers: Dict[str, str] = { + 'Private-Token': api_token + } + req = urllib.request.Request(url, headers=headers) + try: + resp: http.client.HTTPResponse = urllib.request.urlopen(req) + except HTTPError as e: + print(e.read().decode()) + sys.exit(1) + resp_data: bytes = resp.read() + joblist: List[Dict[str, Any]] = decoder.decode(resp_data.decode()) + + jobidmap: Dict[str, str] = {} + for job in joblist: + name: str = job['name'] + id: str = job['id'] + jobidmap[name] = id + return jobidmap + + def fetch_single_shafile(url: str) -> str: req = urllib.request.Request(url) try: @@ -42,24 +68,27 @@ def fetch_single_shafile(url: str) -> str: return filename -def fetch_wheel_url(base_url: str) -> Optional[Tuple[str, str]]: - wheel_sha_url: str = f'{base_url}/dist/SHA256SUMS?job=build_wheel' +def fetch_wheel_url(base_url: str, job_ids: Dict[str, str]) -> Optional[Tuple[str, str]]: + mybase: str = f'{base_url}/jobs/{job_ids["build_wheel"]}/artifacts/raw' + wheel_sha_url: str = f'{mybase}/dist/SHA256SUMS' wheel_filename: str = fetch_single_shafile(wheel_sha_url) - wheel_url: str = f'{base_url}/dist/{wheel_filename}?job=build_wheel' + wheel_url: str = f'{mybase}/dist/{wheel_filename}' return wheel_url, wheel_sha_url -def fetch_debian_url(base_url: str) -> Optional[Tuple[str, str]]: - debian_sha_url: str = f'{base_url}/package/debian/SHA256SUMS?job=build_debian' +def fetch_debian_url(base_url: str, job_ids: Dict[str, str]) -> Optional[Tuple[str, str]]: + mybase: str = f'{base_url}/jobs/{job_ids["build_debian"]}/artifacts/raw' + debian_sha_url: str = f'{mybase}/package/debian/SHA256SUMS' debian_filename: str = fetch_single_shafile(debian_sha_url) - debian_url: str = f'{base_url}/package/debian/{debian_filename}?job=build_debian' + debian_url: str = f'{mybase}/package/debian/{debian_filename}' return debian_url, debian_sha_url -def fetch_arch_url(base_url: str) -> Optional[Tuple[str, str]]: - arch_sha_url: str = f'{base_url}/package/archlinux/SHA256SUMS?job=build_archlinux' +def fetch_arch_url(base_url: str, job_ids: Dict[str, str]) -> Optional[Tuple[str, str]]: + mybase: str = f'{base_url}/jobs/{job_ids["build_archlinux"]}/artifacts/raw' + arch_sha_url: str = f'{mybase}/package/archlinux/SHA256SUMS' arch_filename: str = fetch_single_shafile(arch_sha_url) - arch_url: str = f'{base_url}/package/archlinux/{arch_filename}?job=build_archlinux' + arch_url: str = f'{mybase}/package/archlinux/{arch_filename}' return arch_url, arch_sha_url @@ -68,6 +97,7 @@ def main(): release_tag: Optional[str] = os.getenv('CI_COMMIT_TAG') project_name: Optional[str] = os.getenv('CI_PROJECT_PATH') project_id: Optional[str] = os.getenv('CI_PROJECT_ID') + pipeline_id: Optional[str] = os.getenv('CI_PIPELINE_ID') if api_token is None: print('GITLAB_API_TOKEN is not set.', file=sys.stderr) sys.exit(1) @@ -80,17 +110,22 @@ def main(): if project_id is None: print('CI_PROJECT_ID is not set.', file=sys.stderr) sys.exit(1) + if pipeline_id is None: + print('CI_PIPELINE_ID is not set.', file=sys.stderr) + sys.exit(1) changelog: Optional[str] = parse_changelog(release_tag) if changelog is None: print('Changelog could not be parsed.', file=sys.stderr) sys.exit(1) - base_url: str = f'https://gitlab.com/{project_name}/-/jobs/artifacts/{release_tag}/raw' + job_ids: Dict[str, str] = fetch_job_ids(project_id, pipeline_id, api_token) - wheel_url, wheel_sha_url = fetch_wheel_url(base_url) - debian_url, debian_sha_url = fetch_wheel_url(base_url) - arch_url, arch_sha_url = fetch_wheel_url(base_url) + base_url: str = f'https://gitlab.com/{project_name}/-' + + wheel_url, wheel_sha_url = fetch_wheel_url(base_url, job_ids) + debian_url, debian_sha_url = fetch_wheel_url(base_url, job_ids) + arch_url, arch_sha_url = fetch_wheel_url(base_url, job_ids) augmented_changelog = f'''{changelog.strip()} @@ -101,8 +136,6 @@ def main(): - [Arch Linux Package]({arch_url}) ([sha256]({arch_sha_url})) - Docker image: registry.gitlab.com/{project_name}:{release_tag}''' - encoder = json.encoder.JSONEncoder() - decoder = json.decoder.JSONDecoder() post_body: str = encoder.encode({'description': augmented_changelog}) gitlab_release_api_url: str = \ diff --git a/touchkey.html b/touchkey.html deleted file mode 100644 index 5d5b427..0000000 --- a/touchkey.html +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - -

Welcome, {{username}}

- - - - - - - - - - - - - - - - - - - - - - - - - - - From 54ca432ee7e019beb0d753e89a10132ed6cf8e8d Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 10:43:50 +0100 Subject: [PATCH 31/59] Added missing MIME type header in release script --- package/release.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/package/release.py b/package/release.py index 44dd32b..d9a6c2a 100755 --- a/package/release.py +++ b/package/release.py @@ -10,10 +10,6 @@ import http.client from urllib.error import HTTPError -encoder = json.encoder.JSONEncoder() -decoder = json.decoder.JSONDecoder() - - def parse_changelog(tag: str) -> Optional[str]: release_changelog: str = '' with open('CHANGELOG.md', 'r') as f: @@ -45,13 +41,13 @@ def fetch_job_ids(project_id: int, pipeline_id: int, api_token: str) -> Dict[str print(e.read().decode()) sys.exit(1) resp_data: bytes = resp.read() - joblist: List[Dict[str, Any]] = decoder.decode(resp_data.decode()) + joblist: List[Dict[str, Any]] = json.loads(resp_data.decode()) jobidmap: Dict[str, str] = {} for job in joblist: name: str = job['name'] - id: str = job['id'] - jobidmap[name] = id + job_id: str = job['id'] + jobidmap[name] = job_id return jobidmap @@ -136,12 +132,13 @@ def main(): - [Arch Linux Package]({arch_url}) ([sha256]({arch_sha_url})) - Docker image: registry.gitlab.com/{project_name}:{release_tag}''' - post_body: str = encoder.encode({'description': augmented_changelog}) + post_body: str = json.dumps({'description': augmented_changelog}) gitlab_release_api_url: str = \ f'https://gitlab.com/api/v4/projects/{project_id}/repository/tags/{release_tag}/release' headers: Dict[str, str] = { - 'Private-Token': api_token + 'Private-Token': api_token, + 'Content-Type': 'application/json; charset=utf-8' } request = urllib.request.Request( @@ -157,7 +154,7 @@ def main(): sys.exit(1) response_bytes: bytes = response.read() response_str: str = response_bytes.decode() - response_data: Dict[str, Any] = decoder.decode(response_str) + response_data: Dict[str, Any] = json.loads(response_str) if response_data['tag_name'] != release_tag: print('Something went wrong...', file=sys.stderr) From 072db827bb23908d622a18f84184336e302a3146 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 10:52:25 +0100 Subject: [PATCH 32/59] Fixed release notes download urls --- package/release.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/release.py b/package/release.py index d9a6c2a..8461268 100755 --- a/package/release.py +++ b/package/release.py @@ -120,8 +120,8 @@ def main(): base_url: str = f'https://gitlab.com/{project_name}/-' wheel_url, wheel_sha_url = fetch_wheel_url(base_url, job_ids) - debian_url, debian_sha_url = fetch_wheel_url(base_url, job_ids) - arch_url, arch_sha_url = fetch_wheel_url(base_url, job_ids) + debian_url, debian_sha_url = fetch_debian_url(base_url, job_ids) + arch_url, arch_sha_url = fetch_arch_url(base_url, job_ids) augmented_changelog = f'''{changelog.strip()} From ea18d0e8dea8d6ed911e37691930e20f2bad0b92 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 14:58:59 +0100 Subject: [PATCH 33/59] Automatic debian changelog generation --- .gitlab-ci.yml | 7 +++++++ CHANGELOG.md | 4 ++-- package/debian/matemat/DEBIAN/changelog | 5 ----- 3 files changed, 9 insertions(+), 7 deletions(-) delete mode 100644 package/debian/matemat/DEBIAN/changelog diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 254a17b..34390da 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -62,6 +62,13 @@ build_wheel: build_debian: stage: build script: + - echo -n > package/debian/matemat/DEBIAN/changelog + - | + for version in "$(cat CHANGELOG.md | grep '" | grep -B 1000 "<"'!'"-- END CHANGES ${version} -->" | tail -n +2 | head -n -1 | sed -re 's/^-/ */g' >> package/debian/matemat/DEBIAN/changelog + echo "\n -- ${PACKAGE_AUTHOR} $(date -R)\n" >> package/debian/matemat/DEBIAN/changelog + done - cp -r static/ package/debian/matemat/usr/lib/matemat/static/ - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ - python3.6 setup.py egg_info -d -b +master install --root=package/debian/matemat/ --prefix=/usr --optimize=1 diff --git a/CHANGELOG.md b/CHANGELOG.md index a8aa755..b4381e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,9 @@ The packages attached to this release have not been tested. ### Changes - + - Added CI release task. - Went back to Python 3.6 for Debian packaging. - + diff --git a/package/debian/matemat/DEBIAN/changelog b/package/debian/matemat/DEBIAN/changelog deleted file mode 100644 index 8b78df4..0000000 --- a/package/debian/matemat/DEBIAN/changelog +++ /dev/null @@ -1,5 +0,0 @@ -matemat (0.1-1) UNRELEASED; urgency=medium - - * Initial release. - - -- s3lph Wed, 12 Sep 2018 02:04:12 +0000 From 57f794cc598d815437f0206edf6e887dd8aa4fc0 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 15:19:30 +0100 Subject: [PATCH 34/59] Fixed debian postinst --- package/debian/matemat/DEBIAN/postinst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package/debian/matemat/DEBIAN/postinst b/package/debian/matemat/DEBIAN/postinst index ceeed0c..305e6de 100755 --- a/package/debian/matemat/DEBIAN/postinst +++ b/package/debian/matemat/DEBIAN/postinst @@ -5,12 +5,11 @@ set -e if [[ "$1" == "configure" ]]; then if ! getent group matemat >/dev/null; then - addgroup --quiet --system matemat + groupadd --system matemat fi if ! getent passwd matemat >/dev/null; then - adduser --quiet --system --create-home --ingroup matemat --home /var/lib/matemat --shell /usr/sbin/nologin \ - matemat + useradd --system --create-home --gid matemat --home-dir /var/lib/matemat --shell /usr/sbin/nologin matemat fi chown matemat:matemat -R /var/lib/matemat From da16b5ef7eac2f7af437aaed556f736e69a0f6d2 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 21:15:29 +0100 Subject: [PATCH 35/59] Fixed debian postinst, v2 --- package/debian/matemat/DEBIAN/postinst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/debian/matemat/DEBIAN/postinst b/package/debian/matemat/DEBIAN/postinst index 305e6de..d94076b 100755 --- a/package/debian/matemat/DEBIAN/postinst +++ b/package/debian/matemat/DEBIAN/postinst @@ -13,7 +13,7 @@ if [[ "$1" == "configure" ]]; then fi chown matemat:matemat -R /var/lib/matemat - find /var/lib/matemat -type d -exec chmod 0750 {} - find /var/lib/matemat -type f -exec chmod 0640 {} + find /var/lib/matemat -type d -exec chmod 0750 {} \; + find /var/lib/matemat -type f -exec chmod 0640 {} \; fi From 3c7e33e9fa7a3b745301301ca94ac822c7b359bb Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 4 Nov 2018 21:44:30 +0100 Subject: [PATCH 36/59] Added systemctl daemon-reload to debian and arch packages --- package/archlinux/matemat.install | 8 ++++++++ package/debian/matemat/DEBIAN/postinst | 2 ++ package/debian/matemat/DEBIAN/postrm | 9 +++++++++ package/debian/matemat/DEBIAN/prerm | 10 ++++++++++ 4 files changed, 29 insertions(+) create mode 100755 package/debian/matemat/DEBIAN/postrm create mode 100755 package/debian/matemat/DEBIAN/prerm diff --git a/package/archlinux/matemat.install b/package/archlinux/matemat.install index 8a33b84..c7f9e46 100755 --- a/package/archlinux/matemat.install +++ b/package/archlinux/matemat.install @@ -13,6 +13,8 @@ post_install() { find /var/lib/matemat -type d -exec chmod 0750 {} \; find /var/lib/matemat -type f -exec chmod 0640 {} \; + systemctl daemon-reload + } pre_remove() { @@ -21,3 +23,9 @@ pre_remove() { userdel matemat } + +post_remove() { + + systemctl daemon-reload + +} diff --git a/package/debian/matemat/DEBIAN/postinst b/package/debian/matemat/DEBIAN/postinst index d94076b..f18f7fb 100755 --- a/package/debian/matemat/DEBIAN/postinst +++ b/package/debian/matemat/DEBIAN/postinst @@ -16,4 +16,6 @@ if [[ "$1" == "configure" ]]; then find /var/lib/matemat -type d -exec chmod 0750 {} \; find /var/lib/matemat -type f -exec chmod 0640 {} \; + systemctl daemon-reload + fi diff --git a/package/debian/matemat/DEBIAN/postrm b/package/debian/matemat/DEBIAN/postrm new file mode 100755 index 0000000..0a1c224 --- /dev/null +++ b/package/debian/matemat/DEBIAN/postrm @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +if [[ "$1" == "remove" ]]; then + + systemctl daemon-reload + +fi diff --git a/package/debian/matemat/DEBIAN/prerm b/package/debian/matemat/DEBIAN/prerm new file mode 100755 index 0000000..657a1fc --- /dev/null +++ b/package/debian/matemat/DEBIAN/prerm @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +if [[ "$1" == "remove" ]]; then + + systemctl stop matemat.service + userdel matemat + +fi From 7479c7d9f1d4343f0e19232aa6390510354c326f Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 7 Nov 2018 14:53:59 +0100 Subject: [PATCH 37/59] Debian package quality assurance (lintian) --- .gitlab-ci.yml | 19 +++++++++++-------- package/debian/matemat/DEBIAN/conffiles | 1 + package/debian/matemat/DEBIAN/control | 10 +++++----- .../lib/systemd/system/matemat.service | 0 .../share/doc/matemat}/copyright | 0 testing/Dockerfile | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 package/debian/matemat/DEBIAN/conffiles rename package/debian/matemat/{usr => }/lib/systemd/system/matemat.service (100%) rename package/debian/matemat/{DEBIAN => usr/share/doc/matemat}/copyright (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 34390da..a2557e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ --- -image: s3lph/matemat-ci:20181103-01 +image: s3lph/matemat-ci:20181107-01 stages: - test @@ -62,25 +62,28 @@ build_wheel: build_debian: stage: build script: - - echo -n > package/debian/matemat/DEBIAN/changelog + - echo -n > package/debian/matemat/usr/share/doc/matemat/changelog - | for version in "$(cat CHANGELOG.md | grep '" | grep -B 1000 "<"'!'"-- END CHANGES ${version} -->" | tail -n +2 | head -n -1 | sed -re 's/^-/ */g' >> package/debian/matemat/DEBIAN/changelog - echo "\n -- ${PACKAGE_AUTHOR} $(date -R)\n" >> package/debian/matemat/DEBIAN/changelog + echo "matemat (${version}-1); urgency=medium\n" >> package/debian/matemat/usr/share/doc/matemat/changelog + cat CHANGELOG.md | grep -A 1000 "<"'!'"-- BEGIN CHANGES ${version} -->" | grep -B 1000 "<"'!'"-- END CHANGES ${version} -->" | tail -n +2 | head -n -1 | sed -re 's/^-/ */g' >> package/debian/matemat/usr/share/doc/matemat/changelog + echo "\n -- ${PACKAGE_AUTHOR} $(date -R)\n" >> package/debian/matemat/usr/share/doc/matemat/changelog done + - gzip -9 package/debian/matemat/usr/share/doc/matemat/changelog - cp -r static/ package/debian/matemat/usr/lib/matemat/static/ - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ - - python3.6 setup.py egg_info -d -b +master install --root=package/debian/matemat/ --prefix=/usr --optimize=1 + - python3 setup.py egg_info install --root=package/debian/matemat/ --prefix=/usr --optimize=1 - export PYTHON_BIN=$(which python3) - cd package/debian - chmod 0755 -R matemat/DEBIAN - - mv matemat/usr/lib/python3.6/{site,dist}-packages + - mv matemat/usr/lib/python3/{site,dist}-packages + - find matemat/usr/lib/python3/dist-packages -name __pycache__ -exec rm -r {} \; + - find matemat/usr/lib/python3/dist-packages -name '*.pyc' -exec rm {} \; - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin - - find . -type f -exec sed -re "s#${PYTHON_BIN}#/usr/bin/python3.6#g" -i {} \; - dpkg-deb --build matemat - mv matemat.deb "matemat_${MATEMAT_VERSION}-1_all.deb" + - lintian "matemat_${MATEMAT_VERSION}-1_all.deb" - sha256sum *.deb > SHA256SUMS artifacts: paths: diff --git a/package/debian/matemat/DEBIAN/conffiles b/package/debian/matemat/DEBIAN/conffiles new file mode 100644 index 0000000..6cda54c --- /dev/null +++ b/package/debian/matemat/DEBIAN/conffiles @@ -0,0 +1 @@ +/etc/matemat.conf diff --git a/package/debian/matemat/DEBIAN/control b/package/debian/matemat/DEBIAN/control index 6c64cfe..41f5013 100644 --- a/package/debian/matemat/DEBIAN/control +++ b/package/debian/matemat/DEBIAN/control @@ -2,10 +2,10 @@ Package: matemat Version: 0.1 Maintainer: s3lph Section: web -Priority: extra +Priority: optional Architecture: all Depends: python3 (>= 3.6), python3-jinja2, python3-magic, python3-pil -Description: A soda machine stock-keeping webservice - A web service for automated stock-keeping of a soda machine written in Python. - It provides a touch-input-friendly user interface (as most input happens through the - soda machine's touch screen). +Description: Soda machine stock-keeping webservice + A web service for automated stock-keeping of a soda machine written in Python. + It provides a touch-input-friendly user interface (as most input happens + through the soda machine's touch screen). diff --git a/package/debian/matemat/usr/lib/systemd/system/matemat.service b/package/debian/matemat/lib/systemd/system/matemat.service similarity index 100% rename from package/debian/matemat/usr/lib/systemd/system/matemat.service rename to package/debian/matemat/lib/systemd/system/matemat.service diff --git a/package/debian/matemat/DEBIAN/copyright b/package/debian/matemat/usr/share/doc/matemat/copyright similarity index 100% rename from package/debian/matemat/DEBIAN/copyright rename to package/debian/matemat/usr/share/doc/matemat/copyright diff --git a/testing/Dockerfile b/testing/Dockerfile index 6b9cfab..5d93d45 100644 --- a/testing/Dockerfile +++ b/testing/Dockerfile @@ -8,7 +8,7 @@ RUN sed -re 's/stretch/buster/g' -i /etc/apt/sources.list \ && chown matemat:matemat -R /var/matemat/db \ && chown matemat:matemat -R /var/matemat/upload \ && apt-get update -qy \ - && apt-get install -y --no-install-recommends file sudo openssh-client git docker.io build-essential \ + && apt-get install -y --no-install-recommends file sudo openssh-client git docker.io build-essential lintian \ && python3.6 -m pip install coverage wheel pycodestyle mypy \ && rm -rf /var/lib/apt/lists/* From 4e22bfb821d8dea460fe6d70efadec24ebabaeaa Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 7 Nov 2018 14:57:34 +0100 Subject: [PATCH 38/59] Disabled building docker and wheel packages on the deployment branch --- .gitlab-ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a2557e7..9e78b06 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,9 +40,7 @@ build_docker: - docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_REF_NAME" - if [[ -n "$CI_COMMIT_TAG" ]]; then docker push "registry.gitlab.com/s3lph/matemat:$CI_COMMIT_TAG"; fi only: - - 27-deployment - staging - - master - tags build_wheel: @@ -56,7 +54,6 @@ build_wheel: - "dist/*.whl" - dist/SHA256SUMS only: - - 27-deployment - tags build_debian: From 647076150df9e8c404b196e59c9095e74c8cec09 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 7 Nov 2018 14:59:45 +0100 Subject: [PATCH 39/59] (Hopefully) fixed site-packages path in dpkg script --- .gitlab-ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9e78b06..8d4bc24 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -69,11 +69,10 @@ build_debian: - gzip -9 package/debian/matemat/usr/share/doc/matemat/changelog - cp -r static/ package/debian/matemat/usr/lib/matemat/static/ - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ - - python3 setup.py egg_info install --root=package/debian/matemat/ --prefix=/usr --optimize=1 - - export PYTHON_BIN=$(which python3) + - python3.6 setup.py egg_info install --root=package/debian/matemat/ --prefix=/usr --optimize=1 - cd package/debian - chmod 0755 -R matemat/DEBIAN - - mv matemat/usr/lib/python3/{site,dist}-packages + - mv matemat/usr/lib/python3.6/site-packages matemat/usr/lib/python3/dist-packages - find matemat/usr/lib/python3/dist-packages -name __pycache__ -exec rm -r {} \; - find matemat/usr/lib/python3/dist-packages -name '*.pyc' -exec rm {} \; - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat From 2a03857520c1f6e192357ddeafde527ea55e9930 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 7 Nov 2018 15:04:11 +0100 Subject: [PATCH 40/59] (Hopefully) fixed site-packages path in dpkg script, v2 --- .gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8d4bc24..2c09052 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -72,7 +72,9 @@ build_debian: - python3.6 setup.py egg_info install --root=package/debian/matemat/ --prefix=/usr --optimize=1 - cd package/debian - chmod 0755 -R matemat/DEBIAN - - mv matemat/usr/lib/python3.6/site-packages matemat/usr/lib/python3/dist-packages + - mkdir -p matemat/usr/lib/python3/dist-packages/ + - rsync -a matemat/usr/lib/python3.6/site-packages/ matemat/usr/lib/python3/dist-packages/ + - rm -rf matemat/usr/lib/python3.6/ - find matemat/usr/lib/python3/dist-packages -name __pycache__ -exec rm -r {} \; - find matemat/usr/lib/python3/dist-packages -name '*.pyc' -exec rm {} \; - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat From 75ec39852d3e42eb84fe0545a0232476de6d0d2d Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 7 Nov 2018 15:09:45 +0100 Subject: [PATCH 41/59] Added rsync to testing docker image --- .gitlab-ci.yml | 2 +- testing/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2c09052..0b60fac 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ --- -image: s3lph/matemat-ci:20181107-01 +image: s3lph/matemat-ci:20181107-02 stages: - test diff --git a/testing/Dockerfile b/testing/Dockerfile index 5d93d45..ca8831a 100644 --- a/testing/Dockerfile +++ b/testing/Dockerfile @@ -8,7 +8,7 @@ RUN sed -re 's/stretch/buster/g' -i /etc/apt/sources.list \ && chown matemat:matemat -R /var/matemat/db \ && chown matemat:matemat -R /var/matemat/upload \ && apt-get update -qy \ - && apt-get install -y --no-install-recommends file sudo openssh-client git docker.io build-essential lintian \ + && apt-get install -y --no-install-recommends file sudo openssh-client git docker.io build-essential lintian rsync \ && python3.6 -m pip install coverage wheel pycodestyle mypy \ && rm -rf /var/lib/apt/lists/* From 0d88e683f6eee458e1799e669777bc00d374cab5 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 7 Nov 2018 15:15:52 +0100 Subject: [PATCH 42/59] Ignore "failure" of find for removal of __pycache__ directories --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0b60fac..bc4cba3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -75,7 +75,7 @@ build_debian: - mkdir -p matemat/usr/lib/python3/dist-packages/ - rsync -a matemat/usr/lib/python3.6/site-packages/ matemat/usr/lib/python3/dist-packages/ - rm -rf matemat/usr/lib/python3.6/ - - find matemat/usr/lib/python3/dist-packages -name __pycache__ -exec rm -r {} \; + - find matemat/usr/lib/python3/dist-packages -name __pycache__ -exec rm -r {} \; 2>/dev/null || true - find matemat/usr/lib/python3/dist-packages -name '*.pyc' -exec rm {} \; - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin From 21e56c9558a0db6f03993330907b1d5dd76c6bec Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 11 Nov 2018 22:31:11 +0100 Subject: [PATCH 43/59] Attempting to satisfy lintian --- .gitlab-ci.yml | 7 +++++-- package/debian/matemat/DEBIAN/compat | 1 - package/debian/matemat/DEBIAN/matemat.links | 1 - package/debian/matemat/DEBIAN/postinst | 1 + package/debian/matemat/DEBIAN/rules | 3 --- 5 files changed, 6 insertions(+), 7 deletions(-) delete mode 100644 package/debian/matemat/DEBIAN/compat delete mode 100644 package/debian/matemat/DEBIAN/matemat.links delete mode 100755 package/debian/matemat/DEBIAN/rules diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bc4cba3..82536aa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -71,7 +71,10 @@ build_debian: - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ - python3.6 setup.py egg_info install --root=package/debian/matemat/ --prefix=/usr --optimize=1 - cd package/debian - - chmod 0755 -R matemat/DEBIAN + - sed -re 's$#!/usr/local/bin/python3.6$#!/usr/bin/python3.6$' -i matemat/usr/lib/matemat/matemat + - find matemat -type f -exec chmod 0644 {} \; + - find matemat -type d -exec chmod 755 {} \; + - chmod +x matemat/usr/lib/matemat/matemat - mkdir -p matemat/usr/lib/python3/dist-packages/ - rsync -a matemat/usr/lib/python3.6/site-packages/ matemat/usr/lib/python3/dist-packages/ - rm -rf matemat/usr/lib/python3.6/ @@ -81,7 +84,7 @@ build_debian: - rm -rf matemat/usr/bin - dpkg-deb --build matemat - mv matemat.deb "matemat_${MATEMAT_VERSION}-1_all.deb" - - lintian "matemat_${MATEMAT_VERSION}-1_all.deb" + - sudo -u nobody lintian "matemat_${MATEMAT_VERSION}-1_all.deb" - sha256sum *.deb > SHA256SUMS artifacts: paths: diff --git a/package/debian/matemat/DEBIAN/compat b/package/debian/matemat/DEBIAN/compat deleted file mode 100644 index 9a03714..0000000 --- a/package/debian/matemat/DEBIAN/compat +++ /dev/null @@ -1 +0,0 @@ -10 \ No newline at end of file diff --git a/package/debian/matemat/DEBIAN/matemat.links b/package/debian/matemat/DEBIAN/matemat.links deleted file mode 100644 index e789bc0..0000000 --- a/package/debian/matemat/DEBIAN/matemat.links +++ /dev/null @@ -1 +0,0 @@ -/usr/lib/matemat/static/upload /var/lib/matemat/upload \ No newline at end of file diff --git a/package/debian/matemat/DEBIAN/postinst b/package/debian/matemat/DEBIAN/postinst index f18f7fb..28448bc 100755 --- a/package/debian/matemat/DEBIAN/postinst +++ b/package/debian/matemat/DEBIAN/postinst @@ -15,6 +15,7 @@ if [[ "$1" == "configure" ]]; then chown matemat:matemat -R /var/lib/matemat find /var/lib/matemat -type d -exec chmod 0750 {} \; find /var/lib/matemat -type f -exec chmod 0640 {} \; + ln -sf /var/lib/matemat/upload /usr/lib/matemat/static/upload systemctl daemon-reload diff --git a/package/debian/matemat/DEBIAN/rules b/package/debian/matemat/DEBIAN/rules deleted file mode 100755 index cbe925d..0000000 --- a/package/debian/matemat/DEBIAN/rules +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/make -f -%: - dh $@ From f971c65eef850f27bfaf66518039a292d8c83e66 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 11 Nov 2018 22:35:09 +0100 Subject: [PATCH 44/59] Fixed CI debian command order --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 82536aa..9f9f39f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -71,10 +71,6 @@ build_debian: - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ - python3.6 setup.py egg_info install --root=package/debian/matemat/ --prefix=/usr --optimize=1 - cd package/debian - - sed -re 's$#!/usr/local/bin/python3.6$#!/usr/bin/python3.6$' -i matemat/usr/lib/matemat/matemat - - find matemat -type f -exec chmod 0644 {} \; - - find matemat -type d -exec chmod 755 {} \; - - chmod +x matemat/usr/lib/matemat/matemat - mkdir -p matemat/usr/lib/python3/dist-packages/ - rsync -a matemat/usr/lib/python3.6/site-packages/ matemat/usr/lib/python3/dist-packages/ - rm -rf matemat/usr/lib/python3.6/ @@ -82,6 +78,10 @@ build_debian: - find matemat/usr/lib/python3/dist-packages -name '*.pyc' -exec rm {} \; - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin + - sed -re 's$#!/usr/local/bin/python3.6$#!/usr/bin/python3.6$' -i matemat/usr/lib/matemat/matemat + - find matemat -type f -exec chmod 0644 {} \; + - find matemat -type d -exec chmod 755 {} \; + - chmod +x matemat/usr/lib/matemat/matemat - dpkg-deb --build matemat - mv matemat.deb "matemat_${MATEMAT_VERSION}-1_all.deb" - sudo -u nobody lintian "matemat_${MATEMAT_VERSION}-1_all.deb" From 99c27eaeeb33d2bbb834f3baf5fa008cc72c6528 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 11 Nov 2018 22:37:55 +0100 Subject: [PATCH 45/59] Fixed debian package scripts permissions --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9f9f39f..cbde8a0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -81,7 +81,7 @@ build_debian: - sed -re 's$#!/usr/local/bin/python3.6$#!/usr/bin/python3.6$' -i matemat/usr/lib/matemat/matemat - find matemat -type f -exec chmod 0644 {} \; - find matemat -type d -exec chmod 755 {} \; - - chmod +x matemat/usr/lib/matemat/matemat + - chmod +x matemat/usr/lib/matemat/matemat matemat/DEBIAN/postinst matemat/DEBIAN/prerm matemat/DEBIAN/postrm - dpkg-deb --build matemat - mv matemat.deb "matemat_${MATEMAT_VERSION}-1_all.deb" - sudo -u nobody lintian "matemat_${MATEMAT_VERSION}-1_all.deb" From df4d397a1f579dbd35d33c11dda69baba8cb670f Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 11 Nov 2018 22:41:23 +0100 Subject: [PATCH 46/59] Does this make lintian happy? --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cbde8a0..a6aaf93 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -78,7 +78,7 @@ build_debian: - find matemat/usr/lib/python3/dist-packages -name '*.pyc' -exec rm {} \; - mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat - rm -rf matemat/usr/bin - - sed -re 's$#!/usr/local/bin/python3.6$#!/usr/bin/python3.6$' -i matemat/usr/lib/matemat/matemat + - sed -re 's$#!/usr/local/bin/python3.6$#!/usr/bin/python3$' -i matemat/usr/lib/matemat/matemat - find matemat -type f -exec chmod 0644 {} \; - find matemat -type d -exec chmod 755 {} \; - chmod +x matemat/usr/lib/matemat/matemat matemat/DEBIAN/postinst matemat/DEBIAN/prerm matemat/DEBIAN/postrm From 256532e82d1b399672a8a7e5b5915ec826ce3e3e Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 11 Nov 2018 23:13:20 +0100 Subject: [PATCH 47/59] Took care of some more lintian warnings --- .gitlab-ci.yml | 2 +- package/debian/matemat/DEBIAN/postinst | 5 ++--- package/debian/matemat/DEBIAN/prerm | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a6aaf93..3de276f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -66,7 +66,7 @@ build_debian: cat CHANGELOG.md | grep -A 1000 "<"'!'"-- BEGIN CHANGES ${version} -->" | grep -B 1000 "<"'!'"-- END CHANGES ${version} -->" | tail -n +2 | head -n -1 | sed -re 's/^-/ */g' >> package/debian/matemat/usr/share/doc/matemat/changelog echo "\n -- ${PACKAGE_AUTHOR} $(date -R)\n" >> package/debian/matemat/usr/share/doc/matemat/changelog done - - gzip -9 package/debian/matemat/usr/share/doc/matemat/changelog + - gzip -9n package/debian/matemat/usr/share/doc/matemat/changelog - cp -r static/ package/debian/matemat/usr/lib/matemat/static/ - cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/ - python3.6 setup.py egg_info install --root=package/debian/matemat/ --prefix=/usr --optimize=1 diff --git a/package/debian/matemat/DEBIAN/postinst b/package/debian/matemat/DEBIAN/postinst index 28448bc..bf2db9f 100755 --- a/package/debian/matemat/DEBIAN/postinst +++ b/package/debian/matemat/DEBIAN/postinst @@ -12,9 +12,8 @@ if [[ "$1" == "configure" ]]; then useradd --system --create-home --gid matemat --home-dir /var/lib/matemat --shell /usr/sbin/nologin matemat fi - chown matemat:matemat -R /var/lib/matemat - find /var/lib/matemat -type d -exec chmod 0750 {} \; - find /var/lib/matemat -type f -exec chmod 0640 {} \; + chown matemat:matemat /var/lib/matemat + chmod 0750 /var/lib/matemat ln -sf /var/lib/matemat/upload /usr/lib/matemat/static/upload systemctl daemon-reload diff --git a/package/debian/matemat/DEBIAN/prerm b/package/debian/matemat/DEBIAN/prerm index 657a1fc..85ae20e 100755 --- a/package/debian/matemat/DEBIAN/prerm +++ b/package/debian/matemat/DEBIAN/prerm @@ -4,7 +4,6 @@ set -e if [[ "$1" == "remove" ]]; then - systemctl stop matemat.service userdel matemat fi From 17ab6d80cd327c7bd3177c1b4b3f4e9fca10fb85 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 11 Nov 2018 23:22:00 +0100 Subject: [PATCH 48/59] Fixed failing postinst/postrm script on systems without systemd --- package/debian/matemat/DEBIAN/postinst | 2 +- package/debian/matemat/DEBIAN/postrm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package/debian/matemat/DEBIAN/postinst b/package/debian/matemat/DEBIAN/postinst index bf2db9f..f2b9ccc 100755 --- a/package/debian/matemat/DEBIAN/postinst +++ b/package/debian/matemat/DEBIAN/postinst @@ -16,6 +16,6 @@ if [[ "$1" == "configure" ]]; then chmod 0750 /var/lib/matemat ln -sf /var/lib/matemat/upload /usr/lib/matemat/static/upload - systemctl daemon-reload + systemctl daemon-reload || true fi diff --git a/package/debian/matemat/DEBIAN/postrm b/package/debian/matemat/DEBIAN/postrm index 0a1c224..305068d 100755 --- a/package/debian/matemat/DEBIAN/postrm +++ b/package/debian/matemat/DEBIAN/postrm @@ -4,6 +4,6 @@ set -e if [[ "$1" == "remove" ]]; then - systemctl daemon-reload + systemctl daemon-reload || true fi From 4d9a6add4674f7dde36bc4b7678a05a80f3c43c6 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 11 Nov 2018 23:37:12 +0100 Subject: [PATCH 49/59] Fixed a debian python dependency name --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3de276f..f191377 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,6 +59,8 @@ build_wheel: build_debian: stage: build script: + # The Python package name provided by the python3-magic Debian package is "python-magic" rather than "file-magic". + - sed -re 's/file-magic/python-magic/' -i setup.py - echo -n > package/debian/matemat/usr/share/doc/matemat/changelog - | for version in "$(cat CHANGELOG.md | grep ' -## Version 0.1 - -This is only a test for the release CI task - please ignore. - -The packages attached to this release have not been tested. - -### Changes - - -- Added CI release task. -- Went back to Python 3.6 for Debian packaging. - - -