summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlav Vitters <olav@vitters.nl>2020-04-23 16:05:59 +0200
committerOlav Vitters <olav@vitters.nl>2020-04-23 16:05:59 +0200
commit04ffcc4bece7335925fe00d1370a6f429be65319 (patch)
treefae1bdc219ac1b099c5c75928bf5813398b80e7b
parent207e05016128f9cf1f13748a24e56c2cd6506de2 (diff)
downloadmgagnome-04ffcc4bece7335925fe00d1370a6f429be65319.tar
mgagnome-04ffcc4bece7335925fe00d1370a6f429be65319.tar.gz
mgagnome-04ffcc4bece7335925fe00d1370a6f429be65319.tar.bz2
mgagnome-04ffcc4bece7335925fe00d1370a6f429be65319.tar.xz
mgagnome-04ffcc4bece7335925fe00d1370a6f429be65319.zip
restructure the code, move more logic into Downstream class
-rwxr-xr-xmgagnome85
1 files changed, 45 insertions, 40 deletions
diff --git a/mgagnome b/mgagnome
index a644e04..875edea 100755
--- a/mgagnome
+++ b/mgagnome
@@ -335,12 +335,17 @@ class SpecFile(object):
self.module = module
self._changes = collections.OrderedDict()
self._should_rebuild = False
+ self._changed_spec_file = False
@property
def changes(self):
return ''.join(self._changes.keys()) if len(self._changes) == 1 else "\n".join(("- %s" % change for change in self._changes.keys()))
@property
+ def made_changes(self):
+ return self._changed_spec_file
+
+ @property
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]
@@ -480,6 +485,7 @@ class SpecFile(object):
# Overwrite file with new version number
if made_changes:
+ self._changed_spec_file = True
write_file(self.path, data)
return made_changes
@@ -550,6 +556,7 @@ class SpecFile(object):
try:
change_to = data.replace(mo2.group(0), prep, 1)
+ self._changed_spec_file = True
write_file(self.path, change_to)
# Validate patches still apply
@@ -623,6 +630,7 @@ class SpecFile(object):
return False
# Overwrite file with new version number
+ self._changed_spec_file = True
write_file(self.path, data)
if info_patchname:
@@ -768,7 +776,8 @@ class SpecFile(object):
print(changes)
return False
- # Overwrite file with new version number
+ # Overwrite file with updated buildrequire
+ self._changed_spec_file = True
write_file(self.path, data)
return made_changes
@@ -828,6 +837,7 @@ class SpecFile(object):
return False
# Overwrite file with new release
+ self._changed_spec_file = True
write_file(self.path, data)
self._changes['rebuild for %s' % reason] = True
@@ -864,6 +874,7 @@ class SpecFile(object):
return False
# Overwrite file with new version number
+ self._changed_spec_file = True
write_file(self.path, data)
self._changes['new version %s' % version] = True
@@ -1194,6 +1205,17 @@ class Downstream(object):
return set()
@classmethod
+ def package_path(cls, package):
+ return os.path.join(os.path.expanduser(Downstream.PKGROOT), package)
+
+ @classmethod
+ def package_spec(cls, package):
+ path = cls.package_path(package)
+
+ return SpecFile(os.path.join(path, "SPECS", "%s.spec" % package), module=package)
+
+
+ @classmethod
@retry(subprocess.CalledProcessError)
def co(cls, package, cwd=None, spec_only=False):
if cwd is None:
@@ -1211,7 +1233,7 @@ class Downstream(object):
@retry(subprocess.CalledProcessError)
def ci(cls, package, changes, cwd=None):
if cwd is None:
- cwd = os.path.expanduser(cls.PKGROOT)
+ cwd = cls.package_path(package)
cmd = ['mgarepo', 'ci', '-m', changes]
return subprocess.check_call(cmd, cwd=cwd)
@@ -1224,22 +1246,17 @@ class Downstream(object):
if len(self.tarballs[upstream]) == 1:
return list(self.tarballs[upstream].keys())
- # Directories packages are located in
- root = os.path.expanduser(self.PKGROOT)
-
packages = {}
for package in list(self.tarballs[upstream].keys()):
- cwd = os.path.join(root, package)
-
# Checkout package to ensure the checkout reflects the latest changes
try:
- self.co(package, cwd=root)
+ self.co(package)
except subprocess.CalledProcessError:
raise ValueError("Multiple packages found and cannot checkout %s" % package)
# Determine version from spec file
try:
- packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package), module=upstream).version
+ packages[package] = self.package_spec(package).version
except subprocess.CalledProcessError:
raise ValueError("Multiple packages found and cannot determine version of %s" % package)
@@ -1302,8 +1319,6 @@ def cmd_co(options, parser):
executor.map(cmd_co_multi, packages)
def join_streams(show_version=False, only_diff_version=False, auto_update=True):
- root = os.path.expanduser(Downstream.PKGROOT)
-
upstream = Upstream().names
downstream = Downstream()
@@ -1312,7 +1327,7 @@ def join_streams(show_version=False, only_diff_version=False, auto_update=True):
for package in list(downstream.tarballs[module].keys()):
package_version = downstream.tarballs[module][package]
spec_version = None
- cwd = os.path.join(root, package)
+ cwd = Downstream.package_path(package)
if show_version or only_diff_version:
# ensure package is checked out
@@ -1323,7 +1338,7 @@ def join_streams(show_version=False, only_diff_version=False, auto_update=True):
# XXX - ignoring packages which cannot be checked out
continue
try:
- spec_version = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package), module=module).version
+ spec_version = Downstream.package_spec(package).version
except subprocess.CalledProcessError:
spec_version = 'N/A'
@@ -1331,7 +1346,7 @@ def join_streams(show_version=False, only_diff_version=False, auto_update=True):
if auto_update and package_version != spec_version and version_cmp(package_version, spec_version) == 1:
try:
downstream.co(package)
- spec_version = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package), module=module).version
+ spec_version = downstream.package_spec(package).version
except subprocess.CalledProcessError:
pass
@@ -1487,7 +1502,7 @@ def cmd_check_latest(options, parser):
if 'S' in upgrade and options.submit and not Downstream.DISTRO:
cmd = ['mgagnome', 'increase', package, safe_version]
- subprocess.call(cmd, cwd=os.path.expanduser(os.path.join(Downstream.PKGROOT, package)))
+ subprocess.call(cmd, cwd=Downstream.package_path(package))
def cmd_patches(options, parser):
root = os.path.expanduser(Downstream.PKGROOT)
@@ -1510,20 +1525,14 @@ def cmd_dep3(options, parser):
p.add_dep3()
def cmd_check_prep(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 = Downstream.package_spec(options.package)
s.check_and_update_patches()
def cmd_clean_spec_multi(args):
options, package = args
- # Directories packages are located in
- root = os.path.expanduser(Downstream.PKGROOT)
print(package)
- cwd = os.path.join(root, package)
+ cwd = Downstream.package_path(package)
path = os.path.join(cwd, "SPECS", "%s.spec" % package)
if not os.path.exists(path):
@@ -1536,7 +1545,7 @@ def cmd_clean_spec_multi(args):
print('ERROR: Cannot find spec file for package %s' % package, file=sys.stderr)
return False
- s = SpecFile(path, module=package)
+ s = Downstream.package_spec(package)
try:
if not s.ensure_no_local_changes(options.force):
@@ -1703,7 +1712,7 @@ def cmd_clean_spec_multi(args):
Downstream.ci(package, s.changes, cwd=cwd)
if s.should_rebuild:
cmd = ['mgagnome', 'rebuild', '-s', '-m', 'to test removal of deprecated macros', package]
- subprocess.call(cmd, cwd=os.path.expanduser(os.path.join(Downstream.PKGROOT, package)))
+ subprocess.call(cmd, cwd=cwd)
else:
# show the diff and undo all changes
if s.should_rebuild:
@@ -1713,19 +1722,17 @@ def cmd_clean_spec_multi(args):
def cmd_check_spec_multi(args):
options, package = args
- # Directories packages are located in
- root = os.path.expanduser(Downstream.PKGROOT)
- cwd = os.path.join(root, package)
+ cwd = Downstream.package_path(package)
path = os.path.join(cwd, "SPECS", "%s.spec" % package)
if not os.path.exists(path):
return False
- s = SpecFile(path, module=package)
+ s = Downstream.package_spec(package)
try:
patches = s.patches
- except ValueError:
+ except SpecFileError:
print('ERROR: Broken spec file for package %s' % package, file=sys.stderr)
return False
@@ -1783,13 +1790,11 @@ def cmd_new_release(options, parser):
else:
package = pkg
- # Directories packages are located in
- root = os.path.expanduser(Downstream.PKGROOT)
- cwd = os.path.join(root, package)
+ cwd = Downstream.package_path(package)
# Checkout package to ensure the checkout reflects the latest changes
try:
- Downstream.co(package, cwd=root)
+ Downstream.co(package)
except subprocess.CalledProcessError:
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd)
success = False
@@ -1797,11 +1802,12 @@ def cmd_new_release(options, parser):
# 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)
+ s = Downstream.package_spec(package)
cur_release = s.release
try:
new_release = int(cur_release)+1
except ValueError:
+ print("ERROR: Cannot increase the release for package %s" % pkg, file=sys.stderr)
success = False
continue
cur_version = s.version
@@ -1852,19 +1858,18 @@ def cmd_package_new_version(options, parser):
package = options.package
# Directories packages are located in
- root = os.path.expanduser(Downstream.PKGROOT)
- cwd = os.path.join(root, package)
+ cwd = Downstream.package_path(package)
# Checkout package to ensure the checkout reflects the latest changes
try:
- Downstream.co(package, cwd=root)
+ Downstream.co(package)
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)
+ s = Downstream.package_spec(package)
print("%s => %s" % (s.version, options.version))
# XXX - Duplicate check as should not revert changes if specfile has already been changed
@@ -1976,7 +1981,7 @@ def cmd_parse_ftp_release_list(options, parser):
try:
packages = Downstream().get_downstream_from_upstream(module, version)
- except ValueError as e:
+ except (ValueError, SpecFileError) as e:
#print(bytes("ERROR: %s" % str(e), 'UTF-8'), file=stderr)
stderr.write(bytes("ERROR: %s" % str(e), 'UTF-8'))
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True)