opkg-query-helper.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python
  2. # OpenEmbedded opkg query helper utility
  3. #
  4. # Written by: Paul Eggleton <paul.eggleton@linux.intel.com>
  5. #
  6. # Copyright 2012 Intel Corporation
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License version 2 as
  10. # published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. #
  22. import sys
  23. import fileinput
  24. import re
  25. archmode = False
  26. filemode = False
  27. vermode = False
  28. args = []
  29. for arg in sys.argv[1:]:
  30. if arg == '-a':
  31. archmode = True
  32. elif arg == '-f':
  33. filemode = True
  34. elif arg == '-v':
  35. vermode = True
  36. else:
  37. args.append(arg)
  38. # Regex for removing version specs after dependency items
  39. verregex = re.compile(' \([=<>]* [^ )]*\)')
  40. pkg = ""
  41. ver = ""
  42. for line in fileinput.input(args):
  43. line = line.rstrip()
  44. if ': ' in line:
  45. if line.startswith("Package:"):
  46. pkg = line.split(": ")[1]
  47. ver = ""
  48. else:
  49. if archmode:
  50. if line.startswith("Architecture:"):
  51. arch = line.split(": ")[1]
  52. print("%s %s" % (pkg,arch))
  53. elif filemode:
  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_%s.ipk %s" % (pkg,pkg,ver,arch,arch))
  59. elif vermode:
  60. if line.startswith("Version:"):
  61. ver = line.split(": ")[1]
  62. elif line.startswith("Architecture:"):
  63. arch = line.split(": ")[1]
  64. print("%s %s %s" % (pkg,arch,ver))
  65. else:
  66. if line.startswith("Depends:"):
  67. depval = line.split(": ")[1]
  68. deps = depval.split(", ")
  69. for dep in deps:
  70. dep = verregex.sub('', dep)
  71. print("%s|%s" % (pkg,dep))
  72. elif line.startswith("Recommends:"):
  73. recval = line.split(": ")[1]
  74. recs = recval.split(", ")
  75. for rec in recs:
  76. rec = verregex.sub('', rec)
  77. print("%s|%s [REC]" % (pkg, rec))