From: Richard Purdie Date: Thu, 19 Jul 2012 16:55:12 +0100 Subject: [PATCH] opkg.py: Add check_output defintion so it works on python 2.6 Signed-off-by: Richard Purdie --- opkg.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/opkg.py b/opkg.py index 84a8eb1..45a6119 100644 --- a/opkg.py +++ b/opkg.py @@ -326,10 +326,30 @@ class Package: return self.license def get_file_list_dir(self, directory): + def check_output(*popenargs, **kwargs): + """Run command with arguments and return its output as a byte string. + + Backported from Python 2.7 as it's implemented as pure python on stdlib. + + >>> check_output(['/usr/bin/python', '--version']) + Python 2.6.2 + """ + process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs) + output, unused_err = process.communicate() + retcode = process.poll() + if retcode: + cmd = kwargs.get("args") + if cmd is None: + cmd = popenargs[0] + error = subprocess.CalledProcessError(retcode, cmd) + error.output = output + raise error + return output + if not self.fn: try: cmd = "find %s -name %s | head -n 1" % (directory, self.filename) - rc = subprocess.check_output(cmd, shell=True) + rc = check_output(cmd, shell=True) if rc != "": newfn = str(rc).split()[0] # sys.stderr.write("Package '%s' with empty fn and filename is '%s' was found in '%s', updating fn\n" % (self.package, self.filename, newfn))