aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo/log.py
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <proyvind@moondrake.org>2016-08-18 07:09:57 +0200
committerPer Øyvind Karlsen <proyvind@moondrake.org>2016-08-18 07:09:57 +0200
commit63821d6de037580afda4e27d93b234b6329992ff (patch)
tree1c88355524ea161b9b289f143c100c5c3e6a0066 /MgaRepo/log.py
parentcafc90364b7103ec28f9a42c9ce6f38389f91461 (diff)
parent7480f7479ef24584c482143516ee17c7b58f8cde (diff)
downloadmgarepo-63821d6de037580afda4e27d93b234b6329992ff.tar
mgarepo-63821d6de037580afda4e27d93b234b6329992ff.tar.gz
mgarepo-63821d6de037580afda4e27d93b234b6329992ff.tar.bz2
mgarepo-63821d6de037580afda4e27d93b234b6329992ff.tar.xz
mgarepo-63821d6de037580afda4e27d93b234b6329992ff.zip
Merge remote-tracking branch 'origin/master' into git
Diffstat (limited to 'MgaRepo/log.py')
-rw-r--r--MgaRepo/log.py112
1 files changed, 74 insertions, 38 deletions
diff --git a/MgaRepo/log.py b/MgaRepo/log.py
index d7ad511..f6c0fc9 100644
--- a/MgaRepo/log.py
+++ b/MgaRepo/log.py
@@ -20,7 +20,8 @@ import subprocess
locale.setlocale(locale.LC_ALL, "C")
-def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
+
+def getrelease(pkgdirurl, rev=None, macros=[], exported=None, create=False):
"""Tries to obtain the version-release of the package for a
yet-not-markrelease revision of the package.
@@ -30,38 +31,72 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
svn = SVN()
pkgcurrenturl = os.path.join(pkgdirurl, "current")
specurl = os.path.join(pkgcurrenturl, "SPECS")
- if exported is None:
- tmpdir = tempfile.mktemp()
- svn.export(specurl, tmpdir, rev=rev)
- else:
- tmpdir = os.path.join(exported, "SPECS")
- try:
- found = glob.glob(os.path.join(tmpdir, "*.spec"))
- if not found:
- raise Error("no .spec file found inside %s" % specurl)
- specpath = found[0]
- options = [("--define", expr) for expr in macros]
- command = ["rpm", "-q", "--qf", "%{EPOCH}:%{VERSION}-%{RELEASE}\n",
- "--specfile", specpath]
- command.extend(options)
- status, output = execcmd(*command)
- releases = output.split()
+ srpmurl = os.path.join(pkgcurrenturl, "SRPMS")
+ if not create:
+ if exported is None:
+ tmpdir = tempfile.mktemp()
+ svn.export(specurl, tmpdir, rev=rev)
+ else:
+ tmpdir = os.path.join(exported, "SPECS")
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
+ found = glob.glob(os.path.join(tmpdir, "*.spec"))
+ if not found:
+ raise Error("no .spec file found inside %s" % specurl)
+ specpath = found[0]
+ options = [("--define", expr) for expr in macros]
+ command = ["rpm", "-q", "--qf", "%{EPOCH}:%{VERSION}-%{RELEASE}\n",
+ "--specfile", specpath]
+ command.extend(options)
+ status, output = execcmd(*command)
+ 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(specurl, tmpdir, rev=rev)
else:
- ev = epoch + ":" + version
- return ev, release
- finally:
- if exported is None and os.path.isdir(tmpdir):
- shutil.rmtree(tmpdir)
-
+ tmpdir = os.path.join(exported, "SRPMS")
+ try:
+ found = glob.glob(os.path.join(srpmurl, "*.src.rpm"))
+ if not found:
+ raise Error("no .src.rpm file found inside %s" % srpmurl)
+ srpmpath = found[0]
+ options = [("--define", expr) for expr in macros]
+ command = ["rpm", "-q", "--qf", "%{EPOCH}:%{VERSION}-%{RELEASE}\n",
+ "--specfile", specpath]
+ command.extend(options)
+ status, output = execcmd(*command)
+ 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 = []
date = None
@@ -395,7 +430,7 @@ def parse_markrelease_log(relentry):
def svn2rpm(pkgdirurl, rev=None, size=None, submit=False,
- template=None, macros=[], exported=None):
+ template=None, macros=[], exported=None, create=False):
concat = config.get("log", "concat", "").split()
revoffset = get_revision_offset()
svn = SVN()
@@ -459,7 +494,7 @@ def svn2rpm(pkgdirurl, rev=None, size=None, submit=False,
# if they are not submitted yet, what we have to do is to add
# a release/version number from getrelease()
version, release = getrelease(pkgdirurl, macros=macros,
- exported=exported)
+ exported=exported, create=create)
toprelease = make_release(entries=notsubmitted, released=False,
version=version, release=release)
releases.append(toprelease)
@@ -631,7 +666,7 @@ def _map_user_names():
def get_changelog(pkgdirurl, another=None, svn=True, rev=None, size=None,
submit=False, sort=False, template=None, macros=[], exported=None,
- oldlog=False, fullnames=False):
+ oldlog=False, create=False, fullnames=False):
"""Generates the changelog for a given package URL
@another: a stream with the contents of a changelog to be merged with
@@ -653,6 +688,7 @@ def get_changelog(pkgdirurl, another=None, svn=True, rev=None, size=None,
parsed from there
@oldlog: if set it will try to append the old changelog file defined
in oldurl in mgarepo.conf
+ @create: if set, will use rpm -qp rpm instead of --specfile to get release number
"""
newlog = StringIO()
if svn:
@@ -660,7 +696,7 @@ def get_changelog(pkgdirurl, another=None, svn=True, rev=None, size=None,
if not usermap:
_map_user_names()
rawsvnlog = svn2rpm(pkgdirurl, rev=rev, size=size, submit=submit,
- template=template, macros=macros, exported=exported)
+ template=template, macros=macros, exported=exported, create=create)
newlog.write(rawsvnlog)
if another:
newlog.writelines(another)
@@ -673,7 +709,7 @@ def get_changelog(pkgdirurl, another=None, svn=True, rev=None, size=None,
return newlog
def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None,
- submit=False, sort=False, template=None, macros=[], exported=None, fullnames=False):
+ submit=False, sort=False, template=None, macros=[], exported=None, create=False, fullnames=False):
with open(specfile, encoding = 'utf-8') as fi:
spec, oldchlog = split_spec_changelog(fi)
another = None
@@ -684,14 +720,14 @@ def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None,
_map_user_names()
chlog = get_changelog(pkgdirurl, another=another, rev=rev, size=size,
submit=submit, sort=sort, template=template, macros=macros,
- exported=exported, oldlog=True)
+ exported=exported, oldlog=True, create=create)
with open(specfile, "w", encoding='utf-8') as fo:
fo.writelines(spec)
fo.write("\n%changelog\n")
fo.writelines(chlog)
if __name__ == "__main__":
- l = svn2rpm(sys.argv[1])
+ l = svn2rpm(sys.argv[1], create=True)
print(l)
# vim:et:ts=4:sw=4