diff --git a/osclib/freeze_command.py b/osclib/freeze_command.py index 1e008580..865ea4e5 100644 --- a/osclib/freeze_command.py +++ b/osclib/freeze_command.py @@ -122,6 +122,23 @@ class FreezeCommand(object): self.set_links() self.freeze_prjlinks() + # Update the version information found in the Test-DVD package, to match openSUSE-release + version = self.api.package_version(prj, 'openSUSE-release') + self.update_product_version(prj + ':DVD', 'Test-DVD-x86_64', version) + + def update_product_version(self, project, product, version): + if not self.api.item_exists(project, product): + return None + + kiwifile = self.api.load_file_content(project, product, 'PRODUCT-x86_64.kiwi') + root = ET.fromstring(kiwifile) + prodvar = root.find(".//productvar[@name='VERSION']") + prodvar.text = version + prodinfoversion = root.find(".//productinfo[@name='VERSION']") + prodinfoversion.text = version + + self.api.save_file_content(project, product, 'PRODUCT-x86_64.kiwi', ET.tostring(root)) + def prj_meta_for_bootstrap_copy(self, prj): root = ET.Element('project', {'name': prj}) ET.SubElement(root, 'title') diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index eaa0476b..337d35cc 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -907,6 +907,50 @@ class StagingAPI(object): return False return True + def package_version(self, project, package): + """ + Return the version of a package, None in case the package does not exist + The first non-commented Version: tag found is used. + :param project: the project the package resides in + :param package: the package to check + :param product: if passed, the package to be checked is considered to be part of _product + """ + if not self.item_exists(project, package): + return None + + version = None + + specfile = self.api.load_file_content(project, package, '{}.spec'.format(package)) + if specfile: + try: + version = re.findall("^Version:(.*)",specfile,re.MULTILINE)[0].strip() + except: + pass + return version + + def load_file_content(self, project, package, filename): + """ + Load the content of a file and return the content as data. If the package is a link, it will be expanded + :param project: The project to query + :param package: The package to quert + :param filename: The filename to query + """ + url = self.api.makeurl(['source', project, package, '{}?expand=1'.format(filename)]) + try: + return http_GET(url).read() + except: + return None + + def save_file_content(self, project, package, filename, content): + """ + Save content to a project/package/file + :param project: The project containing the package + :param package: the package to update + :param filename: the filename to save the data to + :param content: the content to write to the file + """ + url = self.api.makeurl(['source', project, package, filename]) + http_PUT(url + '?comment=scripted+update', data=content) def update_status_comments(self, project, command): """