| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
 | 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 | # SPDX-License-Identifier: GPL-2.0-only | 
 | 10 | # | 
 | 11 |  | 
 | 12 | import sys | 
 | 13 | import fileinput | 
 | 14 | import re | 
 | 15 |  | 
 | 16 | archmode = False | 
 | 17 | filemode = False | 
 | 18 | vermode = False | 
 | 19 |  | 
 | 20 | args = [] | 
 | 21 | for arg in sys.argv[1:]: | 
 | 22 |     if arg == '-a': | 
 | 23 |         archmode = True | 
 | 24 |     elif arg == '-f': | 
 | 25 |         filemode = True | 
 | 26 |     elif arg == '-v': | 
 | 27 |         vermode = True | 
 | 28 |     else: | 
 | 29 |         args.append(arg) | 
 | 30 |  | 
 | 31 | # Regex for removing version specs after dependency items | 
 | 32 | verregex = re.compile(' \([=<>]* [^ )]*\)') | 
 | 33 |  | 
 | 34 | pkg = "" | 
 | 35 | ver = "" | 
 | 36 | for line in fileinput.input(args): | 
 | 37 |     line = line.rstrip() | 
 | 38 |     if ': ' in line: | 
 | 39 |         if line.startswith("Package:"): | 
 | 40 |             pkg = line.split(": ")[1] | 
 | 41 |             ver = "" | 
 | 42 |         else: | 
 | 43 |             if archmode: | 
 | 44 |                 if line.startswith("Architecture:"): | 
 | 45 |                     arch = line.split(": ")[1] | 
 | 46 |                     print("%s %s" % (pkg,arch)) | 
 | 47 |             elif filemode: | 
 | 48 |                 if line.startswith("Version:"): | 
 | 49 |                     ver = line.split(": ")[1] | 
 | 50 |                 elif line.startswith("Architecture:"): | 
 | 51 |                     arch = line.split(": ")[1] | 
 | 52 |                     print("%s %s_%s_%s.ipk %s" % (pkg,pkg,ver,arch,arch)) | 
 | 53 |             elif vermode: | 
 | 54 |                 if line.startswith("Version:"): | 
 | 55 |                     ver = line.split(": ")[1] | 
 | 56 |                 elif line.startswith("Architecture:"): | 
 | 57 |                     arch = line.split(": ")[1] | 
 | 58 |                     print("%s %s %s" % (pkg,arch,ver)) | 
 | 59 |             else: | 
 | 60 |                 if line.startswith("Depends:"): | 
 | 61 |                     depval = line.split(": ")[1] | 
 | 62 |                     deps = depval.split(", ") | 
 | 63 |                     for dep in deps: | 
 | 64 |                         dep = verregex.sub('', dep) | 
 | 65 |                         print("%s|%s" % (pkg,dep)) | 
 | 66 |                 elif line.startswith("Recommends:"): | 
 | 67 |                     recval = line.split(": ")[1] | 
 | 68 |                     recs = recval.split(", ") | 
 | 69 |                     for rec in recs: | 
 | 70 |                         rec = verregex.sub('', rec) | 
 | 71 |                         print("%s|%s [REC]" % (pkg, rec)) | 
 | 72 |  |