Esempio n. 1
0
    def __init__(self, apiurl, project):
        """Initialize instance variables."""

        self.apiurl = apiurl
        self.project = project

        # Store some prefix / data used in the code.
        self.cstaging = conf.config[project]['staging']
        self.cstaging_group = conf.config[project]['staging-group']
        self.cstaging_archs = conf.config[project]['staging-archs'].split()
        self.cstaging_dvd_archs = conf.config[project][
            'staging-dvd-archs'].split()
        self.cstaging_nocleanup = conf.config[project][
            'nocleanup-packages'].split()
        self.crings = conf.config[project]['rings']
        self.cnonfree = conf.config[project]['nonfree']
        self.crebuild = conf.config[project]['rebuild']
        self.cproduct = conf.config[project]['product']
        self.copenqa = conf.config[project]['openqa']
        self.user = conf.get_apiurl_usr(apiurl)
        self._ring_packages = None
        self._ring_packages_for_links = None
        self._packages_staged = None
        self._package_metas = dict()

        # If the project support rings, inititialize some variables.
        if self.crings:
            self.rings = ('{}:0-Bootstrap'.format(self.crings),
                          '{}:1-MinimalX'.format(self.crings),
                          '{}:2-TestDVD'.format(self.crings))
        else:
            self.rings = []
Esempio n. 2
0
def mail_send(apiurl, project, to, subject, body, from_key='maintainer',
              followup_to_key='release-list', dry=False):
    from email.mime.text import MIMEText
    import email.utils
    import smtplib

    config = Config.get(apiurl, project)
    msg = MIMEText(body)
    msg['Message-ID'] = email.utils.make_msgid()
    msg['Date'] = email.utils.formatdate(localtime=1)
    if from_key is None:
        msg['From'] = entity_email(apiurl, conf.get_apiurl_usr(apiurl), include_name=True)
    else:
        msg['From'] = config['mail-{}'.format(from_key)]
    if '@' not in to:
        to = config['mail-{}'.format(to)]
    msg['To'] = to
    followup_to = config.get('mail-{}'.format(followup_to_key))
    if followup_to:
        msg['Mail-Followup-To'] = followup_to
    msg['Subject'] = subject

    if dry:
        print(msg.as_string())
        return

    s = smtplib.SMTP(config.get('mail-relay', 'relay.suse.de'))
    s.sendmail(msg['From'], [msg['To']], msg.as_string())
    s.quit()
Esempio n. 3
0
def mail_send(apiurl,
              project,
              to,
              subject,
              body,
              from_key='maintainer',
              followup_to_key='release-list',
              dry=False):

    config = Config.get(apiurl, project)
    if from_key is None:
        sender = entity_email(apiurl,
                              conf.get_apiurl_usr(apiurl),
                              include_name=True)
    else:
        sender = config['mail-{}'.format(from_key)]

    if '@' not in to:
        to = config['mail-{}'.format(to)]

    followup_to = config.get('mail-{}'.format(followup_to_key))
    relay = config.get('mail-relay', 'relay.suse.de')

    mail_send_with_details(text=body,
                           subject=subject,
                           relay=relay,
                           sender=sender,
                           followup_to=followup_to,
                           to=to,
                           dry=dry)
Esempio n. 4
0
    def __init__(self, apiurl, project):
        """Initialize instance variables."""

        self.apiurl = apiurl
        self.project = project

        # Store some prefix / data used in the code.
        self.cstaging = conf.config[project]['staging']
        self.cstaging_group = conf.config[project]['staging-group']
        self.cstaging_archs = conf.config[project]['staging-archs'].split()
        self.cstaging_dvd_archs = conf.config[project]['staging-dvd-archs'].split()
        self.cstaging_nocleanup = conf.config[project]['nocleanup-packages'].split()
        self.crings = conf.config[project]['rings']
        self.cnonfree = conf.config[project]['nonfree']
        self.crebuild = conf.config[project]['rebuild']
        self.cproduct = conf.config[project]['product']
        self.copenqa = conf.config[project]['openqa']
        self.user = conf.get_apiurl_usr(apiurl)
        self._ring_packages = None
        self._ring_packages_for_links = None
        self._packages_staged = None
        self._package_metas = dict()

        # If the project support rings, inititialize some variables.
        if self.crings:
            self.rings = (
                '{}:0-Bootstrap'.format(self.crings),
                '{}:1-MinimalX'.format(self.crings),
                '{}:2-TestDVD'.format(self.crings)
            )
        else:
            self.rings = []
Esempio n. 5
0
    def __init__(self, apiurl, project):
        """Initialize instance variables."""

        self.apiurl = apiurl
        self.project = project

        # Store some prefix / data used in the code.
        self.cstaging = conf.config[project]['staging']
        self.cstaging_group = conf.config[project]['staging-group']
        self.cstaging_archs = conf.config[project]['staging-archs'].split(' ')
        self.crings = conf.config[project]['rings']
        self.cnonfree = conf.config[project]['nonfree']
        self.crebuild = conf.config[project]['rebuild']
        self.cproduct = conf.config[project]['product']
        self.copenqa = conf.config[project]['openqa']
        self.user = conf.get_apiurl_usr(apiurl)

        # If the project support rings, inititialize some variables.
        self.ring_packages = {}
        if self.crings:
            self.rings = (
                '{}:0-Bootstrap'.format(self.crings),
                '{}:1-MinimalX'.format(self.crings),
                '{}:2-TestDVD'.format(self.crings)
            )
            self.ring_packages = self._generate_ring_packages()

        self.packages_staged = self._get_staged_requests()
