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