summaryrefslogtreecommitdiffstats
path: root/mgagnome
diff options
context:
space:
mode:
authorOlav Vitters <olav@vitters.nl>2013-09-17 17:23:13 +0200
committerOlav Vitters <olav@vitters.nl>2013-09-17 17:23:13 +0200
commit802d02e02abbc1299d8eef07b9c0dd9a7cb3272b (patch)
tree0e42f801bfcb25c4b190214c27426fb50d89aa57 /mgagnome
parenta783d3f38d752aaa409a0808ac445e526c6a705f (diff)
downloadmgagnome-802d02e02abbc1299d8eef07b9c0dd9a7cb3272b.tar
mgagnome-802d02e02abbc1299d8eef07b9c0dd9a7cb3272b.tar.gz
mgagnome-802d02e02abbc1299d8eef07b9c0dd9a7cb3272b.tar.bz2
mgagnome-802d02e02abbc1299d8eef07b9c0dd9a7cb3272b.tar.xz
mgagnome-802d02e02abbc1299d8eef07b9c0dd9a7cb3272b.zip
add a check-setup command
Diffstat (limited to 'mgagnome')
-rwxr-xr-xmgagnome80
1 files changed, 80 insertions, 0 deletions
diff --git a/mgagnome b/mgagnome
index 70e1a0e..18c9ee1 100755
--- a/mgagnome
+++ b/mgagnome
@@ -49,6 +49,9 @@ import datetime
# packages --sort
import itertools
+# automatically dropping merged patches
+import shlex
+
# check-latest
import requests
@@ -290,6 +293,7 @@ class SpecFile(object):
self.path = path
self.cwd = os.path.dirname(path)
self.module = module
+ self.changes = []
@property
def version(self):
@@ -306,9 +310,70 @@ class SpecFile(object):
return self._sources_and_patches(flag=2)
@property
+ def uses_apply_patches(self):
+ return subprocess.call(['grep', '-q', '^%apply_patches', '--', self.path]) == 0
+
+ @property
def sources(self):
return self._sources_and_patches(flag=1)
+ def check_and_update_patches(self):
+ """Check if patches still apply
+
+ Remove any merged patches"""
+
+ LOGLINES = 15
+
+ initial_patches = self.patches
+ patches = initial_patches
+ uses_apply_patches = self.uses_apply_patches if patches else False
+
+ try:
+ # Check patches still apply
+ subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd)
+ except subprocess.CalledProcessError:
+ logfile = os.path.join(os.path.dirname(self.path), 'log.%s' % os.path.splitext(os.path.basename(self.path))[0])
+
+ failed_patch = None
+ cmd = None
+ cmd_output = []
+ # Determine the last command that failed
+ if os.path.exists(logfile):
+ with open(logfile, "r") as f:
+ for line in line_input(f):
+ if line.startswith('+ '):
+ cmd = line[2:]
+ cmd_output = []
+ else:
+ cmd_output.append(line)
+
+ cmd_parsed = shlex.split(cmd) if cmd else []
+
+ if uses_apply_patches and patches and cmd_parsed:
+ if os.path.basename(cmd_parsed[0]) == 'patch' and os.path.exists(cmd_parsed[-1]):
+ failed_patch = os.path.basename(cmd_parsed[-1])
+
+ # XXX -- check if patch has been merged
+ # XXX -- if patch was merged, drop it from spec file and rety
+
+ if cmd and len(cmd_output) > LOGLINES:
+ print >>sys.stdout, '+ %s' % cmd
+ print >>sys.stdout, "\n".join(cmd_output)
+ elif os.path.exists(logfile):
+ subprocess.call(['tail', '-n', str(LOGLINES), logfile])
+
+ if failed_patch:
+ print >>sys.stderr, "ERROR: Problem applying patch: %s" % failed_patch
+ elif cmd:
+ print >>sys.stderr, "ERROR: Problem in %%setup phase command: %s" % cmd
+ elif patches:
+ print >>sys.stderr, "ERROR: Problem applying patches and/or %setup phase"
+ else:
+ print >>sys.stderr, "ERROR: Problem in %setup phase"
+ return False
+
+ return True
+
def update(self, version, force=False):
"""Update specfile (increase version)"""
cur_version = self.version
@@ -362,6 +427,7 @@ class SpecFile(object):
# Overwrite file with new version number
write_file(self.path, data)
+ self.changes.append('new version %s' % version)
# Verify that RPM also agrees that version number has changed
if self.version != version:
@@ -857,6 +923,14 @@ def cmd_dep3(options, parser):
p = Patch(options.patch)
p.add_dep3()
+def cmd_check_setup(options, parser):
+ # Directories packages are located in
+ root = os.path.expanduser(Downstream.PKGROOT)
+ cwd = os.path.join(root, options.package)
+
+ s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % options.package), module=options.package)
+ s.check_and_update_patches()
+
def cmd_package_new_version(options, parser):
# Determine the package name
if options.upstream:
@@ -1072,6 +1146,12 @@ def main():
func=cmd_dep3, path=False
)
+ subparser = subparsers.add_parser('check-setup', help='check setup phase')
+ subparser.add_argument("package", help="Package name")
+ subparser.set_defaults(
+ func=cmd_check_setup
+ )
+
subparser = subparsers.add_parser('increase', help='Increase version number')
subparser.add_argument("package", help="Package name")
subparser.add_argument("version", help="Version number")