Esempio n. 6
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))
Esempio n. 7
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))
Esempio n. 8
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)))
    def setup_checker(self):
        """ reimplement this """
        apiurl = conf.config['apiurl']
        if apiurl is None:
            raise osc.oscerr.ConfigError("missing apiurl")
        user = self.options.user
        group = self.options.group
        # if no args are given, use the current oscrc "owner"
        if user is None and group is None:
            user = conf.get_apiurl_usr(apiurl)

        return self.clazz(apiurl=apiurl,
                          dryrun=self.options.dry,
                          user=user,
                          group=group,
                          logger=self.logger)
Esempio n. 10
0
    def setup_checker(self):
        """ reimplement this """
        apiurl = conf.config['apiurl']
        if apiurl is None:
            raise osc.oscerr.ConfigError("missing apiurl")
        user = self.options.user
        group = self.options.group
        # if no args are given, use the current oscrc "owner"
        if user is None and group is None:
            user = conf.get_apiurl_usr(apiurl)

        return self.clazz(apiurl = apiurl, \
                dryrun = self.options.dry, \
                user = user, \
                group = group, \
                logger = self.logger)
Esempio n. 11
0
def mail_send(apiurl,
              project,
              to,
              subject,
              body,
              from_key='maintainer',
              followup_to_key='release-list',
              dry=False):
    from email.mime.text import MIMEText
    import email.utils
    import smtplib

    config = Config.get(apiurl, project)
    msg = MIMEText(body)
    msg['Message-ID'] = email.utils.make_msgid()
    msg['Date'] = email.utils.formatdate(localtime=1)
    if from_key is None:
        msg['From'] = entity_email(apiurl,
                                   conf.get_apiurl_usr(apiurl),
                                   include_name=True)
    else:
        msg['From'] = config['mail-{}'.format(from_key)]
    if '@' not in to:
        to = config['mail-{}'.format(to)]
    msg['To'] = to
    followup_to = config.get('mail-{}'.format(followup_to_key))
    if followup_to:
        msg['Mail-Followup-To'] = followup_to
    msg['Subject'] = subject

    if dry:
        print(msg.as_string())
        return

    s = smtplib.SMTP(config.get('mail-relay', 'relay.suse.de'))
    s.sendmail(msg['From'], [msg['To']], msg.as_string())
    s.quit()
Esempio n. 12
0
def sentry_init(obs_apiurl=None, tags=None):
    try:
        import sentry_sdk
    except ImportError:
        sentry_init.client = sentry_client_dummy()
        return sentry_sdk_dummy()

    sentry_init.client = sentry_sdk.init(
        conf.config.get('sentry_sdk.dsn'),
        environment=conf.config.get('sentry_sdk.environment'),
        release=VERSION)

    with sentry_sdk.configure_scope() as scope:
        scope.set_tag('osc', core.__version__)

        if obs_apiurl:
            scope.set_tag('obs_apiurl', obs_apiurl)
            scope.user = {'username': conf.get_apiurl_usr(obs_apiurl)}

        if tags:
            for key, value in tags.items():
                scope.set_tag(key, value)

    return sentry_sdk
Esempio n. 13
0
        if e.code == 404:
            print "osc: Cannot link to non-existent project %s" % link_to_project
            return False
            
    path = quote_plus(new_project),
    kind = 'prj'
    try:
        data = meta_exists(metatype=kind,
                           path_args=path,
                           template_args=None,
                           create_new=False)
    except urllib2.HTTPError, e:
        if e.code != 404:
            raise
        root = ET.fromstring(new_prj_link % { "name" : new_project,
                             "user" : conf.get_apiurl_usr(conf.config['apiurl']),
                             "link_source" : link_to_project
                            })
        repos = {}
        for repo in get_repos_of_project(conf.config['apiurl'], link_to_project):
            if repo.name not in repos:
                repos[repo.name] = []
            repos[repo.name].append(repo.arch)

        if not repos:
            print "osc: no repositories found in %s" % link_to_project
            return False

        comment_element = ET.Comment(text="Repositories to build against project %s" % link_to_project )
        root.append(comment_element)
        for reponame, archs in repos.iteritems():
Esempio n. 14
0
            return False

    path = quote_plus(new_project),
    kind = 'prj'
    try:
        data = meta_exists(metatype=kind,
                           path_args=path,
                           template_args=None,
                           create_new=False)
    except urllib2.HTTPError, e:
        if e.code != 404:
            raise
        root = ET.fromstring(
            new_prj_link % {
                "name": new_project,
                "user": conf.get_apiurl_usr(conf.config['apiurl']),
                "link_source": link_to_project
            })
        repos = {}
        for repo in get_repos_of_project(conf.config['apiurl'],
                                         link_to_project):
            if repo.name not in repos:
                repos[repo.name] = []
            repos[repo.name].append(repo.arch)

        if not repos:
            print "osc: no repositories found in %s" % link_to_project
            return False

        comment_element = ET.Comment(
            text="Repositories to build against project %s" % link_to_project)