aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageialinux-online.org>2016-05-29 12:07:58 +0200
committerPapoteur <papoteur@mageialinux-online.org>2016-05-29 12:07:58 +0200
commit8fc7ce395e1d9370896fe7a14e0128177fcd8c4f (patch)
tree99387420df64dd8988fda8248c57d6ffd90df148
parent9d8d2bc03257a39bc5ddf6bec848431b4e538662 (diff)
downloadmgarepo-8fc7ce395e1d9370896fe7a14e0128177fcd8c4f.tar
mgarepo-8fc7ce395e1d9370896fe7a14e0128177fcd8c4f.tar.gz
mgarepo-8fc7ce395e1d9370896fe7a14e0128177fcd8c4f.tar.bz2
mgarepo-8fc7ce395e1d9370896fe7a14e0128177fcd8c4f.tar.xz
mgarepo-8fc7ce395e1d9370896fe7a14e0128177fcd8c4f.zip
Add a retry with building srpm in case of error in getrelease when creating a srpm.
-rw-r--r--MgaRepo/log.py124
-rw-r--r--MgaRepo/rpmutil.py70
2 files changed, 128 insertions, 66 deletions
diff --git a/MgaRepo/log.py b/MgaRepo/log.py
index e02547f..fab7d6e 100644
--- a/MgaRepo/log.py
+++ b/MgaRepo/log.py
@@ -19,7 +19,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,84 @@ 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 = rpm_macros_defs(macros)
- command = (("rpm -q --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' "
- "--specfile %s %s") %
- (specpath, options))
- output = get_output_exec(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 = rpm_macros_defs(macros)
+ 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().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(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 = rpm_macros_defs(macros)
+ command = (("rpm -qp --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' "
+ " %s %s") %
+ (srpmpath, options))
+ 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 = []
date = None
@@ -390,7 +437,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()
@@ -454,7 +501,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)
@@ -561,7 +608,7 @@ def get_old_log(pkgdirurl):
def get_changelog(pkgdirurl, another=None, svn=True, rev=None, size=None,
submit=False, sort=False, template=None, macros=[], exported=None,
- oldlog=False):
+ oldlog=False, create=False):
"""Generates the changelog for a given package URL
@another: a stream with the contents of a changelog to be merged with
@@ -583,11 +630,12 @@ 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:
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)
@@ -600,7 +648,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):
+ submit=False, sort=False, template=None, macros=[], exported=None, create=False):
with open(specfile, encoding = 'utf-8') as fi:
spec, oldchlog = split_spec_changelog(fi)
another = None
@@ -609,14 +657,14 @@ def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None,
sort = sort or config.getbool("log", "sort", False)
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\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
diff --git a/MgaRepo/rpmutil.py b/MgaRepo/rpmutil.py
index 8c00da9..01f6fa2 100644
--- a/MgaRepo/rpmutil.py
+++ b/MgaRepo/rpmutil.py
@@ -55,6 +55,32 @@ def rev_touched_url(url, rev):
touched = True
return touched
+def cp_srpms(revision, revname, geturl, targetdirs, srpmsdir, verbose):
+ targetsrpms = []
+ urlrev = None
+ if revname:
+ urlrev = revision or layout.get_url_revision(geturl)
+ if not targetdirs:
+ targetdirs = (".",)
+ srpms = glob.glob(os.path.join(srpmsdir, "*.src.rpm"))
+ if not srpms:
+ # something fishy happened
+ raise Error, "no SRPMS were found at %s" % srpmsdir
+ for srpm in srpms:
+ name = os.path.basename(srpm)
+ if revname:
+ name = "@%s:%s" % (urlrev, name)
+ for targetdir in targetdirs:
+ newpath = os.path.join(targetdir, name)
+ targetsrpms.append(newpath)
+ if os.path.exists(newpath):
+ # should we warn?
+ os.unlink(newpath)
+ shutil.copy(srpm, newpath)
+ if verbose:
+ sys.stderr.write("Wrote: %s\n" % newpath)
+ return targetsrpms
+
def get_srpm(pkgdirurl,
mode = "current",
targetdirs = None,
@@ -111,49 +137,37 @@ def get_srpm(pkgdirurl,
if not speclist:
raise Error("no spec files found")
spec = speclist[0]
+
+ defs = rpm_macros_defs(macros)
+ sourcecmd = config.get("helper", "rpmbuild", "rpmbuild")
+ if packager:
+ packager = " --define 'packager %s'" % packager
if svnlog:
submit = not not revision
- log.specfile_svn2rpm(pkgdirurl, spec, revision, submit=submit,
+ try:
+ log.specfile_svn2rpm(pkgdirurl, spec, revision, submit=submit,
template=template, macros=macros, exported=tmpdir)
+ except:
+ execcmd("%s -bs --nodeps %s %s %s %s %s %s %s %s %s %s" %
+ (sourcecmd, topdir, builddir, rpmdir, sourcedir, specdir,
+ srcrpmdir, patchdir, packager, spec, defs))
+ cp_srpms(revision, revname, geturl, targetdirs, srpmsdir, verbose)
+ log.specfile_svn2rpm(pkgdirurl, spec, revision, submit=submit,
+ template=template, macros=macros, exported=tmpdir, create=True)
+
for script in scripts:
#FIXME revision can be "None"
status, output = execcmd(script, tmpdir, spec, str(revision),
noerror=1)
if status != 0:
raise Error("script %s failed" % script)
- if packager:
- packager = " --define 'packager %s'" % packager
- defs = rpm_macros_defs(macros)
- sourcecmd = config.get("helper", "rpmbuild", "rpmbuild")
execcmd("%s -bs --nodeps %s %s %s %s %s %s %s %s %s %s" %
(sourcecmd, topdir, builddir, rpmdir, sourcedir, specdir,
srcrpmdir, patchdir, packager, spec, defs))
# copy the generated SRPMs to their target locations
- targetsrpms = []
- urlrev = None
- if revname:
- urlrev = revision or layout.get_url_revision(geturl)
- if not targetdirs:
- targetdirs = (".",)
- srpms = glob.glob(os.path.join(srpmsdir, "*.src.rpm"))
- if not srpms:
- # something fishy happened
- raise Error("no SRPMS were found at %s" % srpmsdir)
- for srpm in srpms:
- name = os.path.basename(srpm)
- if revname:
- name = "@%s:%s" % (urlrev, name)
- for targetdir in targetdirs:
- newpath = os.path.join(targetdir, name)
- targetsrpms.append(newpath)
- if os.path.exists(newpath):
- # should we warn?
- os.unlink(newpath)
- shutil.copy(srpm, newpath)
- if verbose:
- sys.stderr.write("Wrote: %s\n" % newpath)
+ targetsrpms = cp_srpms(revision, revname, geturl, targetdirs, srpmsdir, verbose)
return targetsrpms
finally:
if os.path.isdir(tmpdir):