brpkgutil.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (C) 2010-2013 Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  2. import logging
  3. import sys
  4. import subprocess
  5. # Execute the "make <pkg>-show-version" command to get the version of a given
  6. # list of packages, and return the version formatted as a Python dictionary.
  7. def get_version(pkgs):
  8. logging.info("Getting version for %s" % pkgs)
  9. cmd = ["make", "-s", "--no-print-directory"]
  10. for pkg in pkgs:
  11. cmd.append("%s-show-version" % pkg)
  12. p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
  13. output = p.communicate()[0]
  14. if p.returncode != 0:
  15. logging.error("Error getting version %s" % pkgs)
  16. sys.exit(1)
  17. output = output.split("\n")
  18. if len(output) != len(pkgs) + 1:
  19. logging.error("Error getting version")
  20. sys.exit(1)
  21. version = {}
  22. for i in range(0, len(pkgs)):
  23. pkg = pkgs[i]
  24. version[pkg] = output[i]
  25. return version
  26. def _get_depends(pkgs, rule):
  27. logging.info("Getting dependencies for %s" % pkgs)
  28. cmd = ["make", "-s", "--no-print-directory"]
  29. for pkg in pkgs:
  30. cmd.append("%s-%s" % (pkg, rule))
  31. p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
  32. output = p.communicate()[0]
  33. if p.returncode != 0:
  34. logging.error("Error getting dependencies %s\n" % pkgs)
  35. sys.exit(1)
  36. output = output.split("\n")
  37. if len(output) != len(pkgs) + 1:
  38. logging.error("Error getting dependencies")
  39. sys.exit(1)
  40. deps = {}
  41. for i in range(0, len(pkgs)):
  42. pkg = pkgs[i]
  43. pkg_deps = output[i].split(" ")
  44. if pkg_deps == ['']:
  45. deps[pkg] = []
  46. else:
  47. deps[pkg] = pkg_deps
  48. return deps
  49. # Execute the "make <pkg>-show-depends" command to get the list of
  50. # dependencies of a given list of packages, and return the list of
  51. # dependencies formatted as a Python dictionary.
  52. def get_depends(pkgs):
  53. return _get_depends(pkgs, 'show-depends')
  54. # Execute the "make <pkg>-show-rdepends" command to get the list of
  55. # reverse dependencies of a given list of packages, and return the
  56. # list of dependencies formatted as a Python dictionary.
  57. def get_rdepends(pkgs):
  58. return _get_depends(pkgs, 'show-rdepends')