From 492756142ff2cfa848898a06207777fc3cf39e85 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Sat, 10 Aug 2013 19:34:14 +0300 Subject: [PATCH] Implemented main module and plugin system 2 empty command modules are included: list and group. Their implementation will be added soon. At the moment they're just printing messages to the console. Main module looks for subcommands using setup.py entry point group 'repa_commands'. This allows to develop and distribute extra repa commands independently. Change-Id: I599a040f33d137909539020027a6a35a341ea35c Signed-off-by: Ed Bartosh Reviewed-on: https://otctools.jf.intel.com/review/5834 Tested-by: OTC Tools Tester --- packaging/repa.spec | 8 +++++++- repa/__init__.py | 13 +++++++++++++ repa/group.py | 37 +++++++++++++++++++++++++++++++++++++ repa/list.py | 37 +++++++++++++++++++++++++++++++++++++ repa/main.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 9 ++++++++- 6 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 repa/__init__.py create mode 100755 repa/group.py create mode 100755 repa/list.py create mode 100755 repa/main.py diff --git a/packaging/repa.spec b/packaging/repa.spec index 93f30fe..bea2d0a 100644 --- a/packaging/repa.spec +++ b/packaging/repa.spec @@ -14,6 +14,9 @@ Source0: %{name}_%{version}.tar.gz BuildRequires: python-setuptools +Requires: python >= 2.6 +Requires: python-setuptools + %description This tool is to assist release engineers to operate with submissions in easy and flexible manner @@ -33,6 +36,9 @@ rm -rf %{buildroot} %files %defattr(-,root,root,-) %{_prefix}/share/doc/packages/%{name} -%{python_sitelib}/%{name}*egg-info +%{python_sitelib}/%{name}-%{version}-*.egg-info +%{python_sitelib}/%{name}-%{version}-*-nspkg.pth +%{python_sitelib}/%{name} +%{_bindir}/%{name} %changelog diff --git a/repa/__init__.py b/repa/__init__.py new file mode 100644 index 0000000..49df581 --- /dev/null +++ b/repa/__init__.py @@ -0,0 +1,13 @@ +""" +REPA: Release Engineering Process Assistant. + +Copyright (C) Intel Corporation 2013 +Licence: GPL version 2 +Author: Ed Bartosh + +Init. +Namespace declaration. +""" + +import pkg_resources +pkg_resources.declare_namespace(__name__) diff --git a/repa/group.py b/repa/group.py new file mode 100755 index 0000000..4d8140f --- /dev/null +++ b/repa/group.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +""" +REPA: Release Engineering Process Assistant. + +Copyright (C) Intel Corporation 2013 +Licence: GPL version 2 +Author: Ed Bartosh + +Group module. +Group submissions. +""" + +import sys + +from repa.main import sub_main + +class Group(object): + """Subcommand: Manage group submissions.""" + + name = 'group' + description = 'Group submissions' + help = description + + @staticmethod + def add_arguments(parser): + """Adds arguments to the parser. Called from [sub_]main.""" + parser.add_argument('--comment', help='comment') + + def run(self, argv): + """Command line entry point. Called from [sub_]main.""" + print '%s: Not implemented yet' % self.help + print 'comment=%s' % argv.comment + + +if __name__ == '__main__': + sys.exit(sub_main(sys.argv[1:], Group())) diff --git a/repa/list.py b/repa/list.py new file mode 100755 index 0000000..6359502 --- /dev/null +++ b/repa/list.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +""" +REPA: Release Engineering Process Assistant. + +Copyright (C) Intel Corporation 2013 +Licence: GPL version 2 +Author: Ed Bartosh + +List module. +Get list of submissions. +""" + +import sys + +from repa.main import sub_main + +class List(object): + """Subcommand: List submissions.""" + + name = 'list' + description = 'List submissions' + help = description + + @staticmethod + def add_arguments(parser): + """Adds arguments to the parser. Called from [sub_]main.""" + parser.add_argument('-regexp', default='.*', help='search regexp') + + def run(self, argv): + """Command line entry point. Called from [sub_]main""" + print '%s: Not implemented yet' % self.help + print 'regexp=%s' % argv.regexp + + +if __name__ == '__main__': + sys.exit(sub_main(sys.argv[1:], List())) diff --git a/repa/main.py b/repa/main.py new file mode 100755 index 0000000..7dc63b8 --- /dev/null +++ b/repa/main.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +""" +REPA: Release Engineering Process Assistant. + +Copyright (C) Intel Corporation 2013 +Licence: GPL version 2 +Author: Ed Bartosh + +Main module. +Command line parsing, script entry point. +""" + +import sys +import pkg_resources + +from argparse import ArgumentParser + +def parse_args(argv): + """Command line parsing.""" + parser = ArgumentParser(description='Release Engineering Process Assistant') + + # Define subcommands using setup.py entry points + subparsers = parser.add_subparsers(help='sub-command help') + for entry in pkg_resources.iter_entry_points(group='repa_commands'): + cmd = entry.load()() + parser_cmd = subparsers.add_parser(cmd.name, + description=cmd.description, + help=cmd.help) + if hasattr(cmd, 'add_arguments'): + cmd.add_arguments(parser_cmd) + parser_cmd.set_defaults(func=cmd.run) + + return parser.parse_args(argv) + +def sub_main(argv, cmd): + """Subcommand entry point.""" + parser = ArgumentParser(description=cmd.description) + cmd.add_arguments(parser) + return cmd.run(parser.parse_args(argv)) + +def main(argv=sys.argv[1:]): + """Command line entry point.""" + args = parse_args(argv) + return args.func(args) + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/setup.py b/setup.py index a71ae15..6c38f90 100644 --- a/setup.py +++ b/setup.py @@ -16,5 +16,12 @@ setup(name = "repa", version = '0.0.1', author = 'Ed Bartosh', author_email = 'eduard.bartosh@intel.com', - data_files = [('/usr/share/doc/packages/repa/', ['README']),] + packages = ['repa'], + namespace_packages = ['repa'], + data_files = [('share/doc/packages/repa/', ['README']),], + entry_points = { + 'console_scripts': ['repa = repa.main:main'], + 'repa_commands': ['list = repa.list:List', + 'group = repa.group:Group'] + } ) -- 2.7.4