summaryrefslogtreecommitdiffstats
path: root/scripts/oe-pkgdata-util
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/oe-pkgdata-util')
-rwxr-xr-xscripts/oe-pkgdata-util167
1 files changed, 167 insertions, 0 deletions
diff --git a/scripts/oe-pkgdata-util b/scripts/oe-pkgdata-util
new file mode 100755
index 0000000000..2427f10d89
--- /dev/null
+++ b/scripts/oe-pkgdata-util
@@ -0,0 +1,167 @@
1#!/usr/bin/env python
2
3# OpenEmbedded pkgdata utility
4#
5# Written by: Paul Eggleton <paul.eggleton@linux.intel.com>
6#
7# Copyright 2012 Intel Corporation
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21#
22#
23# Currently only has one function - mapping of packages to their dev/dbg/doc/locale etc.
24# counterparts ("glob" command). Could be extended in future to perform other useful querying
25# functions on the pkgdata though.
26#
27
28import sys
29import os
30import os.path
31import fnmatch
32import re
33
34def usage():
35 print("syntax: pkgdata-util glob [-d] <pkgdatadir> <vendor-os> <pkglist> \"<globs>\"");
36
37
38
39def glob(args):
40 if len(args) < 4:
41 usage()
42 sys.exit(1)
43
44 pkgdata_dir = args[0]
45 target_suffix = args[1]
46 pkglist_file = args[2]
47 globs = args[3].split()
48
49 if target_suffix.startswith("-"):
50 target_suffix = target_suffix[1:]
51
52 skipregex = re.compile("-locale-|^locale-base-|-dev$|-doc$|-dbg$|-staticdev$|^kernel-module-")
53
54 mappedpkgs = set()
55 with open(pkglist_file, 'r') as f:
56 for line in f:
57 fields = line.rstrip().split()
58 if len(fields) < 2:
59 continue
60 pkg = fields[0]
61 arch = fields[1]
62 multimach_target_sys = "%s-%s" % (arch, target_suffix)
63
64 # Skip packages for which there is no point applying globs
65 if skipregex.search(pkg):
66 if debug:
67 print("%s -> !!" % pkg)
68 continue
69
70 # Skip packages that already match the globs, so if e.g. a dev package
71 # is already installed and thus in the list, we don't process it any further
72 # Most of these will be caught by skipregex already, but just in case...
73 already = False
74 for g in globs:
75 if fnmatch.fnmatchcase(pkg, g):
76 already = True
77 break
78 if already:
79 if debug:
80 print("%s -> !" % pkg)
81 continue
82
83 # Define some functions
84 def revpkgdata(pkgn):
85 return os.path.join(pkgdata_dir, multimach_target_sys, "runtime-reverse", pkgn)
86 def fwdpkgdata(pkgn):
87 return os.path.join(pkgdata_dir, multimach_target_sys, "runtime", pkgn)
88 def readpn(pkgdata_file):
89 pn = ""
90 with open(pkgdata_file, 'r') as f:
91 for line in f:
92 if line.startswith("PN:"):
93 pn = line.split(': ')[1].rstrip()
94 return pn
95 def readrenamed(pkgdata_file):
96 renamed = ""
97 pn = os.path.basename(pkgdata_file)
98 with open(pkgdata_file, 'r') as f:
99 for line in f:
100 if line.startswith("PKG_%s:" % pn):
101 renamed = line.split(': ')[1].rstrip()
102 return renamed
103
104 # Main processing loop
105 for g in globs:
106 mappedpkg = ""
107 # First just try substitution (i.e. packagename -> packagename-dev)
108 newpkg = g.replace("*", pkg)
109 revlink = revpkgdata(newpkg)
110 if os.path.exists(revlink):
111 mappedpkg = os.path.basename(os.readlink(revlink))
112 fwdfile = fwdpkgdata(mappedpkg)
113 if os.path.exists(fwdfile):
114 mappedpkg = readrenamed(fwdfile)
115 else:
116 # That didn't work, so now get the PN, substitute that, then map in the other direction
117 revlink = revpkgdata(pkg)
118 if os.path.exists(revlink):
119 pn = readpn(revlink)
120 newpkg = g.replace("*", pn)
121 fwdfile = fwdpkgdata(newpkg)
122 if os.path.exists(fwdfile):
123 mappedpkg = readrenamed(fwdfile)
124 else:
125 # Package doesn't even exist...
126 if debug:
127 print "%s is not a valid package!" % (pkg)
128 break
129
130 if mappedpkg:
131 if debug:
132 print "%s (%s) -> %s" % (pkg, g, mappedpkg)
133 mappedpkgs.add(mappedpkg)
134 else:
135 if debug:
136 print "%s (%s) -> ?" % (pkg, g)
137
138 if debug:
139 print "------"
140
141 print("\n".join(mappedpkgs))
142
143
144
145# Too lazy to use getopt
146debug = False
147noopt = False
148args = []
149for arg in sys.argv[1:]:
150 if arg == "--":
151 noopt = True
152 else:
153 if not noopt:
154 if arg == "-d":
155 debug = True
156 continue
157 args.append(arg)
158
159if len(args) < 1:
160 usage()
161 sys.exit(1)
162
163if args[0] == "glob":
164 glob(args[1:])
165else:
166 usage()
167 sys.exit(1)