summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmgagnome156
1 files changed, 129 insertions, 27 deletions
diff --git a/mgagnome b/mgagnome
index 00f7cd6..abe23da 100755
--- a/mgagnome
+++ b/mgagnome
@@ -329,6 +329,10 @@ class SpecFile(object):
def version(self):
return subprocess.check_output(["rpm", "--define", "_topdir %s" % os.path.join(self.cwd, ".."), "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).decode("utf-8").splitlines()[0]
+ @property
+ def release(self):
+ return subprocess.check_output(["rpm", "--define", "%dist %nil", "--define", "_topdir %s" % os.path.join(self.cwd, ".."), "--specfile", self.path, "--queryformat", "%{RELEASE}\n"]).decode("utf-8").splitlines()[0]
+
def _sources_and_patches(self, flag=None):
os.chdir(self.cwd)
rpm.delMacro("_topdir" )
@@ -751,9 +755,48 @@ class SpecFile(object):
return True
+ def _check_can_update(self, force):
+ data = None
+ if not self.ensure_no_local_changes(force):
+ return None
+
+ with open(self.path, "r", encoding="utf-8") as f:
+ data = f.read()
+
+ if data.count("%subrel") != 0:
+ print("ERROR: %subrel found; don't know what to do!", file=sys.stderr)
+ return None
+
+ if data.count("%mkrel") != 1:
+ print("ERROR: Multiple %mkrel found; don't know what to do!", file=sys.stderr)
+ return None
+
+ return data
+
+ def update_release(self, release, reason, force=False):
+ """Update release (usually for rebuilds)"""
+ cur_release = self.release
+
+ data = self._check_can_update(force)
+ if data is None:
+ return False
+
+ # XXX - validate current release
+ data, nr = self.re_update_release.subn(r'\g<pre>%%mkrel %s\g<post>' % release, data, 1)
+ if nr != 1:
+ print(data, file=sys.stdout)
+ print("ERROR: Could not increase release!", file=sys.stderr)
+ return False
+
+ # Overwrite file with new release
+ write_file(self.path, data)
- def update(self, version, force=False, max_judgement=MAX_JUDGEMENT):
- """Update specfile (increase version)"""
+ self._changes['rebuild for %s' % reason] = True
+
+ return True
+
+ def update_version(self, version, force=False, max_judgement=MAX_JUDGEMENT):
+ """Update version and reset release"""
cur_version = self.version
(judgement, msg) = judge_version_increase(cur_version, version, self.module)
@@ -766,33 +809,23 @@ class SpecFile(object):
print("WARNING: %s!" % (msg))
if not force: return False
- if not self.ensure_no_local_changes(force):
+ data = self._check_can_update(force)
+ if data is None:
return False
- with open(self.path, "r", encoding="utf-8") as f:
- data = f.read()
-
- if data.count("%subrel") != 0:
- print("ERROR: %subrel found; don't know what to do!", file=sys.stderr)
- return False
-
- if data.count("%mkrel") != 1:
- print("ERROR: Multiple %mkrel found; don't know what to do!", file=sys.stderr)
- return False
-
- data, nr = self.re_update_version.subn(r'\g<pre>%s\g<post>' % version, data, 1)
- if nr != 1:
- print("ERROR: Could not increase version!", file=sys.stderr)
- return False
+ data, nr = self.re_update_version.subn(r'\g<pre>%s\g<post>' % version, data, 1)
+ if nr != 1:
+ print("ERROR: Could not increase version!", file=sys.stderr)
+ return False
- data, nr = self.re_update_release.subn(r'\g<pre>%mkrel 1\g<post>', data, 1)
- if nr != 1:
- print(data, file=sys.stdout)
- print("ERROR: Could not reset release!", file=sys.stderr)
- return False
+ data, nr = self.re_update_release.subn(r'\g<pre>%mkrel 1\g<post>', data, 1)
+ if nr != 1:
+ print(data, file=sys.stdout)
+ print("ERROR: Could not reset release!", file=sys.stderr)
+ return False
- # Overwrite file with new version number
- write_file(self.path, data)
+ # Overwrite file with new version number
+ write_file(self.path, data)
self._changes['new version %s' % version] = True
@@ -801,7 +834,6 @@ class SpecFile(object):
print("ERROR: Increased version to %s, but RPM doesn't agree!?!" % version, file=sys.stderr)
return False
-
# Try to download the new tarball various times and wait between attempts
tries = 0
while tries < SLEEP_TIMES:
@@ -1492,6 +1524,60 @@ def cmd_clean_spec(options, parser):
# for package in packages:
# cmd_clean_spec_multi((options, package))
+def cmd_new_release(options, parser):
+ # Determine the package name
+ if options.upstream:
+ try:
+ package = Downstream().get_downstream_from_upstream(options.package, options.version)[0]
+ except ValueError as e:
+ print("ERROR: %s" % e, file=sys.stderr)
+ sys.exit(1)
+ else:
+ package = options.package
+
+ # Directories packages are located in
+ root = os.path.expanduser(Downstream.PKGROOT)
+ cwd = os.path.join(root, package)
+
+ # Checkout package to ensure the checkout reflects the latest changes
+ try:
+ Downstream.co(package, cwd=root)
+ except subprocess.CalledProcessError:
+ subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd)
+ sys.exit(1)
+
+ # SpecFile class handles the actual version+release change
+ # XXX - module should reflect upstream name, this gives it the package name
+ s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package), module=package)
+ cur_release = s.release
+ new_release = int(cur_release)+1
+ print("%s => %s" % (cur_release, new_release))
+
+ # XXX - Duplicate check as should not revert changes if specfile has already been changed
+ if not s.ensure_no_local_changes(options.force):
+ sys.exit(1)
+
+ if not s.update_release(new_release, options.reason, force=options.force):
+ subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd, stdout=subprocess.DEVNULL)
+ sys.exit(1)
+
+ try:
+ # If we made it this far, checkin the changes
+ Downstream.ci(package, s.changes, cwd=cwd)
+
+ # Submit is optional
+ if options.submit:
+ cmd = ['mgarepo', 'submit']
+ if Downstream.DISTRO:
+ cmd.extend(('--define', 'section=core/updates_testing', '-t', Downstream.DISTRO))
+
+ # retry submission various times, could be that some dependencies are being built at the same time
+ @retry(subprocess.CalledProcessError, tries=10, delay=300, backoff=1.5)
+ def _submit(): subprocess.check_call(cmd, cwd=cwd)
+ _submit()
+ except subprocess.CalledProcessError:
+ sys.exit(1)
+
def cmd_package_new_version(options, parser):
# Determine the package name
if options.upstream:
@@ -1523,7 +1609,7 @@ def cmd_package_new_version(options, parser):
if not s.ensure_no_local_changes(options.force):
sys.exit(1)
- if not s.update(options.version, force=options.force):
+ if not s.update_version(options.version, force=options.force):
# XXX - hack to automatically revert changes when auto upgrading from ftp release list
if options.hexdigest is not None:
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd, stdout=subprocess.DEVNULL)
@@ -1738,6 +1824,22 @@ def main():
func=cmd_group_owner
)
+ subparser = subparsers.add_parser('rebuild', help='increase release')
+ subparser.add_argument("package", help="Package name")
+ subparser.add_argument("-m", "--reason", dest="reason", required=True, help="Reason for the rebuild")
+ subparser.add_argument("-f", "--force", action="store_true", dest="force",
+ help="Override warnings, just do it")
+ subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream",
+ help="Package name reflects the upstream name")
+ subparser.add_argument("-s", "--submit", action="store_true", dest="submit",
+ help="Commit changes and submit")
+ subparser.add_argument( "--no-submit", action="store_false", dest="submit",
+ help="Do not commit changes and submit")
+ subparser.set_defaults(
+ func=cmd_new_release, submit=argparse.SUPPRESS, upstream=False,
+ force=False
+ )
+
subparser = subparsers.add_parser('increase', help='increase version number')
subparser.add_argument("package", help="Package name")
subparser.add_argument("version", help="Version number")