aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo
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
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')
-rw-r--r--MgaRepo/log.py112
-rw-r--r--MgaRepo/rpmutil.py80
2 files changed, 121 insertions, 71 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
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):