Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | vermode = False |
| 32 | |
| 33 | args = [] |
| 34 | for arg in sys.argv[1:]: |
| 35 | if arg == '-a': |
| 36 | archmode = True |
| 37 | elif arg == '-f': |
| 38 | filemode = True |
| 39 | elif arg == '-v': |
| 40 | vermode = True |
| 41 | else: |
| 42 | args.append(arg) |
| 43 | |
| 44 | # Regex for removing version specs after dependency items |
| 45 | verregex = re.compile(' \([=<>]* [^ )]*\)') |
| 46 | |
| 47 | pkg = "" |
| 48 | ver = "" |
| 49 | for line in fileinput.input(args): |
| 50 | line = line.rstrip() |
| 51 | if ': ' in line: |
| 52 | if line.startswith("Package:"): |
| 53 | pkg = line.split(": ")[1] |
| 54 | ver = "" |
| 55 | else: |
| 56 | if archmode: |
| 57 | if line.startswith("Architecture:"): |
| 58 | arch = line.split(": ")[1] |
| 59 | print("%s %s" % (pkg,arch)) |
| 60 | elif filemode: |
| 61 | if line.startswith("Version:"): |
| 62 | ver = line.split(": ")[1] |
| 63 | elif line.startswith("Architecture:"): |
| 64 | arch = line.split(": ")[1] |
| 65 | print("%s %s_%s_%s.ipk %s" % (pkg,pkg,ver,arch,arch)) |
| 66 | elif vermode: |
| 67 | if line.startswith("Version:"): |
| 68 | ver = line.split(": ")[1] |
| 69 | elif line.startswith("Architecture:"): |
| 70 | arch = line.split(": ")[1] |
| 71 | print("%s %s %s" % (pkg,arch,ver)) |
| 72 | else: |
| 73 | if line.startswith("Depends:"): |
| 74 | depval = line.split(": ")[1] |
| 75 | deps = depval.split(", ") |
| 76 | for dep in deps: |
| 77 | dep = verregex.sub('', dep) |
| 78 | print("%s|%s" % (pkg,dep)) |
| 79 | elif line.startswith("Recommends:"): |
| 80 | recval = line.split(": ")[1] |
| 81 | recs = recval.split(", ") |
| 82 | for rec in recs: |
| 83 | rec = verregex.sub('', rec) |
| 84 | print("%s|%s [REC]" % (pkg, rec)) |
| 85 | |