diff options
| author | Amanda Brindle <amanda.r.brindle@intel.com> | 2018-01-18 15:18:27 -0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-01-22 10:39:09 +0000 |
| commit | 76cbeffd2f260e1d55826f499ecedef15a47b1dc (patch) | |
| tree | e96835c7f2bd6cee246acfc1dd345382d44347e6 /scripts | |
| parent | 5840ae6d136fa226de1f9cbc5d9f6f2ea22cecc7 (diff) | |
| download | poky-76cbeffd2f260e1d55826f499ecedef15a47b1dc.tar.gz | |
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>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/oe-pkgdata-util | 107 |
1 files changed, 48 insertions, 59 deletions
diff --git a/scripts/oe-pkgdata-util b/scripts/oe-pkgdata-util index c6fba56c89..e4ccf30308 100755 --- a/scripts/oe-pkgdata-util +++ b/scripts/oe-pkgdata-util | |||
| @@ -257,25 +257,22 @@ def lookup_recipe(args): | |||
| 257 | for pkgitem in args.pkg: | 257 | for pkgitem in args.pkg: |
| 258 | pkgs.extend(pkgitem.split()) | 258 | pkgs.extend(pkgitem.split()) |
| 259 | 259 | ||
| 260 | mappings = defaultdict(list) | ||
| 261 | for pkg in pkgs: | 260 | for pkg in pkgs: |
| 262 | pkgfile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg) | 261 | pkgdatafile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg) |
| 263 | if os.path.exists(pkgfile): | 262 | if os.path.exists(pkgdatafile): |
| 264 | with open(pkgfile, 'r') as f: | 263 | with open(pkgdatafile, 'r') as f: |
| 264 | found = False | ||
| 265 | for line in f: | 265 | for line in f: |
| 266 | fields = line.rstrip().split(': ') | 266 | if line.startswith('PN'): |
| 267 | if fields[0] == 'PN': | 267 | print("\t%s" % line.split(':', 1)[1].strip()) |
| 268 | mappings[pkg].append(fields[1]) | 268 | found = True |
| 269 | break | 269 | break |
| 270 | if len(mappings) < len(pkgs): | 270 | if not found: |
| 271 | missing = list(set(pkgs) - set(mappings.keys())) | 271 | logger.error("Unable to find PN entry in %s" % pkgdatafile) |
| 272 | logger.error("The following packages could not be found: %s" % ', '.join(missing)) | 272 | sys.exit(1) |
| 273 | sys.exit(1) | 273 | else: |
| 274 | 274 | logger.error("Unable to find any built runtime package named %s" % pkg) | |
| 275 | items = [] | 275 | sys.exit(1) |
| 276 | for pkg in pkgs: | ||
| 277 | items.extend(mappings.get(pkg, [])) | ||
| 278 | print('\n'.join(items)) | ||
| 279 | 276 | ||
| 280 | def package_info(args): | 277 | def package_info(args): |
| 281 | # Handle both multiple arguments and multiple values within an arg (old syntax) | 278 | # Handle both multiple arguments and multiple values within an arg (old syntax) |
| @@ -293,51 +290,43 @@ def package_info(args): | |||
| 293 | logger.error("No packages specified") | 290 | logger.error("No packages specified") |
| 294 | sys.exit(1) | 291 | sys.exit(1) |
| 295 | 292 | ||
| 296 | mappings = defaultdict(lambda: defaultdict(str)) | ||
| 297 | for pkg in packages: | 293 | for pkg in packages: |
| 298 | pkgfile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg) | 294 | pkgdatafile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg) |
| 299 | if os.path.exists(pkgfile): | 295 | if os.path.exists(pkgdatafile): |
| 300 | with open(pkgfile, 'r') as f: | 296 | with open(pkgdatafile, 'r') as f: |
| 297 | pkge = '' | ||
| 298 | pkgr = '' | ||
| 299 | pe = '' | ||
| 300 | pr = '' | ||
| 301 | for line in f: | 301 | for line in f: |
| 302 | fields = line.rstrip().split(': ') | 302 | if line.startswith('PKGV'): |
| 303 | if fields[0].endswith("_" + pkg): | 303 | pkg_version = line.split(':', 1)[1].strip() |
| 304 | k = fields[0][:len(fields[0]) - len(pkg) - 1] | 304 | elif line.startswith('PKGE'): |
| 305 | else: | 305 | pkge = line.split(':', 1)[1].strip() |
| 306 | k = fields[0] | 306 | elif line.startswith('PKGR'): |
| 307 | v = fields[1] if len(fields) == 2 else "" | 307 | pkgr = line.split(':', 1)[1].strip() |
| 308 | mappings[pkg][k] = v | 308 | elif line.startswith('PN'): |
| 309 | 309 | recipe = line.split(':', 1)[1].strip() | |
| 310 | if len(mappings) < len(packages): | 310 | elif line.startswith('PV'): |
| 311 | missing = list(set(packages) - set(mappings.keys())) | 311 | recipe_version = line.split(':', 1)[1].strip() |
| 312 | logger.error("The following packages could not be found: %s" % | 312 | elif line.startswith('PE'): |
| 313 | ', '.join(missing)) | 313 | pe = line.split(':', 1)[1].strip() |
| 314 | sys.exit(1) | 314 | elif line.startswith('PR'): |
| 315 | 315 | pr = line.split(':', 1)[1].strip() | |
| 316 | items = [] | 316 | elif line.startswith('PKGSIZE'): |
| 317 | for pkg in packages: | 317 | pkg_size = line.split(':', 1)[1].strip() |
| 318 | pkg_version = mappings[pkg]['PKGV'] | 318 | if pkge: |
| 319 | if mappings[pkg]['PKGE']: | 319 | pkg_version = pkge + ":" + pkg_version |
| 320 | pkg_version = mappings[pkg]['PKGE'] + ":" + pkg_version | 320 | if pkgr: |
| 321 | if mappings[pkg]['PKGR']: | 321 | pkg_version = pkg_version + "-" + pkgr |
| 322 | pkg_version = pkg_version + "-" + mappings[pkg]['PKGR'] | 322 | if pe: |
| 323 | recipe = mappings[pkg]['PN'] | 323 | recipe_version = pe + ":" + recipe_version |
| 324 | recipe_version = mappings[pkg]['PV'] | 324 | if pr: |
| 325 | if mappings[pkg]['PE']: | 325 | recipe_version = recipe_version + "-" + pr |
| 326 | recipe_version = mappings[pkg]['PE'] + ":" + recipe_version | 326 | print("%s %s %s %s %s" % (pkg, pkg_version, recipe, recipe_version, pkg_size)) |
| 327 | if mappings[pkg]['PR']: | 327 | else: |
| 328 | recipe_version = recipe_version + "-" + mappings[pkg]['PR'] | 328 | logger.error("Unable to find any built runtime package named %s" % pkg) |
| 329 | pkg_size = mappings[pkg]['PKGSIZE'] | 329 | sys.exit(1) |
| 330 | |||
| 331 | line = "%s %s %s %s %s" % (pkg, pkg_version, recipe, recipe_version, pkg_size) | ||
| 332 | |||
| 333 | if args.extra: | ||
| 334 | for var in args.extra: | ||
| 335 | val = mappings[pkg][var].strip() | ||
| 336 | val = re.sub(r'\s+', ' ', val) | ||
| 337 | line += ' "%s"' % val | ||
| 338 | |||
| 339 | items.append(line) | ||
| 340 | print('\n'.join(items)) | ||
| 341 | 330 | ||
| 342 | def get_recipe_pkgs(pkgdata_dir, recipe, unpackaged): | 331 | def get_recipe_pkgs(pkgdata_dir, recipe, unpackaged): |
| 343 | recipedatafile = os.path.join(pkgdata_dir, recipe) | 332 | recipedatafile = os.path.join(pkgdata_dir, recipe) |
