Browse Source

Initial Commit

Nathaniel van Diepen 3 years ago
parent
commit
60ab1a4d7d

+ 0 - 0
PKGBUILD


+ 0 - 0
etc/pacman-repo.d/repo.yml


+ 7 - 0
etc/pacman-repo.yml

@@ -0,0 +1,7 @@
+---
+verbosity: 3
+maxthreads: 4
+logdir: /var/log/pacman-repo.d
+truncatelogs: true
+sources:
+  - pacman-repo.d

+ 20 - 0
pacman_repo/__init__.py

@@ -0,0 +1,20 @@
+import sys
+
+from .config import BaseConfig
+from .util import term
+
+
+def main(args):
+    try:
+        config = BaseConfig(args[0] if len(args) else '/etc/pacman-repo.yml')
+        print(config)
+
+    except Exception:
+        from traceback import format_exc
+        msg = "Error encountered:\n" + format_exc().strip()
+        print(term().red(msg))
+        sys.exit(1)
+
+
+if __name__ == '__main__':
+    main(sys.argv[1:])

+ 8 - 0
pacman_repo/__main__.py

@@ -0,0 +1,8 @@
+#!/usr/bin/env python
+import sys
+
+from . import main as pacman_backup
+
+
+def main():
+    pacman_backup(sys.argv[1:])

+ 7 - 0
pacman_repo/command_line.py

@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+import pacman_backup
+import sys
+
+
+def main():
+    pacman_backup.main(sys.argv[1:])

+ 47 - 0
pacman_repo/config.py

@@ -0,0 +1,47 @@
+import yaml
+import os
+
+from .util import pushd
+
+
+class ConfigException(Exception):
+    pass
+
+
+class BaseConfig(object):
+    def __init__(self, path):
+        self.path = path
+        if not os.path.exists(path):
+            raise ConfigException("Base config file not found: {}".format(path))
+
+        with open(path) as f:
+            self._data = yaml.load(f, Loader=yaml.SafeLoader)
+
+        self.sources = []
+        with pushd(os.path.dirname(path)):
+            for source in self["sources"]:
+                self.sources.append(RepoConfig(self, source))
+
+    def __getitem__(self, name):
+        return self._data[name]
+
+    def __contains__(self, name):
+        return name in self._data
+
+
+class RepoConfig(object):
+    def __init__(self, config, path):
+        self.path = path
+        self.config = config
+
+        if not os.path.exists(path):
+            raise ConfigException("Repo config file not found: {}".format(path))
+
+        with open(path) as f:
+            self._data = yaml.load(f, Loader=yaml.SafeLoader)
+
+    def __getitem__(self, name):
+        return self._data[name]
+
+    def __contains__(self, name):
+        return name in self._data

+ 37 - 0
pacman_repo/util.py

@@ -0,0 +1,37 @@
+import contextlib
+import sys
+import os
+import platform
+
+
+def term():
+    """Get the Terminal reference to make output pretty
+
+    Returns:
+        (blessings.Terminal): Returns
+        a `blessings <https://blessings.readthedocs.io/en/latest>`_ terminal
+        instance. If running in windows and not cygwin it will return an
+        `intercessions <https://pypi.org/project/intercessions>`_ terminal
+        instance instead
+    """
+    if not hasattr(term, '_handle'):
+        if sys.platform != "cygwin" and platform.system() == 'Windows':
+            from intercessions import Terminal
+
+        else:
+            from blessings import Terminal
+
+        term._handle = Terminal()
+
+    return term._handle
+
+
[email protected]
+def pushd(newDir):
+    previousDir = os.getcwd()
+    os.chdir(newDir)
+    try:
+        yield
+
+    finally:
+        os.chdir(previousDir)

+ 4 - 0
requirements.txt

@@ -0,0 +1,4 @@
+blessings==1.7
+intercessions==1.1.6
+PyYAML==3.13
+psutil==5.7.0

+ 35 - 0
setup.py

@@ -0,0 +1,35 @@
+import setuptools
+
+with open("README.md", 'r') as f:
+    long_description = f.read()
+
+with open("requirements.txt", 'r') as f:
+    install_requires = list(f.read().splitlines())
+
+setuptools.setup(
+    name="pacman-repo",
+    version_format='{tag}.{commitcount}',
+    author="Nathaniel van Diepen",
+    author_email="[email protected]",
+    description="Configuration file based file backup",
+    long_description=long_description,
+    long_description_content_type="text/markdown",
+    url="https://eeems.codes/Eeems/pacman-repo",
+    include_package_data=True,
+    classifiers=[
+        "Programming Language :: Python :: 3",
+        "Programming Language :: Python :: 3 :: Only",
+        "License :: OSI Approved :: MIT License",
+        "Operating System :: OS Independent",
+        "Development Status :: 4 - Beta",
+        "Environment :: Console",
+        "Intended Audience :: Information Technology"
+    ],
+    entry_points={
+        'console_scripts': ['pacman_backup=pacman_backup:main'],
+    },
+    python_requires='>=3.6.9',
+    packages=setuptools.find_packages(),
+    setup_requires=['setuptools-git-version'],
+    install_requires=install_requires
+)