def _bump_version(self, release=False, zstream=False): """ Bump up the package version in the spec file. Set release to True to bump the package release instead. Checks for the keep version option and if found, won't actually bump the version or release. """ old_version = get_latest_tagged_version(self.project_name) if old_version is None: old_version = "untagged" if not self.keep_version: version_regex = re.compile("^(version:\s*)(.+)$", re.IGNORECASE) release_regex = re.compile("^(release:\s*)(.+)$", re.IGNORECASE) in_f = open(self.spec_file, 'r') out_f = open(self.spec_file + ".new", 'w') for line in in_f.readlines(): version_match = re.match(version_regex, line) release_match = re.match(release_regex, line) if version_match and not zstream and not release: current_version = version_match.group(2) if hasattr(self, '_use_version'): updated_content = self._use_version else: updated_content = increase_version(current_version) line = "".join([version_match.group(1), updated_content, "\n"]) elif release_match: current_release = release_match.group(2) if hasattr(self, '_use_release'): updated_content = self._use_release elif release: updated_content = increase_version(current_release) elif zstream: updated_content = increase_zstream(current_release) else: updated_content = reset_release(current_release) line = "".join([release_match.group(1), updated_content, "\n"]) out_f.write(line) in_f.close() out_f.close() shutil.move(self.spec_file + ".new", self.spec_file) new_version = get_spec_version_and_release(self.full_project_dir, self.spec_file_name) if new_version.strip() == "": msg = "Error getting bumped package version, try: \n" msg = msg + " 'rpm -q --specfile %s'" % self.spec_file error_out(msg) info_out("Tagging new version of %s: %s -> %s" % (self.project_name, old_version, new_version)) return new_version
def _bump_version(self, release=False, zstream=False): """ Bump version in main and Fedora spec file Version and Release in Fedora spec file are always updated accordingly to main spec file """ # Version and Release without dist tag old_version, old_release = get_spec_version_and_release( self.full_project_dir, self.spec_file_name).split('-') old_release += '%{?dist}' new_version = super(RestraintVersionTagger, self)._bump_version(release, zstream) if not self.keep_version: version_regex = re.compile("^(version:\s*)(.+)$", re.IGNORECASE) release_regex = re.compile("^(release:\s*)(.+)$", re.IGNORECASE) in_f = open(self.fedora_spec_file, 'r') out_f = open(self.fedora_spec_file + ".new", 'w') for line in in_f.readlines(): version_match = re.match(version_regex, line) release_match = re.match(release_regex, line) if version_match and not zstream and not release: if hasattr(self, '_use_version'): updated_content = self._use_version else: updated_content = increase_version(old_version) line = "".join( [version_match.group(1), updated_content, "\n"]) elif release_match: if hasattr(self, '_use_release'): updated_content = self._use_release elif release: updated_content = increase_version(old_release) elif zstream: updated_content = increase_zstream(old_release) else: updated_content = reset_release(old_release) line = "".join( [release_match.group(1), updated_content, "\n"]) out_f.write(line) in_f.close() out_f.close() shutil.move(self.fedora_spec_file + ".new", self.fedora_spec_file) return new_version
def test_reset_release(self): line = "2" expected = "1" self.assertEquals(expected, reset_release(line))
def test_reset_release_with_more_rpm_cruft(self): line = "2.beta" expected = "1.beta" self.assertEquals(expected, reset_release(line))
def test_reset_release_with_rpm_cruft(self): line = "2%{?dist}" expected = "1%{?dist}" self.assertEquals(expected, reset_release(line))
def _bump_version(self, release=False, zstream=False, force=False): """ Bump up the package version in the spec file. Set release to True to bump the package release instead. Checks for the keep version option and if found, won't actually bump the version or release. """ old_version = get_latest_tagged_version(self.project_name) if old_version == None: old_version = "untagged" if not self.keep_version: version_regex = re.compile("^(version:\s*)(.+)$", re.IGNORECASE) release_regex = re.compile("^(release:\s*)(.+)$", re.IGNORECASE) in_f = open(self.spec_file, 'r') out_f = open(self.spec_file + ".new", 'w') for line in in_f.readlines(): if release: match = re.match(release_regex, line) if match: line = "".join((match.group(1), increase_version(match.group(2)), "\n" )) elif zstream: match = re.match(release_regex, line) if match: line = "".join((match.group(1), increase_zstream(match.group(2)), "\n" )) elif force: match = re.match(version_regex, line) if match: line = "".join((match.group(1), self._use_version, "\n" )) match = re.match(release_regex, line) if match: line = "".join((match.group(1), reset_release(match.group(2)), "\n" )) else: match = re.match(version_regex, line) if match: line = "".join((match.group(1), increase_version(match.group(2)), "\n" )) match = re.match(release_regex, line) if match: line = "".join((match.group(1), reset_release(match.group(2)), "\n" )) out_f.write(line) in_f.close() out_f.close() shutil.move(self.spec_file + ".new", self.spec_file) new_version = self._get_spec_version_and_release() if new_version.strip() == "": msg = "Error getting bumped package version, try: \n" msg = msg + " 'rpm -q --specfile %s'" % self.spec_file error_out(msg) print("Tagging new version of %s: %s -> %s" % (self.project_name, old_version, new_version)) return new_version