summaryrefslogtreecommitdiffstats
path: root/support/scripts/pkgutil.py
diff options
context:
space:
mode:
authorThomas De Schampheleire <thomas.de_schampheleire@nokia.com>2017-02-03 21:57:44 +0100
committerThomas Petazzoni <thomas.petazzoni@free-electrons.com>2017-02-06 12:26:55 +0100
commit12683184b1969f65680cb7db55b547a620a9860f (patch)
treee3bccd3b704b0746c535f0f14f2f4cf11583432c /support/scripts/pkgutil.py
parenta7399b257a522023c497db351e17b233fdd29f61 (diff)
downloadbuildroot-12683184b1969f65680cb7db55b547a620a9860f.tar.gz
buildroot-12683184b1969f65680cb7db55b547a620a9860f.zip
graph-depends: split off get_version/get_depends into pkgutil.py
Functions to obtain the version and dependencies of a package from Python can be useful for several scripts. Extract this logic out of graph-depends into pkgutil.py. Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr> [Thomas: remove shebang from pkgutil.py, noticed by Yann E. Morin.] Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Diffstat (limited to 'support/scripts/pkgutil.py')
-rw-r--r--support/scripts/pkgutil.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/support/scripts/pkgutil.py b/support/scripts/pkgutil.py
new file mode 100644
index 0000000000..46af4b5d38
--- /dev/null
+++ b/support/scripts/pkgutil.py
@@ -0,0 +1,53 @@
+# Copyright (C) 2010-2013 Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+
+import sys
+import subprocess
+
+# Execute the "make <pkg>-show-version" command to get the version of a given
+# list of packages, and return the version formatted as a Python dictionary.
+def get_version(pkgs):
+ sys.stderr.write("Getting version for %s\n" % pkgs)
+ cmd = ["make", "-s", "--no-print-directory" ]
+ for pkg in pkgs:
+ cmd.append("%s-show-version" % pkg)
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
+ output = p.communicate()[0]
+ if p.returncode != 0:
+ sys.stderr.write("Error getting version %s\n" % pkgs)
+ sys.exit(1)
+ output = output.split("\n")
+ if len(output) != len(pkgs) + 1:
+ sys.stderr.write("Error getting version\n")
+ sys.exit(1)
+ version = {}
+ for i in range(0, len(pkgs)):
+ pkg = pkgs[i]
+ version[pkg] = output[i]
+ return version
+
+# Execute the "make <pkg>-show-depends" command to get the list of
+# dependencies of a given list of packages, and return the list of
+# dependencies formatted as a Python dictionary.
+def get_depends(pkgs, rule):
+ sys.stderr.write("Getting dependencies for %s\n" % pkgs)
+ cmd = ["make", "-s", "--no-print-directory" ]
+ for pkg in pkgs:
+ cmd.append("%s-%s" % (pkg, rule))
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
+ output = p.communicate()[0]
+ if p.returncode != 0:
+ sys.stderr.write("Error getting dependencies %s\n" % pkgs)
+ sys.exit(1)
+ output = output.split("\n")
+ if len(output) != len(pkgs) + 1:
+ sys.stderr.write("Error getting dependencies\n")
+ sys.exit(1)
+ deps = {}
+ for i in range(0, len(pkgs)):
+ pkg = pkgs[i]
+ pkg_deps = output[i].split(" ")
+ if pkg_deps == ['']:
+ deps[pkg] = []
+ else:
+ deps[pkg] = pkg_deps
+ return deps
OpenPOWER on IntegriCloud