Exemple #1
0
    def create_project(self, target, src=None, rewrite=False,
                       description='', linkto='', linkedbuild=''):
        """
        Create new OBS project based on existing project.
        Copy config and repositories from src project to target
        if src exists.
        """

        if src and not self.exists(src):
            raise ObsError('base project: %s not exists' % src)

        if self.exists(target):
            logger.warning('target project: %s exists' % target)
            if rewrite:
                logger.warning('rewriting target project %s' % target)
            else:
                return

        # Create target meta
        meta = '<project name="%s"><title></title>'\
	       '<description>%s</description>'\
               '<person role="maintainer" userid="%s"/>' % \
               (target, description, conf.get_apiurl_usr(self.apiurl))
        if linkto:
            meta += '<link project="%s"/>' % linkto

        # Collect source repos if src project exist
        if src:
            # Copy debuginfo, build, useforbuild and publish meta
            meta += self.get_tags(src, ['debuginfo', 'build',
                                        'useforbuild', 'publish'])
            # Copy repos to target
            repos = self.get_repos_of_project(src)
            for name in repos:
                if linkedbuild:
                    meta += '<repository name="%s" linkedbuild="%s">' % \
                                (name, linkedbuild)
                else:
                    meta += '<repository name="%s">' % name
                meta += '<path project="%s" repository="%s" />' % (src, name)
                for arch in repos[name]:
                    meta += "<arch>%s</arch>\n" % arch
                meta += "</repository>\n"
        else:
            logger.warning('no project repos in target project, please add '
                           'repos from OBS webUI manually, or specify base '
                           'project with -B <base_prj>, then gbs can help to '
                           'set repos using the settings of the specified '
                           'base project.')
        meta += "</project>\n"

        try:
            # Create project and set its meta
            core.edit_meta('prj', path_args=quote_plus(target), data=meta)
        except (urllib2.URLError, M2Crypto.m2urllib2.URLError,
                M2Crypto.SSL.SSLError), err:
            raise ObsError("Can't set meta for %s: %s" % (target, str(err)))
Exemple #2
0
    def __init__(self, apiurl=None, oscrc=None):
        if oscrc:
            try:
                conf.get_config(override_conffile=oscrc)
            except OSError, err:
                if err.errno == 1:
                    # permission problem, should be the chmod(0600) issue
                    raise ObsError('Current user has no write permission '\
                                   'for specified oscrc: %s' % oscrc)

                raise  # else
            except urllib2.URLError:
                raise ObsError("invalid service apiurl: %s" % apiurl)
Exemple #3
0
    def commit_files(self, prj, pkg, files, message):
        """Commits files to OBS."""

        query = {
            'cmd': 'commitfilelist',
            'user': conf.get_apiurl_usr(self.apiurl),
            'comment': message,
            'keeplink': 1
        }
        url = core.makeurl(self.apiurl, ['source', prj, pkg], query=query)

        xml = "<directory>"
        for fpath, _ in files:
            with open(fpath) as fhandle:
                xml += '<entry name="%s" md5="%s"/>' % \
                       (os.path.basename(fpath), hexdigest(fhandle))
        xml += "</directory>"

        try:
            self.core_http(core.http_POST, url, data=xml)
            for fpath, commit_flag in files:
                if commit_flag:
                    put_url = core.makeurl(self.apiurl, [
                        'source', prj, pkg,
                        pathname2url(os.path.basename(fpath))
                    ],
                                           query="rev=repository")
                    self.core_http(core.http_PUT, put_url, filep=fpath)
            self.core_http(core.http_POST, url, data=xml)
        except OSCError, err:
            raise ObsError("can't commit files to %s/%s: %s" % (prj, pkg, err))
Exemple #4
0
 def rebuild(self, prj, pkg, arch):
     """Rebuild package."""
     try:
         return core.rebuild(self.apiurl, prj, pkg, repo=None, arch=arch)
     except (urllib2.URLError, M2Crypto.m2urllib2.URLError, \
             M2Crypto.SSL.SSLError), err:
         raise ObsError("Can't trigger rebuild for %s/%s: %s" % \
                        (prj, pkg, str(err)))
Exemple #5
0
 def get_results(self, prj, pkg):
     """Get package build results."""
     results = defaultdict(dict)
     try:
         build_status = core.get_results(self.apiurl, prj, pkg)
     except (urllib2.URLError, M2Crypto.m2urllib2.URLError,
             M2Crypto.SSL.SSLError), err:
         raise ObsError("can't get %s/%s build results: %s" \
                        % (prj, pkg, str(err)))
Exemple #6
0
    def get_buildlog(self, prj, pkg, repo, arch):
        """Get package build log from OBS."""

        url = core.makeurl(self.apiurl, ['build', prj, repo, arch, pkg,
                                         '_log?nostream=1&start=0'])
        try:
            log = self.core_http(core.http_GET, url).read()
        except OSCError, err:
            raise ObsError("can't get %s/%s build log: %s" % (prj, pkg, err))
Exemple #7
0
    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))
Exemple #8
0
 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:
         self.core_http(core.http_DELETE, url)
     except OSCError, err:
         raise ObsError("can't delete project %s: %s" % (prj, err))
Exemple #9
0
            # Create project and set its meta
            core.edit_meta('prj', path_args=quote_plus(target), data=meta)
        except (urllib2.URLError, M2Crypto.m2urllib2.URLError,
                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: