diff options
Diffstat (limited to 'MgaRepo')
-rw-r--r-- | MgaRepo/log.py | 95 |
1 files changed, 32 insertions, 63 deletions
diff --git a/MgaRepo/log.py b/MgaRepo/log.py index ab7695a..22dc3eb 100644 --- a/MgaRepo/log.py +++ b/MgaRepo/log.py @@ -30,84 +30,53 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None, create=False): from MgaRepo.rpmutil import rpm_macros_defs svn = SVN() pkgcurrenturl = os.path.join(pkgdirurl, "current") - if not create: - if exported is None: - tmpdir = tempfile.mktemp() - svn.export(pkgcurrenturl, tmpdir, rev=rev) - topdir = tmpdir - else: - topdir = exported - try: + if exported is None: + tmpdir = tempfile.mktemp() + svn.export(pkgcurrenturl, tmpdir, rev=rev) + topdir = tmpdir + else: + topdir = exported + try: + options = rpm_macros_defs(macros) + if not create: found = glob.glob(os.path.join(topdir, "SPECS", "*.spec")) if not found: raise Error("no .spec file found inside %s" % specurl) specpath = found[0] - options = rpm_macros_defs(macros) command = (("rpm -q --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' " "--specfile %s %s --define '_topdir %s'") % (specpath, options, topdir)) - pipe = subprocess.Popen(command, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, shell=True) - pipe.wait() - output = pipe.stdout.read().decode('utf8') - error = pipe.stderr.read().decode('utf8') - if pipe.returncode != 0: - raise Error("Error in command %s: %s" % (command, error)) - releases = output.split() - try: - epoch, vr = releases[0].split(":", 1) - version, release = vr.split("-", 1) - except ValueError: - raise Error("Invalid command output: %s: %s" % \ - (command, output)) - #XXX check if this is the right way: - if epoch == "(none)": - ev = version - else: - ev = epoch + ":" + version - return ev, release - finally: - if exported is None and os.path.isdir(tmpdir): - shutil.rmtree(tmpdir) - else: - if exported is None: - tmpdir = tempfile.mktemp() - svn.export(pkgcurrenturl, tmpdir, rev=rev) - topdir = tmpdir else: - topdir = exported - try: found = glob.glob(os.path.join(topdir, "SRPMS", "*.src.rpm")) if not found: raise Error("no .src.rpm file found inside %s" % srpmurl) srpmpath = found[0] - options = rpm_macros_defs(macros) command = (("rpm -qp --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' " " %s %s --define '_topdir %s'") % (srpmpath, options, topdir)) - pipe = subprocess.Popen(command, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, shell=True) - pipe.wait() - output = pipe.stdout.read().decode('utf8') - error = pipe.stderr.read().decode('utf8') - if pipe.returncode != 0: - raise Error("Error in command %s: %s" % (command, error)) - releases = output.split() - try: - epoch, vr = releases[0].split(":", 1) - version, release = vr.split("-", 1) - except ValueError: - raise Error("Invalid command output: %s: %s" % \ - (command, output)) - #XXX check if this is the right way: - if epoch == "(none)": - ev = version - else: - ev = epoch + ":" + version - return ev, release - finally: - if exported is None and os.path.isdir(tmpdir): - shutil.rmtree(tmpdir) + pipe = subprocess.Popen(command, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True) + pipe.wait() + output = pipe.stdout.read().decode('utf8') + error = pipe.stderr.read().decode('utf8') + if pipe.returncode != 0: + raise Error("Error in command %s: %s" % (command, error)) + releases = output.split() + try: + epoch, vr = releases[0].split(":", 1) + version, release = vr.split("-", 1) + except ValueError: + raise Error("Invalid command output: %s: %s" % \ + (command, output)) + #XXX check if this is the right way: + if epoch == "(none)": + ev = version + else: + ev = epoch + ":" + version + return ev, release + finally: + if exported is None and os.path.isdir(tmpdir): + shutil.rmtree(tmpdir) class _Revision: lines = [] |