diff options
author | Pascal Terjan <pterjan@mageia.org> | 2018-10-04 21:39:40 +0000 |
---|---|---|
committer | Pascal Terjan <pterjan@mageia.org> | 2018-10-04 21:39:40 +0000 |
commit | f05d7bf3e8b8d594086115bc0a8ba8939fd6bed5 (patch) | |
tree | 2cf7fcf63d4c953436a6db5634dece7de884aa43 /MgaRepo/log.py | |
parent | aea06b5322692608d94670d809e4244ce68ed7a5 (diff) | |
download | mgarepo-f05d7bf3e8b8d594086115bc0a8ba8939fd6bed5.tar mgarepo-f05d7bf3e8b8d594086115bc0a8ba8939fd6bed5.tar.gz mgarepo-f05d7bf3e8b8d594086115bc0a8ba8939fd6bed5.tar.bz2 mgarepo-f05d7bf3e8b8d594086115bc0a8ba8939fd6bed5.tar.xz mgarepo-f05d7bf3e8b8d594086115bc0a8ba8939fd6bed5.zip |
Merge duplicate code
Diffstat (limited to 'MgaRepo/log.py')
-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 = [] |