aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo/log.py
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageialinux-online.org>2016-02-15 23:10:29 +0100
committerPapoteur <papoteur@mageialinux-online.org>2016-02-15 23:10:29 +0100
commitc8ad01472671c862cd759addcb5983817fe66c29 (patch)
treef0dec7f868a737647fb6afc0f76eb8d9d3c5c212 /MgaRepo/log.py
parent23f4f4e3272e7a7026545c084de0ed140368f3bd (diff)
downloadmgarepo-c8ad01472671c862cd759addcb5983817fe66c29.tar
mgarepo-c8ad01472671c862cd759addcb5983817fe66c29.tar.gz
mgarepo-c8ad01472671c862cd759addcb5983817fe66c29.tar.bz2
mgarepo-c8ad01472671c862cd759addcb5983817fe66c29.tar.xz
mgarepo-c8ad01472671c862cd759addcb5983817fe66c29.zip
Correct a crash in rpmlog command when smthg is not committed
Diffstat (limited to 'MgaRepo/log.py')
-rw-r--r--MgaRepo/log.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/MgaRepo/log.py b/MgaRepo/log.py
index 40302bc..692e3d2 100644
--- a/MgaRepo/log.py
+++ b/MgaRepo/log.py
@@ -14,6 +14,7 @@ import glob
import tempfile
import shutil
import subprocess
+import select
locale.setlocale(locale.LC_ALL, "C")
@@ -43,13 +44,26 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
command = (("rpm -q --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' "
"--specfile %s %s") %
(specpath, options))
- pipe = subprocess.Popen(command, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, shell=True)
- pipe.wait()
- output = pipe.stdout.read()
- error = pipe.stderr.read()
- if pipe.returncode != 0:
- raise Error("Error in command %s: %s" % (command, error))
+ output = StringIO()
+ err = StringIO()
+ p = subprocess.Popen(command, shell=True,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ of = p.stdout.fileno()
+ ef = p.stderr.fileno()
+ while True:
+ r,w,x = select.select((of,ef), (), ())
+ odata = None
+ if of in r:
+ odata = (os.read(of, 8192)).decode('utf8')
+ output.write(odata)
+ edata = None
+ if ef in r:
+ edata = (os.read(ef, 8192)).decode('utf8')
+ err.write(edata)
+ status = p.poll()
+ if status is not None and odata == '' and edata == '':
+ break
+ output = output.getvalue()
releases = output.split()
try:
epoch, vr = releases[0].split(":", 1)