Skip to content

Commit

Permalink
Merge pull request #3 from tallero/win32
Browse files Browse the repository at this point in the history
Add Windows support
  • Loading branch information
tallero authored Mar 23, 2021
2 parents d031240 + 71aeb1f commit d38cf7d
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 59 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 27 additions & 11 deletions pgpgram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,49 @@
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
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 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
73 changes: 73 additions & 0 deletions pgpgram/config.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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)
38 changes: 20 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
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="[email protected]",
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",
Expand Down
25 changes: 0 additions & 25 deletions win32/PKGBUILD

This file was deleted.

5 changes: 0 additions & 5 deletions win32/README.md

This file was deleted.

0 comments on commit d38cf7d

Please sign in to comment.