Implemented main module and plugin system
authorEd Bartosh <eduard.bartosh@intel.com>
Sat, 10 Aug 2013 16:34:14 +0000 (19:34 +0300)
committerEduard Bartosh <eduard.bartosh@intel.com>
Tue, 13 Aug 2013 06:55:05 +0000 (23:55 -0700)
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 <eduard.bartosh@intel.com>
Reviewed-on: https://otctools.jf.intel.com/review/5834
Tested-by: OTC Tools Tester <ed.bartosh@linux.intel.com>
packaging/repa.spec
repa/__init__.py [new file with mode: 0644]
repa/group.py [new file with mode: 0755]
repa/list.py [new file with mode: 0755]
repa/main.py [new file with mode: 0755]
setup.py

index 93f30fe..bea2d0a 100644 (file)
@@ -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 (file)
index 0000000..49df581
--- /dev/null
@@ -0,0 +1,13 @@
+"""
+REPA: Release Engineering Process Assistant.
+
+Copyright (C) Intel Corporation 2013
+Licence: GPL version 2
+Author: Ed Bartosh <eduard.bartosh@intel.com>
+
+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 (executable)
index 0000000..4d8140f
--- /dev/null
@@ -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 <eduard.bartosh@intel.com>
+
+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 (executable)
index 0000000..6359502
--- /dev/null
@@ -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 <eduard.bartosh@intel.com>
+
+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 (executable)
index 0000000..7dc63b8
--- /dev/null
@@ -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 <eduard.bartosh@intel.com>
+
+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:]))
index a71ae15..6c38f90 100644 (file)
--- 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']
+      }
 )