def set_prj_pseudometa(self, project, meta): """ Sets project description to the YAML of the provided object :param project: project to save into :param meta: data to save """ # Get current metadata url = make_meta_url('prj', project, self.apiurl) root = ET.parse(http_GET(url)).getroot() # Find description description = root.find('description') # Order the requests and replace it with yaml meta['requests'] = sorted(meta['requests'], key=lambda x: x['id']) description.text = yaml.dump(meta) # Find title title = root.find('title') # Put something nice into title as well new_title = [] for request in meta['requests']: new_title.append(request['package']) nt = ', '.join(sorted(new_title)) title.text = nt[:240] # Write XML back url = make_meta_url('prj', project, self.apiurl, force=True) http_PUT(url, data=ET.tostring(root))
def set_prj_pseudometa(self, project, meta): """ Sets project description to the YAML of the provided object :param project: project to save into :param meta: data to save """ # Get current metadata url = make_meta_url('prj', project, self.apiurl) root = ET.parse(http_GET(url)).getroot() # Find description description = root.find('description') # Order the requests and replace it with yaml meta['requests'] = sorted(meta['requests'], key=lambda x: x['id']) description.text = yaml.dump(meta) # Find title title = root.find('title') # Put something nice into title as well new_title = [] for request in meta['requests']: new_title.append(request['package']) nt = ', '.join(sorted(new_title)) title.text = nt[:240] # Write XML back url = make_meta_url('prj', project, self.apiurl, force=True) http_PUT(url, data=ET.tostring(root)) # Invalidate here the cache for this stating project self._invalidate_get_prj_pseudometa(project)
def create_adi_project(self, name): """Create an ADI project.""" if not name: name = self._candidate_adi_project() else: name = self.adi_prj_from_number(name) adi_projects = self.get_adi_projects() if name in adi_projects: raise Exception('Project {} already exist'.format(name)) meta = """ <project name="{}"> <title></title> <description></description> <publish> <disable/> </publish> <debuginfo> <enable/> </debuginfo> <repository name="standard"> <path project="{}" repository="standard"/> <arch>x86_64</arch> </repository> </project>""".format(name, self.project) url = make_meta_url('prj', name, self.apiurl) http_PUT(url, data=meta) # put twice because on first put, the API adds useless maintainer http_PUT(url, data=meta) return name
def create_package(self, prj, pkg): """Create package in the project.""" meta = '<package project="%s" name="%s">'\ '<title/><description/></package>' % (prj, pkg) url = core.make_meta_url("pkg", (quote_plus(prj), quote_plus(pkg)), self.apiurl, False) try: self.core_http(core.http_PUT, url, data=meta) except OSCError, err: raise ObsError("can't create %s/%s: %s" % (prj, pkg, err))
def watchProject(self, project): """ watchProject(project) Watch project """ username = self.getUserName() data = core.meta_exists('user', username, create_new=False, apiurl=self.apiurl) url = core.make_meta_url('user', username, self.apiurl) person = ElementTree.fromstring(''.join(data)) watchlist = person.find('watchlist') if not watchlist: watchlist = ElementTree.SubElement(person, 'watchlist') ElementTree.SubElement(watchlist, 'project', name=str(project)) f = metafile(url, ElementTree.tostring(person)) f.sync()
def unwatchProject(self, project): """ watchProject(project) Watch project """ username = self.getUserName() data = core.meta_exists('user', username, create_new=False, apiurl=self.apiurl) url = core.make_meta_url('user', username, self.apiurl) person = ElementTree.fromstring(''.join(data)) watchlist = person.find('watchlist') for node in watchlist: if node.get('name') == str(project): watchlist.remove(node) break f = metafile(url, ElementTree.tostring(person)) f.sync()
def get_prj_pseudometa(self, project): """ Gets project data from YAML in project description :param project: project to read data from :return structured object with metadata """ url = make_meta_url('prj', project, self.apiurl) f = http_GET(url) root = ET.parse(f).getroot() description = root.find('description') # If YAML parsing fails, load default # FIXME: Better handling of errors # * broken description # * directly linked packages # * removed linked packages try: data = yaml.load(description.text) except (TypeError, AttributeError): data = {} # make sure we have a requests field data['requests'] = data.get('requests', []) return data
M2Crypto.SSL.SSLError), err: raise ObsError("Can't set meta for %s: %s" % (target, str(err))) # don't need set project config if no src project if not src: return # copy project config try: config = core.show_project_conf(self.apiurl, src) except (urllib2.URLError, M2Crypto.m2urllib2.URLError, M2Crypto.SSL.SSLError), err: raise ObsError("Can't get config from project %s: %s" \ % (src, str(err))) url = core.make_meta_url("prjconf", quote_plus(target), self.apiurl, False) try: self.core_http(core.http_PUT, url, data=''.join(config)) except OSCError, err: raise ObsError("can't copy config from %s to %s: %s" \ % (src, target, err)) def delete_project(self, prj, force=False, msg=None): """Delete OBS project.""" query = {} if force: query['force'] = "1" if msg: query['comment'] = msg url = core.makeurl(self.apiurl, ['source', prj], query) try:
def get_meta(self, prj, pkg=None): """Get project/package meta.""" metatype, path_args = self.get_path(prj, pkg) url = core.make_meta_url(metatype, path_args, self.apiurl) return self.core_http(core.http_GET, url).read()
def set_meta(self, meta, prj, pkg=None): """Set project/package meta.""" metatype, path_args = self.get_path(prj, pkg) url = core.make_meta_url(metatype, path_args, self.apiurl) return self.core_http(core.http_PUT, url, data=meta)
def get_meta(self, prj, pkg=None): """Get project/package meta.""" metatype, path_args = self.get_path(prj, pkg) url = core.make_meta_url(metatype, path_args, self.apiurl) return self.core_http(core.http_GET, url)
M2Crypto.SSL.SSLError), err: raise ObsError("Can't set meta for %s: %s" % (target, str(err))) # don't need set project config if no src project if not src: return # copy project config try: config = core.show_project_conf(self.apiurl, src) except (urllib2.URLError, M2Crypto.m2urllib2.URLError, M2Crypto.SSL.SSLError), err: raise ObsError("Can't get config from project %s: %s" \ % (src, str(err))) url = core.make_meta_url("prjconf", quote_plus(target), self.apiurl, False) try: self.core_http(core.http_PUT, url, data=''.join(config)) except OSCError, err: raise ObsError("can't copy config from %s to %s: %s" \ % (src, target, err)) def exists(self, prj, pkg=''): """Check if project or package exists.""" metatype = 'prj' path_args = [core.quote_plus(prj)] if pkg: metatype = 'pkg' path_args.append(core.quote_plus(pkg)) err = None