blob: 084d9ef6845490e5987392e9ef31cb137b925d25 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
3# OpenEmbedded opkg query helper utility
4#
5# Written by: Paul Eggleton <paul.eggleton@linux.intel.com>
6#
7# Copyright 2012 Intel Corporation
8#
Brad Bishopc342db32019-05-15 21:57:59 -04009# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010#
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
12import sys
13import fileinput
14import re
15
16archmode = False
17filemode = False
18vermode = False
19
20args = []
21for 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
Patrick Williams73bd93f2024-02-20 08:07:48 -060032verregex = re.compile(r' \([=<>]* [^ )]*\)')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033
34pkg = ""
35ver = ""
36for 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