From e19d1585cddfa62b120160a278db3ea90d8a5c28 Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Sun, 21 Mar 2021 19:29:21 +0100 Subject: [PATCH 01/11] fix PKGBUILD --- win32/PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 win32/PKGBUILD diff --git a/win32/PKGBUILD b/win32/PKGBUILD old mode 100755 new mode 100644 index be004c9..f4e5553 --- a/win32/PKGBUILD +++ b/win32/PKGBUILD @@ -13,7 +13,7 @@ depends=("${MINGW_PACKAGE_PREFIX}-python" "${MINGW_PACKAGE_PREFIX}-python-setpro "${MINGW_PACKAGE_PREFIX}-python-sqlitedict" "${MINGW_PACKAGE_PREFIX}-tdlib" ) optdepends=('youtube-dl' "${MINGW_PACKAGE_PREFIX}-trovotutto") options=('staticlibs' 'strip' '!debug') -makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools") +makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "mingw-w64-x86_64-binutils") source=('pgpgram::git+https://github.com/tallero/pgpgram.git') sha256sums=('SKIP') From f99e41f8e89536b70188b5327b52fb1a25a0fe9d Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Sun, 21 Mar 2021 19:35:15 +0100 Subject: [PATCH 02/11] test variable --- win32/PKGBUILD | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/win32/PKGBUILD b/win32/PKGBUILD index f4e5553..1e330fe 100644 --- a/win32/PKGBUILD +++ b/win32/PKGBUILD @@ -1,19 +1,21 @@ # Mantainer: Pellegrino Prevete +mpp="${MINGW_PACKAGE_PREFIX}" + _realname=pgpgram pkgbase=mingw-w64-${_realname} -pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}") +pkgname=("${mpp}-${_realname}") pkgver=0.3.1 pkgrel=1 pkgdesc='PGP encrypted backups on Telegram Cloud' arch=('any') url='https://github.com/tallero/pgpgram' license=('AGPL3') -depends=("${MINGW_PACKAGE_PREFIX}-python" "${MINGW_PACKAGE_PREFIX}-python-setproctitle" - "${MINGW_PACKAGE_PREFIX}-python-sqlitedict" "${MINGW_PACKAGE_PREFIX}-tdlib" ) -optdepends=('youtube-dl' "${MINGW_PACKAGE_PREFIX}-trovotutto") +depends=("${mpp}-python" "${mpp}-python-setproctitle" + "${mpp}-python-sqlitedict" "${mpp}-tdlib" ) +optdepends=('youtube-dl' "${mpp}-trovotutto") options=('staticlibs' 'strip' '!debug') -makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "mingw-w64-x86_64-binutils") +makedepends=("${mpp}-python-setuptools" "${mpp}-binutils") source=('pgpgram::git+https://github.com/tallero/pgpgram.git') sha256sums=('SKIP') From db482fefddd86acdcb98091df607fe1ee5b0a3a8 Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Sun, 21 Mar 2021 22:20:00 +0100 Subject: [PATCH 03/11] adding windows instructions --- win32/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32/README.md b/win32/README.md index 27784ae..1db5688 100644 --- a/win32/README.md +++ b/win32/README.md @@ -2,4 +2,4 @@ You probably need to install [`tdlib`](https://gitlab.com/tallero/tdlib-mingw) first. -Then just give `makepkg` and install with `pacman -U filename`. +Then just give `makepkg`, install dependencies with `pacman -S ` and after build install with `pacman -U `. From 296ab71b6651ad332c5a353fc97299e3523e0b50 Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Mon, 22 Mar 2021 05:22:43 -0700 Subject: [PATCH 04/11] updated PKGBUILD --- win32/PKGBUILD | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/win32/PKGBUILD b/win32/PKGBUILD index 1e330fe..261b165 100644 --- a/win32/PKGBUILD +++ b/win32/PKGBUILD @@ -1,5 +1,6 @@ # Mantainer: Pellegrino Prevete +mp="${MINGW_PREFIX}" mpp="${MINGW_PACKAGE_PREFIX}" _realname=pgpgram @@ -21,7 +22,11 @@ sha256sums=('SKIP') package() { cd "${_realname}" - python3 setup.py install --root="${pkgdir}" --optimize=1 + echo "${pkgdir}" + MSYS2_ARG_CONV_EXCL="--prefix;--install-scripts=;--install-platlib=" \ + "${mp}"/bin/python3 setup.py install --optimize=1 \ + --prefix="${mp}" \ + --root="${pkgdir}" } # vim: ts=2 sw=2 et: From e9df87ee1c007ad704de8c4ec6f90a0f35538e29 Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Tue, 23 Mar 2021 06:21:16 +0100 Subject: [PATCH 05/11] switch to appdirs from pyxdg --- pgpgram/__init__.py | 34 +++++++++++++++++++++++++--------- setup.py | 38 ++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/pgpgram/__init__.py b/pgpgram/__init__.py index ed5b3e9..41940cf 100644 --- a/pgpgram/__init__.py +++ b/pgpgram/__init__.py @@ -36,7 +36,7 @@ from os import chdir as cd from os import listdir as ls from os import remove as rm -from os import mkdir, symlink, getcwd +from os import getcwd, makedirs, mkdir, symlink, umask from os import walk from pickle import dump as pickle_dump from pickle import load as pickle_load @@ -48,23 +48,37 @@ from subprocess import check_output as sh from subprocess import getoutput +from appdirs import user_cache_dir, user_config_dir, user_data_dir from argparse import ArgumentParser from trovotutto import PGPgramDb, Index -from xdg import BaseDirectory -from .td import Td from .color import Color +from .config import Config +from .td import Td name = "pgpgram" version = "0.4" setproctitle(name) +config = Config() color = Color() + +def mkdirs(newdir, mode=0o700): + """Perche' non ci sta -p in os.mkdir""" + original_umask = umask(0) + try: + makedirs(newdir, mode) + except OSError: + pass + finally: + umask(original_umask) + + def save(variable, path): """Save variable on given path using Pickle - + Args: variable: what to save path (str): path of the output @@ -109,12 +123,12 @@ class Db: verbose (int): level of """ - config_path = BaseDirectory.save_config_path(name) - data_path = BaseDirectory.save_data_path(name) - cache_path = BaseDirectory.save_cache_path(name) + config_path = config.get_config_dir() + data_path = config.get_data_dir() + cache_path = config.get_cache_dir() executable_path = dirname(realpath(__file__)) - files_db_path = path_join(BaseDirectory.save_config_path(name), "files.db") - names_db_path = path_join(BaseDirectory.save_config_path(name), "names.db") + files_db_path = path_join(config.get_config_dir(), "files.db") + names_db_path = path_join(config.get_config_dir(), "names.db") def __init__(self, verbose=0): self.verbose = verbose @@ -167,6 +181,8 @@ def __init__(self, verbose=0): # print("index still not built") self.save() + + def from_pickle_to_db(self): files_pickle_path = path_join(self.config_path, "files.pkl") if exists(files_pickle_path): diff --git a/setup.py b/setup.py index f9bcd7d..3ffdb96 100644 --- a/setup.py +++ b/setup.py @@ -1,31 +1,33 @@ +"""Setup for PGPgram""" +from platform import system, machine from setuptools import setup, find_packages with open("README.md", "r") as fh: long_description = fh.read() setup( - name = "PGPgram", - version = "0.3.1", - author = "Pellegrino Prevete", - author_email = "pellegrinoprevete@gmail.com", - description = "GPG encrypted backups on telegram", - long_description = long_description, - long_description_content_type = "text/markdown", - url = "https://github.com/tallero/PGPgram", - packages = find_packages(), - package_data = { - '': ['libtdjson.so'], + name="PGPgram", + version="0.4", + author="Pellegrino Prevete", + author_email="pellegrinoprevete@gmail.com", + description="GPG encrypted backups on telegram", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/tallero/PGPgram", + packages=find_packages(), + package_data={ + '': ['libtdjson_{}_{}.so'.format(system(), machine())], }, - entry_points = { + entry_points={ 'console_scripts': ['pgpgram = pgpgram:main'] }, - install_requires = [ - 'pyxdg', - 'setproctitle', - 'sqlitedict', - 'trovotutto', + install_requires=[ + 'appdirs', + 'setproctitle', + 'sqlitedict', + 'trovotutto', ], - classifiers = [ + classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", "Operating System :: Unix", From a983628f74d04bf8237ce76b0fe4a98608fe0abb Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Tue, 23 Mar 2021 06:30:01 +0100 Subject: [PATCH 06/11] move pre-installed from deps --- pgpgram/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pgpgram/__init__.py b/pgpgram/__init__.py index 41940cf..e3be06d 100644 --- a/pgpgram/__init__.py +++ b/pgpgram/__init__.py @@ -42,14 +42,14 @@ from pickle import load as pickle_load from pprint import pprint from random import SystemRandom as random -from setproctitle import setproctitle -from sqlitedict import SqliteDict from subprocess import Popen, PIPE from subprocess import check_output as sh from subprocess import getoutput from appdirs import user_cache_dir, user_config_dir, user_data_dir from argparse import ArgumentParser +from setproctitle import setproctitle +from sqlitedict import SqliteDict from trovotutto import PGPgramDb, Index from .color import Color From 6ee28e35a2995a3231095b3f2f92e64345461e4a Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Mon, 22 Mar 2021 22:30:46 -0700 Subject: [PATCH 07/11] update PKGBUILD --- win32/PKGBUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win32/PKGBUILD b/win32/PKGBUILD index 261b165..787877d 100644 --- a/win32/PKGBUILD +++ b/win32/PKGBUILD @@ -6,13 +6,13 @@ mpp="${MINGW_PACKAGE_PREFIX}" _realname=pgpgram pkgbase=mingw-w64-${_realname} pkgname=("${mpp}-${_realname}") -pkgver=0.3.1 +pkgver=0.4 pkgrel=1 pkgdesc='PGP encrypted backups on Telegram Cloud' arch=('any') url='https://github.com/tallero/pgpgram' license=('AGPL3') -depends=("${mpp}-python" "${mpp}-python-setproctitle" +depends=("${mpp}-python" "${mpp}-appdirs" "${mpp}-python-setproctitle" "${mpp}-python-sqlitedict" "${mpp}-tdlib" ) optdepends=('youtube-dl' "${mpp}-trovotutto") options=('staticlibs' 'strip' '!debug') From da296669ad9485c096cc40bb570440f9427e10a6 Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Tue, 23 Mar 2021 06:39:32 +0100 Subject: [PATCH 08/11] forgot new config class file --- pgpgram/config.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 pgpgram/config.py diff --git a/pgpgram/config.py b/pgpgram/config.py new file mode 100644 index 0000000..652af30 --- /dev/null +++ b/pgpgram/config.py @@ -0,0 +1,73 @@ +# Config +# +# ---------------------------------------------------------------------- +# Copyright © 2018, 2019, 2020, 2021 Pellegrino Prevete +# +# All rights reserved +# ---------------------------------------------------------------------- +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from appdirs import user_cache_dir, user_config_dir, user_data_dir +from logging import basicConfig as set_log_config +from logging import INFO as log_level_info +from os.path import join as path_join +from os import makedirs, umask + + +def mkdirs(newdir, mode=0o700): + """Because no -p in os.mkdir""" + original_umask = umask(0) + try: + makedirs(newdir, mode) + except OSError: + pass + finally: + umask(original_umask) + + +class Config: + appname = "pgpgram" + appauthor = "Pellegrino Prevete" + + def __init__(self, + log_level=log_level_info): + self.setup_logging(log_level) + self.setup_dirs() + + def get_db_path(self, db_name: str) -> str: + return path_join(self.get_data_dir(), ".".join([db_name, 'db'])) + + def get_cache_dir(self) -> str: + return user_cache_dir(self.appname, self.appauthor) + + def get_config_dir(self) -> str: + return user_config_dir(self.appname, self.appauthor) + + def get_data_dir(self) -> str: + return user_data_dir(self.appname, self.appauthor) + + def setup_dirs(self) -> None: + mkdirs(self.get_cache_dir()) + mkdirs(self.get_config_dir()) + mkdirs(self.get_data_dir()) + + def setup_logging(self, level: int) -> None: + """Set verbose level""" + log_config_args = { + 'format': '%(asctime)s %(levelname)-8s %(message)s', + 'level': level, + 'datefmt': '%Y-%m-%d %H:%M:%S' + } + set_log_config(**log_config_args) From d94f7764ee2951c100340fe43dd7663c580b8fbc Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Mon, 22 Mar 2021 23:41:52 -0700 Subject: [PATCH 09/11] update PKGBUILD --- win32/.SRCINFO | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 win32/.SRCINFO diff --git a/win32/.SRCINFO b/win32/.SRCINFO new file mode 100644 index 0000000..9fa99a2 --- /dev/null +++ b/win32/.SRCINFO @@ -0,0 +1,24 @@ +pkgbase = mingw-w64-pgpgram + pkgdesc = PGP encrypted backups on Telegram Cloud + pkgver = 0.4 + pkgrel = 1 + url = https://github.com/tallero/pgpgram + arch = any + license = AGPL3 + makedepends = mingw-w64-x86_64-python-setuptools + makedepends = mingw-w64-x86_64-binutils + depends = mingw-w64-x86_64-python + depends = mingw-w64-x86_64-python-appdirs + depends = mingw-w64-x86_64-python-setproctitle + depends = mingw-w64-x86_64-python-sqlitedict + depends = mingw-w64-x86_64-tdlib + optdepends = youtube-dl + optdepends = mingw-w64-x86_64-trovotutto + options = staticlibs + options = strip + options = !debug + source = pgpgram::git+https://github.com/tallero/pgpgram.git#branch=win32 + sha256sums = SKIP + +pkgname = mingw-w64-x86_64-pgpgram + From 09adfc10f5261783da31e6b5430ce572f2b78ddc Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Mon, 22 Mar 2021 23:43:00 -0700 Subject: [PATCH 10/11] update PKGBUILD --- win32/PKGBUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win32/PKGBUILD b/win32/PKGBUILD index 787877d..f974c23 100644 --- a/win32/PKGBUILD +++ b/win32/PKGBUILD @@ -12,12 +12,12 @@ pkgdesc='PGP encrypted backups on Telegram Cloud' arch=('any') url='https://github.com/tallero/pgpgram' license=('AGPL3') -depends=("${mpp}-python" "${mpp}-appdirs" "${mpp}-python-setproctitle" +depends=("${mpp}-python" "${mpp}-python-appdirs" "${mpp}-python-setproctitle" "${mpp}-python-sqlitedict" "${mpp}-tdlib" ) optdepends=('youtube-dl' "${mpp}-trovotutto") options=('staticlibs' 'strip' '!debug') makedepends=("${mpp}-python-setuptools" "${mpp}-binutils") -source=('pgpgram::git+https://github.com/tallero/pgpgram.git') +source=('pgpgram::git+https://github.com/tallero/pgpgram.git#branch=win32') sha256sums=('SKIP') package() { From 71aeb1faa859fdb60d7db3f1dccfaa414bc1cf50 Mon Sep 17 00:00:00 2001 From: Pellegrino Prevete Date: Tue, 23 Mar 2021 07:48:44 +0100 Subject: [PATCH 11/11] release 0.4 --- README.md | 8 ++++++++ win32/.SRCINFO | 24 ------------------------ win32/PKGBUILD | 32 -------------------------------- win32/README.md | 5 ----- 4 files changed, 8 insertions(+), 61 deletions(-) delete mode 100644 win32/.SRCINFO delete mode 100644 win32/PKGBUILD delete mode 100644 win32/README.md diff --git a/README.md b/README.md index 032035f..8a2bb71 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,14 @@ After setting up pip, you can install *PGPgram* by simply typing in your termina # pip3 install pgpgram +### Archlinux + +The packages `pgpgram` and `pgpgram-git` have been published on [AUR](https://aur.archlinux.org). + +### MinGW (Windows) + +The package `pgpgram` has been published on [MinGW AUR](https://gitlab.com/mingw-aur). + ## Usage *PGPgram* install a command line utility with the same name, `pgpgram`, that can be used to `backup`, `restore`, and `list` files. You can invoke command line help with `pgpgram --help` and get command options with diff --git a/win32/.SRCINFO b/win32/.SRCINFO deleted file mode 100644 index 9fa99a2..0000000 --- a/win32/.SRCINFO +++ /dev/null @@ -1,24 +0,0 @@ -pkgbase = mingw-w64-pgpgram - pkgdesc = PGP encrypted backups on Telegram Cloud - pkgver = 0.4 - pkgrel = 1 - url = https://github.com/tallero/pgpgram - arch = any - license = AGPL3 - makedepends = mingw-w64-x86_64-python-setuptools - makedepends = mingw-w64-x86_64-binutils - depends = mingw-w64-x86_64-python - depends = mingw-w64-x86_64-python-appdirs - depends = mingw-w64-x86_64-python-setproctitle - depends = mingw-w64-x86_64-python-sqlitedict - depends = mingw-w64-x86_64-tdlib - optdepends = youtube-dl - optdepends = mingw-w64-x86_64-trovotutto - options = staticlibs - options = strip - options = !debug - source = pgpgram::git+https://github.com/tallero/pgpgram.git#branch=win32 - sha256sums = SKIP - -pkgname = mingw-w64-x86_64-pgpgram - diff --git a/win32/PKGBUILD b/win32/PKGBUILD deleted file mode 100644 index f974c23..0000000 --- a/win32/PKGBUILD +++ /dev/null @@ -1,32 +0,0 @@ -# Mantainer: Pellegrino Prevete - -mp="${MINGW_PREFIX}" -mpp="${MINGW_PACKAGE_PREFIX}" - -_realname=pgpgram -pkgbase=mingw-w64-${_realname} -pkgname=("${mpp}-${_realname}") -pkgver=0.4 -pkgrel=1 -pkgdesc='PGP encrypted backups on Telegram Cloud' -arch=('any') -url='https://github.com/tallero/pgpgram' -license=('AGPL3') -depends=("${mpp}-python" "${mpp}-python-appdirs" "${mpp}-python-setproctitle" - "${mpp}-python-sqlitedict" "${mpp}-tdlib" ) -optdepends=('youtube-dl' "${mpp}-trovotutto") -options=('staticlibs' 'strip' '!debug') -makedepends=("${mpp}-python-setuptools" "${mpp}-binutils") -source=('pgpgram::git+https://github.com/tallero/pgpgram.git#branch=win32') -sha256sums=('SKIP') - -package() { - cd "${_realname}" - echo "${pkgdir}" - MSYS2_ARG_CONV_EXCL="--prefix;--install-scripts=;--install-platlib=" \ - "${mp}"/bin/python3 setup.py install --optimize=1 \ - --prefix="${mp}" \ - --root="${pkgdir}" -} - -# vim: ts=2 sw=2 et: diff --git a/win32/README.md b/win32/README.md deleted file mode 100644 index 1db5688..0000000 --- a/win32/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Build as MSYS2/MinGW package - -You probably need to install [`tdlib`](https://gitlab.com/tallero/tdlib-mingw) first. - -Then just give `makepkg`, install dependencies with `pacman -S ` and after build install with `pacman -U `.