From 9aef1dc341d83b89cd81deab2fc87bdcd5f730fa Mon Sep 17 00:00:00 2001 From: Eduardo Sousa Date: Wed, 20 Mar 2019 13:36:24 +0000 Subject: [PATCH] Adding setup.py to charm-generator Change-Id: I1ba69e255727703ed2f25b4f3dbabd53685573f4 Signed-off-by: Eduardo Sousa --- .../tools/charm-generator/generator-runner.py | 22 ++++++++ .../{actions => generator}/__init__.py | 0 .../charm-generator/generator/__main__.py | 21 +++++++ .../actions}/__init__.py | 0 .../actions/templates/action.j2 | 0 .../actions/templates/actions.yaml.j2 | 0 .../ansible-charm}/__init__.py | 0 .../templates/ansible_charm.py.j2 | 0 .../ansible-charm/templates/ansible_lib.py.j2 | 0 .../ansible-charm/templates/layer.yaml.j2 | 0 .../{ => generator}/generator.py | 8 +-- .../generators}/__init__.py | 0 .../generators/actions_generator.py | 2 +- .../generators/ansible_generator.py | 6 +- .../generators/metadata_generator.py | 2 +- .../generator/metadata/__init__.py | 17 ++++++ .../metadata/templates/metadata.yaml.j2 | 0 .../tools/charm-generator/requirements.txt | 2 +- .../tools/charm-generator/setup.py | 55 +++++++++++++++++++ 19 files changed, 124 insertions(+), 11 deletions(-) create mode 100644 descriptor-packages/tools/charm-generator/generator-runner.py rename descriptor-packages/tools/charm-generator/{actions => generator}/__init__.py (100%) create mode 100644 descriptor-packages/tools/charm-generator/generator/__main__.py rename descriptor-packages/tools/charm-generator/{ansible-charm => generator/actions}/__init__.py (100%) rename descriptor-packages/tools/charm-generator/{ => generator}/actions/templates/action.j2 (100%) rename descriptor-packages/tools/charm-generator/{ => generator}/actions/templates/actions.yaml.j2 (100%) rename descriptor-packages/tools/charm-generator/{generators => generator/ansible-charm}/__init__.py (100%) rename descriptor-packages/tools/charm-generator/{ => generator}/ansible-charm/templates/ansible_charm.py.j2 (100%) rename descriptor-packages/tools/charm-generator/{ => generator}/ansible-charm/templates/ansible_lib.py.j2 (100%) rename descriptor-packages/tools/charm-generator/{ => generator}/ansible-charm/templates/layer.yaml.j2 (100%) rename descriptor-packages/tools/charm-generator/{ => generator}/generator.py (98%) rename descriptor-packages/tools/charm-generator/{metadata => generator/generators}/__init__.py (100%) rename descriptor-packages/tools/charm-generator/{ => generator}/generators/actions_generator.py (98%) rename descriptor-packages/tools/charm-generator/{ => generator}/generators/ansible_generator.py (96%) rename descriptor-packages/tools/charm-generator/{ => generator}/generators/metadata_generator.py (98%) create mode 100644 descriptor-packages/tools/charm-generator/generator/metadata/__init__.py rename descriptor-packages/tools/charm-generator/{ => generator}/metadata/templates/metadata.yaml.j2 (100%) create mode 100644 descriptor-packages/tools/charm-generator/setup.py diff --git a/descriptor-packages/tools/charm-generator/generator-runner.py b/descriptor-packages/tools/charm-generator/generator-runner.py new file mode 100644 index 00000000..275156b8 --- /dev/null +++ b/descriptor-packages/tools/charm-generator/generator-runner.py @@ -0,0 +1,22 @@ +# Copyright 2019 Whitestack, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact: esousa@whitestack.com or glavado@whitestack.com +## + +from generator.generator import main + +if __name__ == '__main__': + main() diff --git a/descriptor-packages/tools/charm-generator/actions/__init__.py b/descriptor-packages/tools/charm-generator/generator/__init__.py similarity index 100% rename from descriptor-packages/tools/charm-generator/actions/__init__.py rename to descriptor-packages/tools/charm-generator/generator/__init__.py diff --git a/descriptor-packages/tools/charm-generator/generator/__main__.py b/descriptor-packages/tools/charm-generator/generator/__main__.py new file mode 100644 index 00000000..01143fbb --- /dev/null +++ b/descriptor-packages/tools/charm-generator/generator/__main__.py @@ -0,0 +1,21 @@ +# Copyright 2019 Whitestack, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact: esousa@whitestack.com or glavado@whitestack.com +## + +from .generator import main + +main() diff --git a/descriptor-packages/tools/charm-generator/ansible-charm/__init__.py b/descriptor-packages/tools/charm-generator/generator/actions/__init__.py similarity index 100% rename from descriptor-packages/tools/charm-generator/ansible-charm/__init__.py rename to descriptor-packages/tools/charm-generator/generator/actions/__init__.py diff --git a/descriptor-packages/tools/charm-generator/actions/templates/action.j2 b/descriptor-packages/tools/charm-generator/generator/actions/templates/action.j2 similarity index 100% rename from descriptor-packages/tools/charm-generator/actions/templates/action.j2 rename to descriptor-packages/tools/charm-generator/generator/actions/templates/action.j2 diff --git a/descriptor-packages/tools/charm-generator/actions/templates/actions.yaml.j2 b/descriptor-packages/tools/charm-generator/generator/actions/templates/actions.yaml.j2 similarity index 100% rename from descriptor-packages/tools/charm-generator/actions/templates/actions.yaml.j2 rename to descriptor-packages/tools/charm-generator/generator/actions/templates/actions.yaml.j2 diff --git a/descriptor-packages/tools/charm-generator/generators/__init__.py b/descriptor-packages/tools/charm-generator/generator/ansible-charm/__init__.py similarity index 100% rename from descriptor-packages/tools/charm-generator/generators/__init__.py rename to descriptor-packages/tools/charm-generator/generator/ansible-charm/__init__.py diff --git a/descriptor-packages/tools/charm-generator/ansible-charm/templates/ansible_charm.py.j2 b/descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/ansible_charm.py.j2 similarity index 100% rename from descriptor-packages/tools/charm-generator/ansible-charm/templates/ansible_charm.py.j2 rename to descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/ansible_charm.py.j2 diff --git a/descriptor-packages/tools/charm-generator/ansible-charm/templates/ansible_lib.py.j2 b/descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/ansible_lib.py.j2 similarity index 100% rename from descriptor-packages/tools/charm-generator/ansible-charm/templates/ansible_lib.py.j2 rename to descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/ansible_lib.py.j2 diff --git a/descriptor-packages/tools/charm-generator/ansible-charm/templates/layer.yaml.j2 b/descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/layer.yaml.j2 similarity index 100% rename from descriptor-packages/tools/charm-generator/ansible-charm/templates/layer.yaml.j2 rename to descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/layer.yaml.j2 diff --git a/descriptor-packages/tools/charm-generator/generator.py b/descriptor-packages/tools/charm-generator/generator/generator.py similarity index 98% rename from descriptor-packages/tools/charm-generator/generator.py rename to descriptor-packages/tools/charm-generator/generator/generator.py index 22ce1cba..0ef9d1d1 100644 --- a/descriptor-packages/tools/charm-generator/generator.py +++ b/descriptor-packages/tools/charm-generator/generator/generator.py @@ -16,13 +16,15 @@ # contact: esousa@whitestack.com or glavado@whitestack.com ## +__version__ = '1.0.0' + import argparse import logging import sys from datetime import datetime -from generators.ansible_generator import AnsibleGenerator +from .generators.ansible_generator import AnsibleGenerator def configure_logger(args): @@ -165,7 +167,3 @@ def main(): generator.generate() logger.info('Generation process complete.') - - -if __name__ == "__main__": - main() diff --git a/descriptor-packages/tools/charm-generator/metadata/__init__.py b/descriptor-packages/tools/charm-generator/generator/generators/__init__.py similarity index 100% rename from descriptor-packages/tools/charm-generator/metadata/__init__.py rename to descriptor-packages/tools/charm-generator/generator/generators/__init__.py diff --git a/descriptor-packages/tools/charm-generator/generators/actions_generator.py b/descriptor-packages/tools/charm-generator/generator/generators/actions_generator.py similarity index 98% rename from descriptor-packages/tools/charm-generator/generators/actions_generator.py rename to descriptor-packages/tools/charm-generator/generator/generators/actions_generator.py index 832fd092..b3da7c33 100644 --- a/descriptor-packages/tools/charm-generator/generators/actions_generator.py +++ b/descriptor-packages/tools/charm-generator/generator/generators/actions_generator.py @@ -26,7 +26,7 @@ from jinja2 import Environment, PackageLoader class ActionsGenerator: LOGGER = logging.getLogger() - ENV = Environment(loader=PackageLoader('actions', 'templates')) + ENV = Environment(loader=PackageLoader('generator.actions', 'templates')) def __init__(self, metadata, actions, license=None, options=None): """ diff --git a/descriptor-packages/tools/charm-generator/generators/ansible_generator.py b/descriptor-packages/tools/charm-generator/generator/generators/ansible_generator.py similarity index 96% rename from descriptor-packages/tools/charm-generator/generators/ansible_generator.py rename to descriptor-packages/tools/charm-generator/generator/generators/ansible_generator.py index 18f5a5a9..cefe4226 100644 --- a/descriptor-packages/tools/charm-generator/generators/ansible_generator.py +++ b/descriptor-packages/tools/charm-generator/generator/generators/ansible_generator.py @@ -23,13 +23,13 @@ import sys from jinja2 import Environment, PackageLoader -from generators.actions_generator import ActionsGenerator -from generators.metadata_generator import MetadataGenerator +from generator.generators.actions_generator import ActionsGenerator +from generator.generators.metadata_generator import MetadataGenerator class AnsibleGenerator: LOGGER = logging.getLogger() - ENV = Environment(loader=PackageLoader('ansible-charm', 'templates')) + ENV = Environment(loader=PackageLoader('generator.ansible-charm', 'templates')) def __init__(self, metadata, license=None, options=None): """ diff --git a/descriptor-packages/tools/charm-generator/generators/metadata_generator.py b/descriptor-packages/tools/charm-generator/generator/generators/metadata_generator.py similarity index 98% rename from descriptor-packages/tools/charm-generator/generators/metadata_generator.py rename to descriptor-packages/tools/charm-generator/generator/generators/metadata_generator.py index 8b0d9b8d..6c9b000b 100644 --- a/descriptor-packages/tools/charm-generator/generators/metadata_generator.py +++ b/descriptor-packages/tools/charm-generator/generator/generators/metadata_generator.py @@ -28,7 +28,7 @@ from jinja2 import Environment, PackageLoader class MetadataGenerator: LOGGER = logging.getLogger() - ENV = Environment(loader=PackageLoader('metadata', 'templates')) + ENV = Environment(loader=PackageLoader('generator.metadata', 'templates')) def __init__(self, metadata, license=None, options=None): """ diff --git a/descriptor-packages/tools/charm-generator/generator/metadata/__init__.py b/descriptor-packages/tools/charm-generator/generator/metadata/__init__.py new file mode 100644 index 00000000..e584ee55 --- /dev/null +++ b/descriptor-packages/tools/charm-generator/generator/metadata/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2019 Whitestack, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact: esousa@whitestack.com or glavado@whitestack.com +## diff --git a/descriptor-packages/tools/charm-generator/metadata/templates/metadata.yaml.j2 b/descriptor-packages/tools/charm-generator/generator/metadata/templates/metadata.yaml.j2 similarity index 100% rename from descriptor-packages/tools/charm-generator/metadata/templates/metadata.yaml.j2 rename to descriptor-packages/tools/charm-generator/generator/metadata/templates/metadata.yaml.j2 diff --git a/descriptor-packages/tools/charm-generator/requirements.txt b/descriptor-packages/tools/charm-generator/requirements.txt index 89ee2b0f..f0aaeda5 100644 --- a/descriptor-packages/tools/charm-generator/requirements.txt +++ b/descriptor-packages/tools/charm-generator/requirements.txt @@ -1 +1 @@ -Jinja2==2.10 +Jinja2>=2.10 diff --git a/descriptor-packages/tools/charm-generator/setup.py b/descriptor-packages/tools/charm-generator/setup.py new file mode 100644 index 00000000..5015efae --- /dev/null +++ b/descriptor-packages/tools/charm-generator/setup.py @@ -0,0 +1,55 @@ +# Copyright 2019 Whitestack, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact: esousa@whitestack.com or glavado@whitestack.com +## + +import re +import setuptools + +version = re.search( + r'^__version__\s*=\s*["\'](.*)["\']', + open('generator/generator.py').read(), + re.MULTILINE).group(1) + +with open('README.md', 'r') as f: + long_description = f.read() + +setuptools.setup( + name='osm-charm-generator', + packages=setuptools.find_packages(), + entry_points={ + "console_scripts": ['osm-charm-generator = generator.generator:main'] + }, + version=version, + author='Eduardo Sousa', + author_email='esousa@whitestack.com', + description='OSM Charm Generator using Ansible', + long_description=long_description, + long_description_content_type='text/markdown', + url='https://osm.etsi.org', + install_requires=[ + 'Jinja2>=2.10' + ], + classifiers=[ + 'Programming Language :: Python :: 3 :: Only', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: POSIX :: Linux', + 'Environment :: Console', + 'Intended Audience :: Telecommunications Industry', + 'Natural Language :: English', + 'Topic :: Software Development :: Code Generators' + ] +) -- 2.25.1