Merge "Add release to pkg-map"

This commit is contained in:
Jenkins 2016-06-07 01:01:09 +00:00 committed by Gerrit Code Review
commit dc149ec9fd
2 changed files with 64 additions and 8 deletions

View File

@ -16,18 +16,25 @@ Provides the following:
--element ELEMENT The element (namespace) to use for translation. --element ELEMENT The element (namespace) to use for translation.
--distro DISTRO The distro name to use for translation. Defaults to --distro DISTRO The distro name to use for translation. Defaults to
DISTRO_NAME DISTRO_NAME
--release RELEASE The release to use for translation. Defaults to
DIB_RELEASE
* Any element may create its own pkg-map JSON config file using * Any element may create its own pkg-map JSON config file using the
the one of 3 sections for the distro/family/ and or default. one of 4 sections for the release/distro/family/ and or default.
The family is set automatically within pkg-map based on The family is set automatically within pkg-map based on the
the supplied distro name. Families include: supplied distro name. Families include:
+ redhat: includes centos, fedora, and rhel distros + redhat: includes centos, fedora, and rhel distros
+ debian: includes debian and ubuntu distros + debian: includes debian and ubuntu distros
+ suse: includes the opensuse distro + suse: includes the opensuse distro
The release is a specification of distro; i.e. the distro and
release must mach for a translation.
The most specific section takes priority. The most specific section takes priority.
An empty package list can be provided. An empty package list can be provided.
Example for Nova and Glance (NOTE: using fictitious package names Example for Nova and Glance (NOTE: using fictitious package names
for Fedora and package mapping for suse family to provide a good for Fedora and package mapping for suse family to provide a good
example!) example!)
@ -35,6 +42,13 @@ Provides the following:
Example format:: Example format::
{ {
"release": {
"fedora": {
"23": {
"nova_package": "foo" "bar"
}
}
},
"distro": { "distro": {
"fedora": { "fedora": {
"nova_package": "openstack-compute", "nova_package": "openstack-compute",

View File

@ -16,7 +16,9 @@
import argparse import argparse
import json import json
import logging
import os import os
import pprint
import sys import sys
@ -46,24 +48,44 @@ def main():
" file is found. Otherwise exits with 0.") " file is found. Otherwise exits with 0.")
parser.add_argument('--element', default='', parser.add_argument('--element', default='',
help='The element (namespace) to use for translation.') help='The element (namespace) to use for translation.')
parser.add_argument('--pkg-map', default='',
help='Path to specific pkg-map file. '
'(Useful for testing)')
parser.add_argument('--distro', default=os.environ.get('DISTRO_NAME'), parser.add_argument('--distro', default=os.environ.get('DISTRO_NAME'),
help='The distro name to use for translation.' help='The distro name to use for translation.'
' Defaults to DISTRO_NAME') ' Defaults to DISTRO_NAME')
parser.add_argument('--release', default=os.environ.get('DIB_RELEASE'),
help='A more specfic name for distribution release')
parser.add_argument('--missing-ok', action="store_true", parser.add_argument('--missing-ok', action="store_true",
help='Do not consider missing mappings an error.' help='Do not consider missing mappings an error.'
' Causes packages where no mapping is set to be' ' Causes packages where no mapping is set to be'
' printed.') ' printed.')
parser.add_argument('--debug', dest='debug', action="store_true",
help="Enable debugging output")
args, extra = parser.parse_known_args() args, extra = parser.parse_known_args()
if not args.element: if args.debug:
logging.basicConfig(level=logging.DEBUG)
if not args.element and not args.pkg_map:
eprint('Please specify an --element argument.') eprint('Please specify an --element argument.')
sys.exit(1) sys.exit(1)
if args.element and args.pkg_map:
eprint('Specify either --element or --pkg-map')
sys.exit(1)
if not args.distro: if not args.distro:
eprint('Please specify a --distro argument or set DISTRO_NAME.') eprint('Please specify a --distro argument or set DISTRO_NAME.')
sys.exit(1) sys.exit(1)
if args.pkg_map:
map_file = args.pkg_map
else:
map_file = '/usr/share/pkg-map/%s' % args.element map_file = '/usr/share/pkg-map/%s' % args.element
logging.debug("Map file is %s" % map_file)
if not os.path.exists(map_file): if not os.path.exists(map_file):
if os.environ.get('DIB_DEBUG_TRACE', '0') != '0': if os.environ.get('DIB_DEBUG_TRACE', '0') != '0':
eprint('Map file for %s element does not exist.' % args.element) eprint('Map file for %s element does not exist.' % args.element)
@ -76,16 +98,29 @@ def main():
with open(map_file) as fd: with open(map_file) as fd:
try: try:
package_names = json.loads(fd.read()) package_names = json.loads(fd.read())
logging.debug(pprint.pformat(package_names))
except ValueError: except ValueError:
eprint('Unable to parse %s' % map_file) eprint('Unable to parse %s' % map_file)
raise raise
# Parse mapping data in this form using distro/family/default # Parse mapping data in this form using release/distro/family/default
# Most specific takes priority (distro is most specific). # Most specific takes priority; order is
# - release
# - distro
# - family
# - default
# An empty package list can be provided. # An empty package list can be provided.
#
# Example for Nova and Glance (using fictitious name for Fedora and SUSE # Example for Nova and Glance (using fictitious name for Fedora and SUSE
# and package mapping for SUSE family) # and package mapping for SUSE family)
# { # {
# "release": {
# "fedora" : {
# "23" : {
# "nova_package": "openstack-compute-foo"
# }
# }
# }
# "distro": { # "distro": {
# "fedora": { # "fedora": {
# "nova_package": "openstack-compute", # "nova_package": "openstack-compute",
@ -115,6 +150,13 @@ def main():
distro_map = package_names['distro'].get(args.distro) distro_map = package_names['distro'].get(args.distro)
if distro_map: if distro_map:
name_map.update(distro_map) name_map.update(distro_map)
if 'release' in package_names:
try:
# release is a sub-concept of distro
release_map = package_names['release'][args.distro][args.release]
name_map.update(release_map)
except KeyError:
pass
for name in extra: for name in extra:
pkg_name = name_map.get(name) pkg_name = name_map.get(name)