def branch(self, projectBranch): branch = self.distro.branch(projectBranch) logger.info('Branching %r/%s as %r/%s', self.distro, self.name, branch, self.name) obsURL = self.distro.config('obs', 'url') obsProject = self.distro.obsProject(self.dist, self.component) targetProject = branch.obsProject(self.dist, self.component) logger.debug('- OBS URL: %r', obsURL) logger.debug('- Source OBS project: %r', obsProject) logger.debug('- Source OBS package: %r', self.obsName) logger.debug('- Target OBS project: %r', targetProject) logger.debug('- Message: %r', 'Branch for %s' % (str(self))) result = osccore.branch_pkg(obsURL, obsProject, self.obsName, target_project=targetProject, nodevelproject=False, msg='Branch for %s' % (str(self)), force=False, return_existing=True) if result[0]: logger.debug('Branched package already exists') else: logger.debug('Branched package was created') if (result[1] != targetProject or result[2] != self.obsName or result[3] not in (None, obsProject) or result[4] not in (None, self.obsName)): logger.warning("Unexpected result from branch_pkg:") logger.warning("- expected source project: %r or None", obsProject) logger.warning("- result's source project: %r", result[3]) logger.warning("- expected source package: %r or None", self.obsName) logger.warning("- result's source package: %r", result[4]) logger.warning("- expected target project: %r", targetProject) logger.warning("- result's target project: %r", result[1]) logger.warning("- expected target package: %r", self.obsName) logger.warning("- result's target package: %r", result[2]) return branch.package(self.dist, self.component, self.name)
def branch(self, projectBranch): branch = self.distro.branch(projectBranch) logger.info('Branching %r/%s as %r/%s', self.distro, self.name, branch, self.name) obsURL = self.distro.config('obs', 'url') obsProject = self.distro.obsProject(self.dist,self.component) targetProject = branch.obsProject(self.dist, self.component) logger.debug('- OBS URL: %r', obsURL) logger.debug('- Source OBS project: %r', obsProject) logger.debug('- Source OBS package: %r', self.obsName) logger.debug('- Target OBS project: %r', targetProject) logger.debug('- Message: %r', 'Branch for %s' % (str(self))) result = osccore.branch_pkg(obsURL, obsProject, self.obsName, target_project=targetProject, nodevelproject=False, msg='Branch for %s'%(str(self)), force=False, return_existing=True) if result[0]: logger.debug('Branched package already exists') else: logger.debug('Branched package was created') if (result[1] != targetProject or result[2] != self.obsName or result[3] not in (None, obsProject) or result[4] not in (None, self.obsName)): logger.warning("Unexpected result from branch_pkg:") logger.warning("- expected source project: %r or None", obsProject) logger.warning("- result's source project: %r", result[3]) logger.warning("- expected source package: %r or None", self.obsName) logger.warning("- result's source package: %r", result[4]) logger.warning("- expected target project: %r", targetProject) logger.warning("- result's target project: %r", result[1]) logger.warning("- expected target package: %r", self.obsName) logger.warning("- result's target package: %r", result[2]) return branch.package(self.dist, self.component, self.name)
def handle_wi(self, wid): """ Workitem handling function """ wid.result = False f = wid.fields p = wid.params project = None package = None if f.project and f.package: project = f.project package = f.package if p.project and p.package: project = p.project package = p.package if not project or not package: raise RuntimeError( "Missing mandatory field or parameter: package, project") if not f.repourl and not p.repourl: raise RuntimeError("Missing mandatory field or parameter: repourl") params = {} if f.repourl: params["url"] = f.repourl if p.repourl: params["url"] = p.repourl params["service"], params["repo"] = find_service_repo(params["url"]) if f.branch: params["branch"] = f.branch if p.branch: params["branch"] = p.branch params["revision"] = "" if f.revision: params["revision"] = f.revision if p.revision: params["revision"] = p.revision params["token"] = "" params["debian"] = "" params["dumb"] = "" if f.token: params["token"] = f.token if p.token: params["token"] = p.token if p.debian: params["debian"] = p.debian if f.debian: params["debian"] = f.debian if p.dumb: params["dumb"] = p.dumb if f.dumb: params["dumb"] = f.dumb if "branch" in params and params["branch"].startswith("pkg-"): if not "service" in params or not "repo" in params: raise RuntimeError( "Service/Repo not found in repourl %s " % p.repourl) service = git_pkg_service else: service = tar_git_service # the simple approach doesn't work with project links # if self.obs.isNewPackage(project, package): # self.obs.getCreatePackage(str(project), str(package)) # else: try: pkginfo = core.show_files_meta( self.obs.apiurl, str(project), str(package), expand=False, meta=True) if "<entry" not in pkginfo: # This is a link and it needs branching from the linked project # so grab the meta and extract the project from the link print "Found %s as a link in %s" % (package, project) x = etree.fromstring( "".join(core.show_project_meta(self.obs.apiurl, project))) l = x.find('link') if l is None: raise Exception( "Expected a <link> in project %s." % project) print "Got a link %s" % l linked_project = l.get('project') print "Branching %s to overwrite _service" % package core.branch_pkg(self.obs.apiurl, linked_project, str(package), target_project=str(project)) except Exception, exc: print "Doing a metatype pkg add because I caught %s" % exc print "Creating package %s in project %s" % (package, project) data = core.metatypes['pkg']['template'] data = StringIO( data % {"name": str(package), "user": self.obs.getUserName()}).readlines() u = core.makeurl( self.obs.apiurl, ['source', str(project), str(package), "_meta"]) x = core.http_PUT(u, data="".join(data)) print "HTTP PUT result of pkg add : %s" % x
def handle_wi(self, wid): """ Workitem handling function """ wid.result = False f = wid.fields p = wid.params project = None package = None if f.project and f.package: project = f.project package = f.package if p.project and p.package: project = p.project package = p.package if not project or not package: raise RuntimeError( "Missing mandatory field or parameter: package, project") if not f.repourl and not p.repourl: raise RuntimeError("Missing mandatory field or parameter: repourl") params = {} if f.repourl: params["url"] = f.repourl if p.repourl: params["url"] = p.repourl params["service"], params["repo"] = find_service_repo(params["url"]) if f.branch: params["branch"] = f.branch if p.branch: params["branch"] = p.branch params["revision"] = "" if f.revision: params["revision"] = f.revision if p.revision: params["revision"] = p.revision params["token"] = "" params["debian"] = "" params["dumb"] = "" if f.token: params["token"] = f.token if p.token: params["token"] = p.token if p.debian: params["debian"] = p.debian if f.debian: params["debian"] = f.debian if p.dumb: params["dumb"] = p.dumb if f.dumb: params["dumb"] = f.dumb if "branch" in params and params["branch"].startswith("pkg-"): if "service" not in params or "repo" not in params: raise RuntimeError("Service/Repo not found in repourl %s " % p.repourl) service = git_pkg_service else: service = tar_git_service # the simple approach doesn't work with project links # if self.obs.isNewPackage(project, package): # self.obs.getCreatePackage(str(project), str(package)) # else: try: pkginfo = core.show_files_meta(self.obs.apiurl, str(project), str(package), expand=False, meta=True) if "<entry" not in pkginfo: # This is a link and it needs branching from the linked project # so grab the meta and extract the project from the link self.log.debug("Found %s as a link in %s" % (package, project)) x = etree.fromstring("".join( core.show_project_meta(self.obs.apiurl, project))) link = x.find('link') if link is None: raise Exception("Expected a <link> in project %s." % project) self.log.debug("Got a link %s" % link) linked_project = link.get('project') self.log.debug("Branching %s to overwrite _service" % package) core.branch_pkg(self.obs.apiurl, linked_project, str(package), target_project=str(project)) except Exception as exc: self.log.warn("Doing a metatype pkg add because I caught %s" % exc) self.log.warn("Creating package %s in project %s" % (package, project)) data = core.metatypes['pkg']['template'] data = StringIO(data % { "name": str(package), "user": self.obs.getUserName() }).readlines() u = core.makeurl( self.obs.apiurl, ['source', str(project), str(package), "_meta"]) x = core.http_PUT(u, data="".join(data)) self.log.debug("HTTP PUT result of pkg add : %s" % x) # Set any constraint before we set the service file constraint_xml = self.make_constraint(package) if constraint_xml: # obs module only exposed the putFile by filepath so # this is a reimplement to avoid writing a tmpfile u = core.makeurl(self.obs.apiurl, ['source', project, package, "_constraints"]) core.http_PUT(u, data=constraint_xml) self.log.info("New _constraints file:\n%s" % constraint_xml) else: self.log.info("No _constraints for %s" % package) # Start with an empty XML doc try: # to get any existing _service file. # We use expand=0 as otherwise a failed service run won't # return the _service file self.log.debug("Trying to get _service file for %s/%s" % (project, package)) services_xml = self.obs.getFile(project, package, "_service", expand=0) except urllib2.HTTPError as e: self.log.debug( "Exception %s trying to get _service file for %s/%s" % (e, project, package)) if e.code == 404: services_xml = empty_service elif e.code == 400: # HTTP Error 400: service in progress error wid.result = True self.log.warn( "Service in progress, could not get _service file. " "Not triggering another run.") return else: raise e services_xml = services_xml.strip() or empty_service # Replace the matching one: try: services = etree.fromstring(services_xml) except etree.XMLSyntaxError as e: self.log.exception("Creating services xml failed") raise # Create our new service (not services anymore) new_service_xml = service % params new_service = etree.fromstring(new_service_xml) svcname = new_service.find(".").get("name") old_service = services.find("./service[@name='%s']" % svcname) if old_service is not None: services.replace(old_service, new_service) else: services.append(new_service) svc_file = etree.tostring(services, pretty_print=True) self.log.debug("New _service file:\n%s" % svc_file) # And send our new service file self.obs.setupService(project, package, svc_file) wid.result = True
def handle_wi(self, wid): """ Workitem handling function """ wid.result = False f = wid.fields p = wid.params project = None package = None if f.project and f.package: project = f.project package = f.package if p.project and p.package: project = p.project package = p.package if not project or not package: raise RuntimeError( "Missing mandatory field or parameter: package, project") if not f.repourl and not p.repourl: raise RuntimeError("Missing mandatory field or parameter: repourl") params = {} if f.repourl: params["url"] = f.repourl if p.repourl: params["url"] = p.repourl params["service"], params["repo"] = find_service_repo(params["url"]) if f.branch: params["branch"] = f.branch if p.branch: params["branch"] = p.branch params["revision"] = "" if f.revision: params["revision"] = f.revision if p.revision: params["revision"] = p.revision params["token"] = "" params["debian"] = "" params["dumb"] = "" if f.token: params["token"] = f.token if p.token: params["token"] = p.token if p.debian: params["debian"] = p.debian if f.debian: params["debian"] = f.debian if p.dumb: params["dumb"] = p.dumb if f.dumb: params["dumb"] = f.dumb if "branch" in params and params["branch"].startswith("pkg-"): if "service" not in params or "repo" not in params: raise RuntimeError( "Service/Repo not found in repourl %s " % p.repourl) service = git_pkg_service else: service = tar_git_service # the simple approach doesn't work with project links # if self.obs.isNewPackage(project, package): # self.obs.getCreatePackage(str(project), str(package)) # else: try: pkginfo = core.show_files_meta( self.obs.apiurl, str(project), str(package), expand=False, meta=True) if "<entry" not in pkginfo: # This is a link and it needs branching from the linked project # so grab the meta and extract the project from the link print("Found %s as a link in %s" % (package, project)) x = etree.fromstring( "".join(core.show_project_meta(self.obs.apiurl, project))) link = x.find('link') if link is None: raise Exception( "Expected a <link> in project %s." % project) print("Got a link %s" % link) linked_project = link.get('project') print("Branching %s to overwrite _service" % package) core.branch_pkg(self.obs.apiurl, linked_project, str(package), target_project=str(project)) except Exception as exc: print("Doing a metatype pkg add because I caught %s" % exc) print("Creating package %s in project %s" % (package, project)) data = core.metatypes['pkg']['template'] data = StringIO( data % { "name": str(package), "user": self.obs.getUserName()} ).readlines() u = core.makeurl( self.obs.apiurl, ['source', str(project), str(package), "_meta"]) x = core.http_PUT(u, data="".join(data)) print("HTTP PUT result of pkg add : %s" % x) # Set any constraint before we set the service file constraint_xml = make_constraint(package) if constraint_xml: # obs module only exposed the putFile by filepath so # this is a reimplement to avoid writing a tmpfile u = core.makeurl(self.obs.apiurl, ['source', project, package, "_constraints"]) core.http_PUT(u, data=constraint_xml) print "New _constraints file:\n%s" % constraint_xml else: print "No _constraints for %s" % package # Start with an empty XML doc try: # to get any existing _service file. # We use expand=0 as otherwise a failed service run won't # return the _service file print("Trying to get _service file for %s/%s" % (project, package)) services_xml = self.obs.getFile( project, package, "_service", expand=0) except urllib2.HTTPError as e: print("Exception %s trying to get _service file for %s/%s" % (e, project, package)) if e.code == 404: services_xml = empty_service elif e.code == 400: # HTTP Error 400: service in progress error wid.result = True print("Service in progress, could not get _service file. " "Not triggering another run.") return else: raise e services_xml = services_xml.strip() or empty_service # Replace the matching one: try: services = etree.fromstring(services_xml) except etree.XMLSyntaxError as e: print(e) raise # Create our new service (not services anymore) new_service_xml = service % params new_service = etree.fromstring(new_service_xml) svcname = new_service.find(".").get("name") old_service = services.find("./service[@name='%s']" % svcname) if old_service is not None: services.replace(old_service, new_service) else: services.append(new_service) svc_file = etree.tostring(services, pretty_print=True) print("New _service file:\n%s" % svc_file) # And send our new service file self.obs.setupService(project, package, svc_file) wid.result = True