[oe-commits] [openembedded-core] 10/17: oe-pkgdata-util: Refactor functions for consistency

git at git.openembedded.org git at git.openembedded.org
Sun Jan 21 09:55:46 UTC 2018


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 22b651bde8bb5ff124f54461719c131d2ba8ccb2
Author: Amanda Brindle <amanda.r.brindle at intel.com>
AuthorDate: Thu Jan 18 15:18:27 2018 -0800

    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.
    
    Signed-off-by: Amanda Brindle <amanda.r.brindle at intel.com>
    Signed-off-by: Ross Burton <ross.burton at intel.com>
---
 scripts/oe-pkgdata-util | 107 ++++++++++++++++++++++--------------------------
 1 file changed, 48 insertions(+), 59 deletions(-)

diff --git a/scripts/oe-pkgdata-util b/scripts/oe-pkgdata-util
index c6fba56..e4ccf30 100755
--- a/scripts/oe-pkgdata-util
+++ b/scripts/oe-pkgdata-util
@@ -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)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list