Add mapping for OpenStack project names
This patch adds a new OPENSTACK_UPSTREAM_PKG_MAP map to map PyPi names to OpenStack project names, as they are not always the same, and a --upstream command-line argument to pymod2pkg. Change-Id: I4eda55b4d7b2dcc8df28912913b876e2c40289b3
This commit is contained in:
parent
aed6f93edb
commit
58a12b93a3
|
@ -47,13 +47,17 @@ and a linux distribution name as returned by `platform.linux_distribution()[0]`:
|
|||
import pymod2pkg
|
||||
pkg = pymod2pkg.module2package('six', 'Fedora')
|
||||
|
||||
An `upstream` map is also provided, to translate python module names to
|
||||
OpenStack project names.
|
||||
|
||||
There's not much more, really, so RTFS.
|
||||
|
||||
Fixing/extending the map
|
||||
========================
|
||||
|
||||
Currently, only package maps for RPM-based systems are provided, but it'd be
|
||||
nice to have all the distros covered and it's really easy to do.
|
||||
Currently, only package maps for RPM-based systems and upstream OpenStack are
|
||||
provided, but it'd be nice to have all the distros covered and it's really
|
||||
easy to do.
|
||||
|
||||
See `*_PKG_MAP` and `get_pkg_map`, hack it to your liking and submit review by
|
||||
|
||||
|
|
|
@ -146,6 +146,13 @@ SUSE_PKG_MAP = [
|
|||
pkgfun=lambda x: x),
|
||||
]
|
||||
|
||||
OPENSTACK_UPSTREAM_PKG_MAP = [
|
||||
SingleRule('openstacksdk', 'python-openstacksdk'),
|
||||
SingleRule('gnocchiclient', 'python-gnocchiclient'),
|
||||
SingleRule('aodhclient', 'python-aodhclient'),
|
||||
SingleRule('keystoneauth1', 'keystoneauth'),
|
||||
]
|
||||
|
||||
|
||||
def get_pkg_map(dist):
|
||||
if dist.lower().find('suse') != -1:
|
||||
|
@ -176,16 +183,34 @@ def module2package(mod, dist, pkg_map=None):
|
|||
return tr_func(mod)
|
||||
|
||||
|
||||
def module2upstream(mod):
|
||||
"""Return a corresponding OpenStack upstream name for a python module.
|
||||
|
||||
mod -- python module name
|
||||
"""
|
||||
for rule in OPENSTACK_UPSTREAM_PKG_MAP:
|
||||
pkg = rule(mod, None)
|
||||
if pkg:
|
||||
return pkg
|
||||
return mod
|
||||
|
||||
|
||||
def main():
|
||||
"""for resolving names from command line"""
|
||||
parser = argparse.ArgumentParser(description='Python module name to'
|
||||
'package name')
|
||||
parser.add_argument('--dist', help='distribution style '
|
||||
'(default: %(default)s)',
|
||||
default=platform.linux_distribution()[0])
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument('--dist', help='distribution style '
|
||||
'(default: %(default)s)',
|
||||
default=platform.linux_distribution()[0])
|
||||
group.add_argument('--upstream', help='map to OpenStack project name',
|
||||
action='store_true')
|
||||
parser.add_argument('modulename', help='python module name')
|
||||
args = vars(parser.parse_args())
|
||||
print(module2package(args['modulename'], args['dist']))
|
||||
if args['upstream']:
|
||||
print(module2upstream(args['modulename']))
|
||||
else:
|
||||
print(module2package(args['modulename'], args['dist']))
|
||||
|
||||
|
||||
# for debugging to call the file directly
|
||||
|
|
9
tests.py
9
tests.py
|
@ -62,6 +62,15 @@ class Pymod2PkgTests(unittest.TestCase):
|
|||
self.assertEqual(pymod2pkg.module2package('nova', 'fedora'),
|
||||
'openstack-nova')
|
||||
|
||||
def test_default_translation_upstream(self):
|
||||
self.assertEqual(pymod2pkg.module2upstream('oslo.db'), 'oslo.db')
|
||||
self.assertEqual(pymod2pkg.module2upstream('python-glanceclient'),
|
||||
'python-glanceclient')
|
||||
self.assertEqual(pymod2pkg.module2upstream('openstacksdk'),
|
||||
'python-openstacksdk')
|
||||
self.assertNotEqual(pymod2pkg.module2upstream('keystoneauth1'),
|
||||
'keystoneauth1')
|
||||
|
||||
def test_translation_horizon_plugins(self):
|
||||
self.assertEqual(pymod2pkg.module2package('sahara-dashboard',
|
||||
'fedora'),
|
||||
|
|
Loading…
Reference in New Issue