diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/oe-pkgdata-util | 167 | ||||
-rwxr-xr-x | scripts/opkg-query-helper.py | 76 |
2 files changed, 243 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 | |||
28 | import sys | ||
29 | import os | ||
30 | import os.path | ||
31 | import fnmatch | ||
32 | import re | ||
33 | |||
34 | def usage(): | ||
35 | print("syntax: pkgdata-util glob [-d] <pkgdatadir> <vendor-os> <pkglist> \"<globs>\""); | ||
36 | |||
37 | |||
38 | |||
39 | def 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 | ||
146 | debug = False | ||
147 | noopt = False | ||
148 | args = [] | ||
149 | for 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 | |||
159 | if len(args) < 1: | ||
160 | usage() | ||
161 | sys.exit(1) | ||
162 | |||
163 | if args[0] == "glob": | ||
164 | glob(args[1:]) | ||
165 | else: | ||
166 | usage() | ||
167 | sys.exit(1) | ||
diff --git a/scripts/opkg-query-helper.py b/scripts/opkg-query-helper.py new file mode 100755 index 0000000000..b52284b325 --- /dev/null +++ b/scripts/opkg-query-helper.py | |||
@@ -0,0 +1,76 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | # OpenEmbedded opkg query helper 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 | |||
24 | |||
25 | import sys | ||
26 | import fileinput | ||
27 | import re | ||
28 | |||
29 | archmode = False | ||
30 | filemode = False | ||
31 | |||
32 | args = [] | ||
33 | for arg in sys.argv[1:]: | ||
34 | if arg == '-a': | ||
35 | archmode = True | ||
36 | elif arg == '-f': | ||
37 | filemode = True | ||
38 | else: | ||
39 | args.append(arg) | ||
40 | |||
41 | # Regex for removing version specs after dependency items | ||
42 | verregex = re.compile(' \([=<>]* [^ )]*\)') | ||
43 | |||
44 | pkg = "" | ||
45 | ver = "" | ||
46 | for line in fileinput.input(args): | ||
47 | line = line.rstrip() | ||
48 | if ': ' in line: | ||
49 | if line.startswith("Package:"): | ||
50 | pkg = line.split(": ")[1] | ||
51 | ver = "" | ||
52 | else: | ||
53 | if archmode: | ||
54 | if line.startswith("Architecture:"): | ||
55 | arch = line.split(": ")[1] | ||
56 | print("%s %s" % (pkg,arch)) | ||
57 | elif filemode: | ||
58 | if line.startswith("Version:"): | ||
59 | ver = line.split(": ")[1] | ||
60 | elif line.startswith("Architecture:"): | ||
61 | arch = line.split(": ")[1] | ||
62 | print("%s %s_%s_%s.ipk" % (pkg,pkg,ver,arch)) | ||
63 | else: | ||
64 | if line.startswith("Depends:"): | ||
65 | depval = line.split(": ")[1] | ||
66 | deps = depval.split(", ") | ||
67 | for dep in deps: | ||
68 | dep = verregex.sub('', dep) | ||
69 | print("%s|%s" % (pkg,dep)) | ||
70 | elif line.startswith("Recommends:"): | ||
71 | recval = line.split(": ")[1] | ||
72 | recs = recval.split(", ") | ||
73 | for rec in recs: | ||
74 | rec = verregex.sub('', rec) | ||
75 | print("%s|%s [REC]" % (pkg, rec)) | ||
76 | |||