8ec0c00ae0
The "all" entry is a fallback if an entry/override for a specific version has not been specified. Change-Id: I5e57a00023cddaed691a2c701dc2e7fbd4726fe4 Closes-Bug: #1686343
83 lines
2.2 KiB
Python
83 lines
2.2 KiB
Python
# Copyright (c) 2015, MapR Technologies
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
|
|
_GROUP_VERSION_SEPARATOR = ","
|
|
_ALL_GROUP_VERSION = "all"
|
|
|
|
|
|
def _build_parser():
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("packages", help="path to the packages.json")
|
|
parser.add_argument("spec", help="path to the spec.json")
|
|
parser.add_argument("--separator", default=":",
|
|
help="separator between package name"
|
|
" and version in output")
|
|
|
|
return parser
|
|
|
|
|
|
def _load_json(path):
|
|
with open(path) as json_file:
|
|
return json.load(json_file)
|
|
|
|
|
|
def _version_matches(version, group_version):
|
|
for gv in group_version.split(_GROUP_VERSION_SEPARATOR):
|
|
if version.startswith(gv):
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
def _get_packages(version, group_spec):
|
|
for group_version in group_spec:
|
|
if _version_matches(version, group_version):
|
|
return group_spec[group_version]
|
|
|
|
return group_spec[_ALL_GROUP_VERSION]
|
|
|
|
|
|
def _get_package_versions(spec, package_groups):
|
|
return [(package, version)
|
|
for pg_name, versions in spec.items()
|
|
for version in versions
|
|
for package in _get_packages(version, package_groups[pg_name])]
|
|
|
|
|
|
parser = _build_parser()
|
|
|
|
|
|
def main(args=None):
|
|
args = parser.parse_args(args or sys.argv[1:])
|
|
|
|
spec = _load_json(args.spec)
|
|
package_groups = _load_json(args.packages)
|
|
separator = args.separator
|
|
|
|
package_versions = _get_package_versions(spec, package_groups)
|
|
package_format = "%s" + separator + "%s\n"
|
|
package_versions = map(lambda pv: package_format % pv, package_versions)
|
|
|
|
sys.stdout.writelines(package_versions)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|