From 6a0cef52749ed17123912fef07f0d788342c1d59 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 8 Dec 2021 16:09:15 +0100 Subject: [PATCH] Adding setup.py --- setup.py | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ec5fb62 --- /dev/null +++ b/setup.py @@ -0,0 +1,195 @@ +#!/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: Modules for handling the PowerDNS API +""" +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__ = os.path.abspath(os.path.dirname(__file__)) +__base_dir__ = Path(__file__).parent.resolve() +# __bin_dir__ = os.path.join(__base_dir__, 'bin') +__bin_dir__ = __base_dir__ / 'bin' +# __lib_dir__ = os.path.join(__base_dir__, 'lib') +__lib_dir__ = __base_dir__ / 'lib' +# __module_dir__ = os.path.join(__lib_dir__, 'pp_admintools') +__module_dir__ = __lib_dir__ / 'pp_admintools' +# __init_py__ = os.path.join(__module_dir__, '__init__.py') +__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 pp_admintools + +__packet_version__ = pp_admintools.__version__ + +__packet_name__ = 'create_terraform' + +__author__ = 'Frank Brehm' +__contact__ = 'frank.brehm@pixelpark.com' +__copyright__ = '(C) 2021 Frank Brehm, Digitas Pixelpark GmbH, Berlin' +__license__ = 'LGPL3+' +__url__ = 'https://git.pixelpark.com/ppadmin/admin-tools' + +__target_scripts_dir__ = Path('usr/libexec/pixelpark') + + +__open_args__ = {} +if sys.version_info[0] >= 3: + __open_args__ = {'encoding': ENCODING, 'errors': 'surrogateescape'} + +# ----------------------------------- +def read(fname): + + content = None + + if sys.version_info[0] < 3: + with open(fname, 'r') as fh: + content = fh.read() + else: + with open(fname, 'r', **__open_args__) as fh: + content = fh.read() + + return content + + +# ----------------------------------- +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() + 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) + + # print("Found required modules: {}\n".format(pp(__requirements__))) + + +read_requirements() + +# ----------------------------------- +__scripts__ = [ + 'bin/dns-deploy-zones' +] + +# ----------------------------------- +__data_files__ = [] +__scripts__ = [] + +__data_files__.append(('etc/pixelpark', 'etc/dns-deploy-zones.ini.default')) + +for f in __script_dir__.glob('*'): + if f.is_file() and os.access(str(f), os.X_OK): + relpath = os.path.relpath(str(f), str(__base_dir__)) + __scripts__.append(relpath) +if __scripts__: + __data_files__.append(('usr/libexec/pixelpark', __scripts__)) + +# ----------------------------------- +MO_FILES = 'locale/*/LC_MESSAGES/*.mo' +PO_FILES = 'locale/*/LC_MESSAGES/*.po' + +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".format(pp(mo_files))) + return mo_files + + +# ----------------------------------- +setup( + version=__packet_version__, + long_description=read('README.md'), + scripts=__scripts__, + requires=__requirements__, + package_dir={'': 'lib'}, + package_data={ + '': create_mo_files(), + }, + data_files=__data_files__, +) + + +# ======================================================================= + +# vim: fileencoding=utf-8 filetype=python ts=4 expandtab -- 2.39.5