summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Bartosh <eduard.bartosh@intel.com>2013-08-10 19:34:14 +0300
committerEduard Bartosh <eduard.bartosh@intel.com>2013-08-12 23:55:05 -0700
commit492756142ff2cfa848898a06207777fc3cf39e85 (patch)
treef90a41fd9ac2fa1f2ae60386b0d567135d09ff35
parent8e563062e5b1c7fb32731587fb296563a4a00bae (diff)
downloadrepa-492756142ff2cfa848898a06207777fc3cf39e85.tar.gz
repa-492756142ff2cfa848898a06207777fc3cf39e85.tar.bz2
repa-492756142ff2cfa848898a06207777fc3cf39e85.zip
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 <eduard.bartosh@intel.com> Reviewed-on: https://otctools.jf.intel.com/review/5834 Tested-by: OTC Tools Tester <ed.bartosh@linux.intel.com>
-rw-r--r--packaging/repa.spec8
-rw-r--r--repa/__init__.py13
-rwxr-xr-xrepa/group.py37
-rwxr-xr-xrepa/list.py37
-rwxr-xr-xrepa/main.py49
-rw-r--r--setup.py9
6 files changed, 151 insertions, 2 deletions
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 <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
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 <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
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 <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
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 <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:]))
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']
+ }
)