oe-pkgdata-util: Refactor functions for consistency

Refactor functions lookup_recipe and package_info to be consistent with
list_pkg_files. Print the appropriate information as soon as it's found,
rather than storing it in a mappings variable and wait to print after
searching all packages.

(From OE-Core rev: 64d3ce83d5c48d479709b4c1355e23b3768493fb)

Signed-off-by: Amanda Brindle <amanda.r.brindle@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Amanda Brindle 2018-01-18 15:18:27 -08:00 committed by Richard Purdie
parent 5840ae6d13
commit 76cbeffd2f

View File

@ -257,25 +257,22 @@ def lookup_recipe(args):
for pkgitem in args.pkg:
pkgs.extend(pkgitem.split())
mappings = defaultdict(list)
for pkg in pkgs:
pkgfile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
if os.path.exists(pkgfile):
with open(pkgfile, 'r') as f:
pkgdatafile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
if os.path.exists(pkgdatafile):
with open(pkgdatafile, 'r') as f:
found = False
for line in f:
fields = line.rstrip().split(': ')
if fields[0] == 'PN':
mappings[pkg].append(fields[1])
if line.startswith('PN'):
print("\t%s" % line.split(':', 1)[1].strip())
found = True
break
if len(mappings) < len(pkgs):
missing = list(set(pkgs) - set(mappings.keys()))
logger.error("The following packages could not be found: %s" % ', '.join(missing))
sys.exit(1)
items = []
for pkg in pkgs:
items.extend(mappings.get(pkg, []))
print('\n'.join(items))
if not found:
logger.error("Unable to find PN entry in %s" % pkgdatafile)
sys.exit(1)
else:
logger.error("Unable to find any built runtime package named %s" % pkg)
sys.exit(1)
def package_info(args):
# Handle both multiple arguments and multiple values within an arg (old syntax)
@ -293,51 +290,43 @@ def package_info(args):
logger.error("No packages specified")
sys.exit(1)
mappings = defaultdict(lambda: defaultdict(str))
for pkg in packages:
pkgfile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
if os.path.exists(pkgfile):
with open(pkgfile, 'r') as f:
pkgdatafile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
if os.path.exists(pkgdatafile):
with open(pkgdatafile, 'r') as f:
pkge = ''
pkgr = ''
pe = ''
pr = ''
for line in f:
fields = line.rstrip().split(': ')
if fields[0].endswith("_" + pkg):
k = fields[0][:len(fields[0]) - len(pkg) - 1]
else:
k = fields[0]
v = fields[1] if len(fields) == 2 else ""
mappings[pkg][k] = v
if len(mappings) < len(packages):
missing = list(set(packages) - set(mappings.keys()))
logger.error("The following packages could not be found: %s" %
', '.join(missing))
sys.exit(1)
items = []
for pkg in packages:
pkg_version = mappings[pkg]['PKGV']
if mappings[pkg]['PKGE']:
pkg_version = mappings[pkg]['PKGE'] + ":" + pkg_version
if mappings[pkg]['PKGR']:
pkg_version = pkg_version + "-" + mappings[pkg]['PKGR']
recipe = mappings[pkg]['PN']
recipe_version = mappings[pkg]['PV']
if mappings[pkg]['PE']:
recipe_version = mappings[pkg]['PE'] + ":" + recipe_version
if mappings[pkg]['PR']:
recipe_version = recipe_version + "-" + mappings[pkg]['PR']
pkg_size = mappings[pkg]['PKGSIZE']
line = "%s %s %s %s %s" % (pkg, pkg_version, recipe, recipe_version, pkg_size)
if args.extra:
for var in args.extra:
val = mappings[pkg][var].strip()
val = re.sub(r'\s+', ' ', val)
line += ' "%s"' % val
items.append(line)
print('\n'.join(items))
if line.startswith('PKGV'):
pkg_version = line.split(':', 1)[1].strip()
elif line.startswith('PKGE'):
pkge = line.split(':', 1)[1].strip()
elif line.startswith('PKGR'):
pkgr = line.split(':', 1)[1].strip()
elif line.startswith('PN'):
recipe = line.split(':', 1)[1].strip()
elif line.startswith('PV'):
recipe_version = line.split(':', 1)[1].strip()
elif line.startswith('PE'):
pe = line.split(':', 1)[1].strip()
elif line.startswith('PR'):
pr = line.split(':', 1)[1].strip()
elif line.startswith('PKGSIZE'):
pkg_size = line.split(':', 1)[1].strip()
if pkge:
pkg_version = pkge + ":" + pkg_version
if pkgr:
pkg_version = pkg_version + "-" + pkgr
if pe:
recipe_version = pe + ":" + recipe_version
if pr:
recipe_version = recipe_version + "-" + pr
print("%s %s %s %s %s" % (pkg, pkg_version, recipe, recipe_version, pkg_size))
else:
logger.error("Unable to find any built runtime package named %s" % pkg)
sys.exit(1)
def get_recipe_pkgs(pkgdata_dir, recipe, unpackaged):
recipedatafile = os.path.join(pkgdata_dir, recipe)