]> Frank Brehm's Git Trees - pixelpark/puppet-tools.git/commitdiff
Adding Python setup files.
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 15 Feb 2023 13:43:51 +0000 (14:43 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 15 Feb 2023 13:43:51 +0000 (14:43 +0100)
setup.cfg [new file with mode: 0644]
setup.py [new file with mode: 0644]

diff --git a/setup.cfg b/setup.cfg
new file mode 100644 (file)
index 0000000..577c4fd
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,64 @@
+[metadata]
+name = dpx_puppettools
+description = Scripts and modules for admin tasks of DPX Betriebs-Department on Puppetservers
+author = Frank Brehm
+author_email = frank.brehm@pixelpark.com
+url = https://git.pixelpark.com/ppadmin/puppet-tools
+license = GNU AGPLv3
+platforms = posix
+provides = dpx_puppettools
+classifiers =
+    Development Status :: 3 - Alpha
+    Environment :: Console
+    Intended Audience :: Developers
+    License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
+    Natural Language :: English
+    Operating System :: POSIX
+    Programming Language :: Python :: 3.6
+    Programming Language :: Python :: 3.7
+    Programming Language :: Python :: 3.8
+    Programming Language :: Python :: 3.9
+    Programming Language :: Python :: 3.10
+    Topic :: Software Development :: Libraries :: Python Modules
+
+[options]
+package_dir=
+    =lib
+
+install_requires =
+    requests
+    six
+    Babel
+    requests
+    fb_logging
+    fb_tools
+
+setup_requires =
+    requests
+    six
+    Babel
+    requests
+    fb_logging
+    fb_tools
+
+packages=find:
+
+[options.packages.find]
+where=lib
+
+[compile_catalog]
+domain = dpx_puppettools
+directory = locale
+statistics = 1
+
+[pep8]
+
+max-line-length = 99
+
+[flake8]
+
+max-line-length = 99
+max-complexity = 20
+ignore = E226,E302,E41,E402
+
+# vim: filetype=dosini
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..cd0b005
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,191 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@license: LGPL3+
+@copyright: © 2021 Frank Brehm, Digitas Pixelpark, Berlin
+@summary: cripts and modules for admin tasks of DPX Betriebs-Department on Puppetservers
+"""
+from __future__ import print_function
+
+import os
+import sys
+import re
+import pprint
+import glob
+import subprocess
+
+from pathlib import Path
+
+# Third party modules
+from setuptools import setup
+
+ENCODING = "utf-8"
+
+# own modules:
+__base_dir__ = Path(__file__).parent.resolve()
+__bin_dir__ = __base_dir__ / 'bin'
+__lib_dir__ = __base_dir__ / 'lib'
+__module_dir__ = __lib_dir__ / 'dpx_puppettools'
+__init_py__ = __module_dir__ / '__init__.py'
+__script_dir__ = __base_dir__ / 'scripts'
+
+PATHS = {
+    '__base_dir__': __base_dir__,
+    '__bin_dir__': __bin_dir__,
+    '__lib_dir__': __lib_dir__,
+    '__module_dir__': __module_dir__,
+    '__init_py__': __init_py__,
+    '__script_dir__=': __script_dir__,
+}
+
+# -----------------------------------
+def pp(obj):
+    pprinter = pprint.PrettyPrinter(indent=4)
+    return pprinter.pformat(obj)
+
+# print("Paths:\n{}".format(pp(PATHS)))
+
+
+if __module_dir__.exists() and __init_py__.is_file():
+    sys.path.insert(0, str(__lib_dir__))
+
+import dpx_puppettools
+
+__packet_version__ = dpx_puppettools.__version__
+
+__packet_name__ = 'dpx_puppettools'
+
+__author__ = 'Frank Brehm'
+__contact__ = 'frank.brehm@pixelpark.com'
+__copyright__ = '(C) 2023 Frank Brehm, Digitas Pixelpark GmbH, Berlin'
+__license__ = 'AGPLv3'
+__url__ = 'https://git.pixelpark.com/ppadmin/puppet-tools'
+
+__target_scripts_dir__ = Path('usr/libexec/dpx-puppet-tools')
+
+
+__open_args__ = {}
+if sys.version_info[0] >= 3:
+    __open_args__ = {'encoding': ENCODING, 'errors': 'surrogateescape'}
+
+# -----------------------------------
+def read(fname):
+
+    f = Path(fname)
+    return f.read_text()
+
+
+# -----------------------------------
+def is_python_file(filename):
+    if str(filename).endswith('.py'):
+        return True
+    else:
+        return False
+
+
+# -----------------------------------
+__requirements__ = [
+    'fb_tools',
+    'six'
+]
+
+
+# -----------------------------------
+def read_requirements():
+
+    req_file = __base_dir__ / 'requirements.txt'
+    if not req_file.is_file():
+        return
+
+    f_content = req_file.read_text()
+    if not f_content:
+        return
+
+    re_comment = re.compile(r'\s*#.*')
+    re_gitrepo = re.compile(r'^(git@|(git\+)?https?://)', re.IGNORECASE)
+    re_module = re.compile(r'([a-z][a-z0-9_]*[a-z0-9])', re.IGNORECASE)
+
+    for line in f_content.splitlines():
+        line = line.strip()
+        line = re_comment.sub('', line)
+        if not line:
+            continue
+        if re_gitrepo.match(line):
+            continue
+        match = re_module.search(line)
+        if not match:
+            continue
+        module = match.group(1)
+        if module not in __requirements__:
+            __requirements__.append(module)
+
+
+read_requirements()
+
+# print("Found required modules:\n" + pp(__requirements__) + '\n')
+
+# -----------------------------------
+__scripts__ = []
+for script in Path('bin').glob('*'):
+    scr = str(script)
+    if os.access(scr, os.X_OK) and not script.is_dir():
+        __scripts__.append(scr)
+
+# print("Given scripts:\n" + pp(__scripts__) + "\n")
+
+# -----------------------------------
+__data_files__ = []
+__admin_scripts__ = []
+
+# __data_files__.append(('/etc/pixelpark', ['etc/dns-deploy-zones.ini.default']))
+
+for f in __script_dir__.glob('*'):
+    if f.is_file():
+        relpath = os.path.relpath(str(f), str(__base_dir__))
+        __admin_scripts__.append(relpath)
+if __admin_scripts__:
+    __data_files__.append(('/usr/libexec/dpx-puppet-tools', __admin_scripts__))
+
+# print("Found data files:\n" + pp(__data_files__) + "\n")
+
+# -----------------------------------
+# MO_FILES = 'locale/*/LC_MESSAGES/*.mo'
+PO_FILES = 'locale/*/LC_MESSAGES/*.po'
+
+__package_data__ = {}
+
+def create_mo_files():
+    mo_files = []
+    for po_path in glob.glob(PO_FILES):
+        mo = Path(po_path.replace('.po', '.mo'))
+        # print("Compiling message catalog {p!r} -> {m!r}.".format(
+        #     p=str(po_path), m=str(mo)))
+        if not mo.exists():
+            subprocess.call(['msgfmt', '-o', str(mo), po_path])
+        mo_files.append(str(mo))
+
+    # print("Found mo files:\n" + pp(mo_files) + '\n')
+    return mo_files
+
+
+__package_data__[''] = create_mo_files()
+# print("Package_data:\n" + pp(__package_data__) + "\n")
+
+# -----------------------------------
+setup(
+    version=__packet_version__,
+    long_description=read('README.md'),
+    scripts=__scripts__,
+    requires=__requirements__,
+    package_dir={'': 'lib'},
+    package_data=__package_data__,
+    data_files=__data_files__,
+)
+
+
+# =======================================================================
+
+# vim: fileencoding=utf-8 filetype=python ts=4 expandtab