aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES7
-rw-r--r--Makefile2
-rw-r--r--MgaRepo/log.py112
-rw-r--r--MgaRepo/rpmutil.py80
-rwxr-xr-xmgarepo2
5 files changed, 130 insertions, 73 deletions
diff --git a/CHANGES b/CHANGES
index 290652d..e45b013 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+* 1.12.3
+- syntax correction
+
+* 1.12.2
+- Suppress prefix with no effect on import command (cf 1.12.0)
+- Add a retry with building srpm in case of error in getrelease when creating a srpm
+
* 1.12.1
- prefix the command svn log without LC_ALL=C (mga#73)
diff --git a/Makefile b/Makefile
index e54cd6f..8205229 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
PACKAGE = mgarepo
-VERSION = 1.12.1
+VERSION = 1.12.3
.PHONY: all $(DIRS) clean
clean:
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
diff --git a/MgaRepo/rpmutil.py b/MgaRepo/rpmutil.py
index c9a87b1..49ef07f 100644
--- a/MgaRepo/rpmutil.py
+++ b/MgaRepo/rpmutil.py
@@ -76,6 +76,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,
@@ -137,26 +163,36 @@ def get_srpm(pkgdirurl,
if not speclist:
raise Error("no spec files found")
spec = speclist[0]
+
+ sourcecmd = config.get("helper", "rpmbuild", "rpmbuild")
+ if packager:
+ packager = " --define 'packager %s'" % packager
+ sourcecmd = config.get("helper", "rpmbuild", "rpmbuild")
+ args = [sourcecmd, "-bs", "--nodeps"]
+ for pair in rpmdefs:
+ args.extend(pair)
+ for pair in macros:
+ args.extend(("--define", "%s %s" % pair))
+ args.append(spec)
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, fullnames=fullnames)
+ except:
+ #cmd = [sourcecmd, topdir, builddir, rpmdir, sourcedir, specdir
+ execcmd(args)
+ 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
- sourcecmd = config.get("helper", "rpmbuild", "rpmbuild")
- args = [sourcecmd, "-bs", "--nodeps"]
- for pair in rpmdefs:
- args.extend(pair)
- for pair in macros:
- args.extend(("--define", "%s %s" % pair))
- args.append(spec)
try:
execcmd(args)
except CommandError as e:
@@ -168,29 +204,7 @@ def get_srpm(pkgdirurl,
"(with %s):\n%s%s" % (sourcecmd, cmdline, e.output))
# 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):
diff --git a/mgarepo b/mgarepo
index 9329684..2ad21b4 100755
--- a/mgarepo
+++ b/mgarepo
@@ -4,7 +4,7 @@ from MgaRepo.command import *
import getopt
import sys
-VERSION="1.12.1"
+VERSION="1.12.3"
HELP = """\
Usage: mgarepo COMMAND [COMMAND ARGUMENTS]