diff options
Diffstat (limited to 'buildbot_gentoo_ci/steps/package.py')
-rw-r--r-- | buildbot_gentoo_ci/steps/package.py | 166 |
1 files changed, 159 insertions, 7 deletions
diff --git a/buildbot_gentoo_ci/steps/package.py b/buildbot_gentoo_ci/steps/package.py index 9fc59e8..13eafa2 100644 --- a/buildbot_gentoo_ci/steps/package.py +++ b/buildbot_gentoo_ci/steps/package.py @@ -4,9 +4,7 @@ import re import os -from portage.xml.metadata import MetaDataXML -from portage.checksum import perform_checksum -from portage.versions import catpkgsplit +import xml.etree.ElementTree as etree from twisted.internet import defer from twisted.python import log @@ -14,6 +12,7 @@ from twisted.python import log from buildbot.process.buildstep import BuildStep from buildbot.process.results import SUCCESS from buildbot.process.results import FAILURE +from buildbot.process import remotecommand from buildbot.plugins import steps class SetupPropertys(BuildStep): @@ -67,6 +66,161 @@ class AddPackage(BuildStep): self.setProperty("package_data", self.package_data, 'package_data') return SUCCESS +class UpdateEmails(BuildStep): + def __init__(self, **kwargs): + super().__init__(**kwargs) + + name = 'UpdateEmails' + description = 'Running' + descriptionDone = 'Ran' + descriptionSuffix = None + haltOnFailure = True + flunkOnFailure = True + + @defer.inlineCallbacks + def run(self): + self.gentooci = self.master.namedServices['services'].namedServices['gentooci'] + packages_emails = yield self.gentooci.db.packages.getEmailsIdsByPackageUuid(self.getProperty("package_data")['uuid']) + if packages_emails != []: + yield self.gentooci.db.packages.delPackageEmail(self.getProperty("package_data")['uuid']) + # update email + for maintainer in self.getProperty("maintainers"): + print(maintainer) + email_data = yield self.gentooci.db.packages.getEmailIdByEmail(maintainer['email']) + print(email_data) + if email_data is None: + email_id = yield self.gentooci.db.packages.addEmail(maintainer['email']) + print(email_id) + else: + email_id = email_data['id'] + if maintainer['proxied'] is None: + proxied = 'no' + else: + proxied = maintainer['proxied'] + res = yield self.gentooci.db.packages.addPackageEmail( + email_id, + self.getProperty("package_data")['uuid'], + maintainer['type'], + proxied + ) + print(res) + return SUCCESS + +class ReadMetadataXML(BuildStep): + def __init__(self, **kwargs): + super().__init__(**kwargs) + + name = 'ReadMetadataXML' + description = 'Running' + descriptionDone = 'Ran' + descriptionSuffix = None + haltOnFailure = True + flunkOnFailure = True + + @defer.inlineCallbacks + def run(self): + self._xml_tree = etree.fromstring(self.getProperty("metadata_xml")) + # get maintainer + self.maintainers = [] + for maintainer in self._xml_tree.findall('maintainer'): + self.maintainers.append(dict( + type=maintainer.get('type'), + proxied=maintainer.get('proxied'), + email=maintainer.find('email').text, + )) + print(self.maintainers) + self.setProperty("maintainers", self.maintainers, 'maintainers') + yield self.build.addStepsAfterCurrentStep([UpdateEmails()]) + # update email + return SUCCESS + +class CheckSha256Metadata(BuildStep): + def __init__(self, **kwargs): + super().__init__(**kwargs) + + name = 'CheckSha256Metadata' + description = 'Running' + descriptionDone = 'Ran' + descriptionSuffix = None + haltOnFailure = True + flunkOnFailure = True + + @defer.inlineCallbacks + def run(self): + # if checksum diff update + self.gentooci = self.master.namedServices['services'].namedServices['gentooci'] + sha256sum_metadata = self.getProperty("sha256sum_metadata").split()[0] + print(sha256sum_metadata) + package_metadata_data_updated = False + self.package_metadata_data = yield self.gentooci.db.packages.getPackageMetadataByPackageUuid(self.getProperty("package_data")['uuid']) + print(self.package_metadata_data) + if self.package_metadata_data is None: + res = yield self.gentooci.db.packages.addMetadata( + self.getProperty("package_data")['uuid'], + sha256sum_metadata + ) + print(res) + package_metadata_data_updated = True + elif self.package_metadata_data['sha256'] != sha256sum_metadata: + # update sha256 + package_metadata_data_updated = True + if package_metadata_data_updated: + yield self.build.addStepsAfterCurrentStep([ + steps.SetPropertyFromCommand( + name = 'CatMetadataFile', + haltOnFailure = True, + flunkOnFailure = True, + command=['cat', self.getProperty("metadata_file")], + strip=False, + property='metadata_xml' + ), + ReadMetadataXML(), + ]) + return SUCCESS + +class CheckMetadataPackagePath(BuildStep): + def __init__(self, **kwargs): + super().__init__(**kwargs) + + name = 'CheckMetadataPackagePath' + description = 'Running' + descriptionDone = 'Ran' + descriptionSuffix = None + haltOnFailure = True + flunkOnFailure = True + + @defer.inlineCallbacks + def run(self): + # set metadata.xml path + self.repository_basedir = yield os.path.join(self.getProperty("worker_basedir"), self.getProperty('portage_repos_path')) + print(self.repository_basedir) + self.repository_path = yield os.path.join(self.repository_basedir, self.getProperty("repository_data")['name']) + print(self.repository_path) + self.cp_path = yield os.path.join(self.repository_path, self.getProperty("change_data")['cp']) + print(self.cp_path) + self.metadata_file = yield '/'.join([self.cp_path, 'metadata.xml']) + print(self.metadata_file) + # check file exist + cmd = remotecommand.RemoteCommand('stat', {'file': self.metadata_file}) + yield self.runCommand(cmd) + if cmd.didFail(): + return FAILURE + self.setProperty("metadata_file", self.metadata_file, 'metadata_file') + # checksum on file + yield self.build.addStepsAfterCurrentStep([ + steps.SetPropertyFromCommand( + name = 'ChecksumMetadataPackage', + haltOnFailure = True, + flunkOnFailure = True, + command=['sha256sum', self.metadata_file], + workdir=self.repository_path, + strip=False, + property='sha256sum_metadata' + ), + CheckSha256Metadata(), + ]) + return SUCCESS + class CheckP(BuildStep): def __init__(self, **kwargs): super().__init__(**kwargs) @@ -90,10 +244,8 @@ class CheckP(BuildStep): if self.package_data is None: self.setProperty("package", self.package, 'package') yield self.build.addStepsAfterCurrentStep([AddPackage()]) - #yield self.build.addStepsAfterLastStep([AddMetadataPackage()]) - return SUCCESS - self.setProperty("package_data", self.package_data, 'package_data') - #yield self.build.addStepsAfterLastStep([CheckPathPackage()]) + else: + self.setProperty("package_data", self.package_data, 'package_data') return SUCCESS class TriggerCheckForV(BuildStep): |