def fromdata(binarytype, arch, name, version, release='', project='', repository=''): """Creates a new BuildDependency object. binarytype is the binarytype, arch the arch, name the name, version the version of the dependency. If binarytype is rpm and a release is not specified a ValueError is raised. Keyword arguments: release -- optional release (default: '') project -- the project to which the dependency belongs to (default: '') repository -- the repository where the dependency can be found (default: '') """ if binarytype == 'rpm' and not release: raise ValueError("binarytype rpm requires a release") xml = fromstring('<bdep />', bdep=BuildDependency) xml.set('binarytype', binarytype) xml.set('name', name) xml.set('version', version) if release: xml.set('release', release) xml.set('arch', arch) if project: xml.set('project', project) if repository: xml.set('repository', repository) return xml
def fromdata(binarytype, arch, name, version, release="", project="", repository=""): """Creates a new BuildDependency object. binarytype is the binarytype, arch the arch, name the name, version the version of the dependency. If binarytype is rpm and a release is not specified a ValueError is raised. Keyword arguments: release -- optional release (default: '') project -- the project to which the dependency belongs to (default: '') repository -- the repository where the dependency can be found (default: '') """ if binarytype == "rpm" and not release: raise ValueError("binarytype rpm requires a release") xml = fromstring("<bdep />", bdep=BuildDependency) xml.set("binarytype", binarytype) xml.set("name", name) xml.set("version", version) if release: xml.set("release", release) xml.set("arch", arch) if project: xml.set("project", project) if repository: xml.set("repository", repository) return xml
def __init__(self, path, name, initial_state, info=None, xml_data=None, **states): """Constructs a new XMLTransactionState object. Either info or xml_data has to be specified otherwise a ValueError is raised. Keyword arguments: info -- a FileUpdateInfo or FileCommitInfo object. xml_data -- xml string. states -- maps each wc file to its current state """ global _PKG_DATA if ((info is not None and xml_data) or (info is None and xml_data is None)): raise ValueError('either specify info or xml_data') super(XMLTransactionState, self).__init__(path) trans_dir = _storefile(self._path, XMLTransactionState.DIR) data_dir = os.path.join(trans_dir, _PKG_DATA) self._location = data_dir if xml_data: self._xml = fromstring(xml_data, entry=File, directory=Directory, linkinfo=Linkinfo) else: self.cleanup() os.mkdir(trans_dir) os.mkdir(data_dir) xml_data = ('<transaction name="%s" state="%s"/>' % (name, initial_state)) self._xml = fromstring(xml_data, entry=File, directory=Directory, linkinfo=Linkinfo) self._xml.append(self._xml.makeelement('states')) self._add_states(states) self._xml.append(self._xml.makeelement('info')) for listname in self._listnames(): self._add_list(listname, info) self._write()
def log(self, **kwargs): """Get the commit log. Keyword arguments: **kwargs -- optional parameters for the http request """ request = Osc.get_osc().get_reqobj() path = "/source/%s/%s/_history" % (self.project, self.name) if 'schema' not in kwargs: kwargs['schema'] = Package.HISTORY_SCHEMA f = request.get(path, **kwargs) return fromstring(f.read())
def _commit_filelist(self, xml_data, **kwargs): request = Osc.get_osc().get_reqobj() path = "/source/%s/%s" % (self.project, self.name) query = {'cmd': 'commitfilelist'} if self.is_expanded(): # the expanded check is not neccessary query['keeplink'] = '1' query['expand'] = '1' query.update(kwargs) f = request.post(path, data=xml_data, apiurl=self.apiurl, content_type='application/xml', **query) return fromstring(f.read(), directory=Directory, entry=File, linkinfo=Linkinfo)
def setUp(self): self.xml = fromstring(""" <root> <foo> <bar name="xyz"> <foo/> </bar> <bar/> <bar/> </foo> <foo/> </root> """)
def setUp(self): self.xml = fromstring( """ <root> <foo> <bar name="xyz"> <foo/> </bar> <bar/> <bar/> </foo> <foo/> </root> """ )
def list(self, **kwargs): """List all files for this package. Keyword arguments: **kwargs -- optional parameters for the http request """ request = Osc.get_osc().get_reqobj() path = "/source/%s/%s" % (self.project, self.name) if 'schema' not in kwargs: kwargs['schema'] = Package.LIST_SCHEMA f = request.get(path, **kwargs) directory = fromstring(f.read(), directory=Directory, entry=File, linkinfo=Linkinfo) # this is needed by the file class directory.set('project', self.project) return directory
def _create_xml(project, repository, arch, package, **kwargs): """Creates and returns a new BinaryList object. Keyword arguments: kwargs -- optional parameters for the http request (like query parameters) """ if "schema" not in kwargs: kwargs["schema"] = BinaryList.SCHEMA f = BinaryList._perform_request(project, repository, arch, package, **kwargs) bl = fromstring(f.read(), binarylist=BinaryList, binary=Binary) bl.set("project", project) bl.set("package", package) bl.set("repository", repository) bl.set("arch", arch) return bl
def _calculate_commit_filelist(self, cinfo): def _append_entry(xml, entry): xml.append(xml.makeelement('entry', name=entry.get('name'), md5=entry.get('md5'))) xml = fromstring('<directory/>') for filename in cinfo.unchanged: if self.status(filename) == 'A': # skip added files continue _append_entry(xml, self._files.find(filename)) for filename in cinfo.added + cinfo.modified: wc_filename = os.path.join(self.path, filename) md5 = file_md5(wc_filename) _append_entry(xml, {'name': filename, 'md5': md5}) xml_data = etree.tostring(xml, pretty_print=True) return xml_data
def _create_xml(project, repository, arch, package, **kwargs): """Creates and returns a new BinaryList object. Keyword arguments: kwargs -- optional parameters for the http request (like query parameters) """ if 'schema' not in kwargs: kwargs['schema'] = BinaryList.SCHEMA f = BinaryList._perform_request(project, repository, arch, package, **kwargs) bl = fromstring(f.read(), binarylist=BinaryList, binary=Binary) bl.set('project', project) bl.set('package', package) bl.set('repository', repository) bl.set('arch', arch) return bl
def list(self, **kwargs): """List all packages for this project. Keyword arguments: **kwargs -- optional parameters for the http request """ request = Osc.get_osc().get_reqobj() path = '/source/' + self.name if 'schema' not in kwargs: kwargs['schema'] = Project.LIST_SCHEMA f = request.get(path, **kwargs) entries = fromstring(f.read()) r = [] # using an xml representation for the <entry /> makes no # sense for e in entries.iterfind('entry'): r.append(Package(self.name, e.get('name'))) return r
def _calculate_commit_filelist(self, cinfo): def _append_entry(xml, entry): xml.append( xml.makeelement('entry', name=entry.get('name'), md5=entry.get('md5'))) xml = fromstring('<directory/>') for filename in cinfo.unchanged: if self.status(filename) == 'A': # skip added files continue _append_entry(xml, self._files.find(filename)) for filename in cinfo.added + cinfo.modified: wc_filename = os.path.join(self.path, filename) md5 = file_md5(wc_filename) _append_entry(xml, {'name': filename, 'md5': md5}) xml_data = etree.tostring(xml, pretty_print=True) return xml_data
def _find(path, xp, tag_class={}, **kwargs): """Returns a Collection with objects which match the xpath. path is the remote path which is used for the http request. xp is the xpath which is used for the search (either an Expression object or a string). Keyword arguments: tag_class -- a dict which maps tag names to classes (see util.xml.fromstring for the details) (default: {}) **kwargs -- optional parameters for the http request """ request = Osc.get_osc().get_reqobj() xpath = xp if hasattr(xp, 'tostring'): xpath = xp.tostring() f = request.get(path, match=xpath, **kwargs) return fromstring(f.read(), **tag_class)
def builddepinfo(self, reverse=False, **kwargs): """Get the builddepinfo. If reverse is True a reverse builddepinfo lookup is done. Keyword arguments: **kwargs -- optional parameters for the http request """ package = self.package or "_repository" path = "/build/%s/%s/%s/%s/_builddepinfo" % (self.project, self.repository, self.arch, package) request = Osc.get_osc().get_reqobj() view = "pkgnames" if reverse: view = "revpkgnames" if "schema" not in kwargs: kwargs["schema"] = BuildResult.BUILDDEPINFO_SCHEMA f = request.get(path, view=view, **kwargs) # no custom parser needed atm return fromstring(f.read())
def __init__(self, project="", package="", repository="", arch="", xml_data="", binarytype="", data=None, **kwargs): """Constructs a new BuildInfo object. A ValueError is raised if xml_data is specified and project or package or repository or arch. A ValueError is raised if no binarytype is specified and the buildinfo has no file element. Keyword arguments: project -- the project (default: '') package -- the package (default: '') repository -- the repository (default: '_repository') arch -- the architecture (default: '') xml_data -- a xml str which contains a buildinfo element (default: '') binarytype -- the package type of the bdep elements (rpm, deb etc.) (default: '') data -- a specfile or cpio archive which is POSTed to the server (default: None) **kwargs -- optional parameters for the http request """ if ( (project or package or repository or arch) and xml_data or not (project and repository and arch) and not xml_data ): msg = "Either project, package, repository, arch or xml_data" raise ValueError(msg) elif not xml_data: package = package or "_repository" path = "/build/%s/%s/%s/%s/_buildinfo" % (project, repository, arch, package) request = Osc.get_osc().get_reqobj() if data is None: f = request.get(path, **kwargs) else: f = request.post(path, data=data, **kwargs) xml_data = f.read() self._xml = fromstring(xml_data, bdep=BuildDependency) self._calculate_binarytype(binarytype)
def result(self, **kwargs): """Get the build result. Keyword arguments: package -- limit results to package (default: '') repository -- limit results repository arch -- limit results to arch kwargs -- optional arguments for the http request Note: package, repository and arch may override the current package, repository and arch instance attributes. """ package = kwargs.pop("package", self.package) repository = kwargs.pop("repository", self.repository) arch = kwargs.pop("arch", self.arch) request = Osc.get_osc().get_reqobj() path = "/build/%s/_result" % self.project if "schema" not in kwargs: kwargs["schema"] = BuildResult.RESULT_SCHEMA f = request.get(path, package=package, repository=repository, arch=arch, **kwargs) results = fromstring(f.read(), status=Status) return results
def builddepinfo(self, reverse=False, **kwargs): """Get the builddepinfo. If reverse is True a reverse builddepinfo lookup is done. Keyword arguments: **kwargs -- optional parameters for the http request """ package = self.package or '_repository' path = "/build/%s/%s/%s/%s/_builddepinfo" % (self.project, self.repository, self.arch, package) request = Osc.get_osc().get_reqobj() view = 'pkgnames' if reverse: view = 'revpkgnames' if 'schema' not in kwargs: kwargs['schema'] = BuildResult.BUILDDEPINFO_SCHEMA f = request.get(path, view=view, **kwargs) # no custom parser needed atm return fromstring(f.read())
def __init__(self, project='', package='', repository='', arch='', xml_data='', binarytype='', data=None, **kwargs): """Constructs a new BuildInfo object. A ValueError is raised if xml_data is specified and project or package or repository or arch. A ValueError is raised if no binarytype is specified and the buildinfo has no file element. Keyword arguments: project -- the project (default: '') package -- the package (default: '') repository -- the repository (default: '_repository') arch -- the architecture (default: '') xml_data -- a xml str which contains a buildinfo element (default: '') binarytype -- the package type of the bdep elements (rpm, deb etc.) (default: '') data -- a specfile or cpio archive which is POSTed to the server (default: None) **kwargs -- optional parameters for the http request """ if ((project or package or repository or arch) and xml_data or not (project and repository and arch) and not xml_data): msg = 'Either project, package, repository, arch or xml_data' raise ValueError(msg) elif not xml_data: package = package or '_repository' path = "/build/%s/%s/%s/%s/_buildinfo" % (project, repository, arch, package) request = Osc.get_osc().get_reqobj() if data is None: f = request.get(path, **kwargs) else: f = request.post(path, data=data, **kwargs) xml_data = f.read() self._xml = fromstring(xml_data, bdep=BuildDependency) self._calculate_binarytype(binarytype)
def result(self, **kwargs): """Get the build result. Keyword arguments: package -- limit results to package (default: '') repository -- limit results repository arch -- limit results to arch kwargs -- optional arguments for the http request Note: package, repository and arch may override the current package, repository and arch instance attributes. """ package = kwargs.pop('package', self.package) repository = kwargs.pop('repository', self.repository) arch = kwargs.pop('arch', self.arch) request = Osc.get_osc().get_reqobj() path = "/build/%s/_result" % self.project if 'schema' not in kwargs: kwargs['schema'] = BuildResult.RESULT_SCHEMA f = request.get(path, package=package, repository=repository, arch=arch, **kwargs) results = fromstring(f.read(), status=Status) return results
def _fromstring(cls, data): return fromstring(data)
def _fromstring(cls, data): return fromstring(data, entry=File, directory=Directory, linkinfo=Linkinfo)
def _read_xml_data(self, xml_data): parser = self._get_parser() self._xml = fromstring(xml_data, parser=parser)