From e8429b7eb1de4fe2227f294eec6828020b86637c Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 24 Sep 2019 18:03:03 +0200 Subject: [PATCH] Adding setupo stuff --- .gitignore | 2 + requirements.txt | 3 - setup.cfg | 55 ++++++++++++++++ setup.py | 168 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index f26d1f9..488ca6c 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ etc/*.ini *.backup .idea .vscode +build +dist diff --git a/requirements.txt b/requirements.txt index a9d1722..87e9a98 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ pip -ansible babel PyYAML pyvmomi>=v6.5.0.2017.5-1 @@ -9,7 +8,5 @@ pytz paramiko dnspython flake8 -docker-py -pathlib setuptools git+https://git.pixelpark.com/python/python_fb_tools.git@master diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..881857a --- /dev/null +++ b/setup.cfg @@ -0,0 +1,55 @@ +[metadata] +name = create-terraform +description = A Tool for creating a terraform project based on a YAML file for provisioning virtual machines. +author = Frank Brehm +author_email = frank.brehm@pixelpark.com +url = https://git.pixelpark.com/ppadmin/create-terraform +license = LGPL3+ +platforms = posix +provides = create_terraform +classifiers = + Development Status :: 3 - Alpha + Environment :: Console + Intended Audience :: System Administrators + License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+) + Natural Language :: English + Natural Language :: German + Operating System :: POSIX :: Linux + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Topic :: System :: Systems Administration + +[options] +package_dir= + =lib + +install_requires = + requests + Babel + PyYAML + pyvmomi + six + pytz + dnspython + fb_tools + +setup_requires = + Babel + six + +packages=find: + +[options.packages.find] +where=lib + +[compile_catalog] +domain = create_terraform +directory = locale +statistics = 1 + +[pep8] + +max-line-length = 99 + +# vim: filetype=dosini diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..04fa929 --- /dev/null +++ b/setup.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +@author: Frank Brehm +@contact: frank.brehm@pixelpark.com +@license: LGPL3+ +@copyright: © 2019 Frank Brehm, Berlin +@summary: A Tool for creating a terraform project based on a YAML file for provisioning virtual machines. +""" + +import os +import sys +import re +import pprint +import datetime +import textwrap +import glob +import pathlib +import subprocess + +# Third party modules +from setuptools import setup +from setuptools.command.install import install + +# own modules: +__base_dir__ = os.path.abspath(os.path.dirname(__file__)) +__bin_dir__ = os.path.join(__base_dir__, 'bin') +__lib_dir__ = os.path.join(__base_dir__, 'lib') +__module_dir__ = os.path.join(__lib_dir__, 'cr_tf') +__init_py__ = os.path.join(__module_dir__, '__init__.py') + +PATHS = { + '__base_dir__': __base_dir__, + '__bin_dir__': __bin_dir__, + '__lib_dir__': __lib_dir__, + '__module_dir__': __module_dir__, + '__init_py__': __init_py__, +} + +# ----------------------------------- +def pp(obj): + pprinter = pprint.PrettyPrinter(indent=4) + return pprinter.pformat(obj) + +#print("Paths:\n{}".format(pp(PATHS))) + +if os.path.exists(__module_dir__) and os.path.isfile(__init_py__): + sys.path.insert(0, os.path.abspath(__lib_dir__)) + +import cr_tf + +ENCODING = "utf-8" + +__packet_version__ = cr_tf.__version__ + +__packet_name__ = 'create_terraform' + +__author__ = 'Frank Brehm' +__contact__ = 'frank.brehm@pixelpark.com' +__copyright__ = '(C) 2019 Frank Brehm, Pixelpark GmbH, Berlin' +__license__ = 'LGPL3+' +__url__ = 'https://git.pixelpark.com/ppadmin/create-terraform' + + +__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 filename.endswith('.py'): + return True + else: + return False + +# ----------------------------------- +__requirements__ = [ + 'argparse', + 'fb_tools', + 'six' +] + +# ----------------------------------- +def read_requirements(): + + req_file = os.path.join(__base_dir__, 'requirements.txt') + if not os.path.isfile(req_file): + return + + f_content = read(req_file) + 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/create-terraform' +] + +# ----------------------------------- +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 = pathlib.Path(po_path.replace('.po', '.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(), + }, +) + + +# ======================================================================= + +# vim: fileencoding=utf-8 filetype=python ts=4 expandtab -- 2.39.5