lrossett / centos / centpkg

Forked from centos/centpkg 2 years ago
Clone
85a850
#pylint: disable=line-too-long,abstract-class-not-used
85a850
'''
85a850
    Top level function library for centpkg
85a850
'''
85a850
#
85a850
# Author(s):
85a850
#            Jesse Keating <jkeating@redhat.com>
85a850
#            Pat Riehecky <riehecky@fnal.gov>
85a850
#            Brian Stinson <bstinson@ksu.edu>
85a850
#
85a850
# This program is free software; you can redistribute it and/or modify it
85a850
# under the terms of the GNU General Public License as published by the
85a850
# Free Software Foundation; either version 2 of the License, or (at your
85a850
# option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
85a850
# the full text of the license.
85a850
85a850
85a850
Brian Stinson ca61eb
import os
Brian Stinson ca61eb
import re
0da767
import sys
8311a4
import urlparse
e7fd56
import warnings
Brian Stinson 2fb8a5
ebeaf1
from pyrpkg import Commands, rpkgError
a394b1
from pyrpkg.layout import ExplodedSRPMLayout, DistGitLayout
0da767
from centos import centos_cert
a394b1
from .lookaside import CentOSLookasideCache
a394b1
from pyrpkg.utils import cached_property
Brian Stinson 2fb8a5
from . import cli
Brian Stinson 2fb8a5
05c687
7ae64c
class DistGitDirectory(object):
7ae64c
86b0d3
    signame = None
86b0d3
    centosversion = None
86b0d3
    projectname = None
86b0d3
    releasename = None
639034
    distrobranch = False
86b0d3
7ae64c
    def __init__(self, branchtext):
a394b1
        sigtobranchre = r'c(?P<centosversion>\d+)-sig-(?P<signame>\w+)-?(?P<projectname>\w+)?-?(?P<releasename>\w+)?'
639034
        distrobranchre = r'c(?P<centosversion>\d+)-?(?P<projectname>\w+)?'
e7fd56
        oldbranchre = r'(?P<signame>\w+)(?P<centosversion>\d)'
639034
        sigmatch = re.match(sigtobranchre, branchtext)
639034
        distromatch = re.match(distrobranchre, branchtext)
e7fd56
        oldbranchmatch = re.match(oldbranchre, branchtext)
639034
        if sigmatch:
639034
            gd = sigmatch.groupdict()
9af8c4
            self.signame = gd['signame']
9af8c4
            self.centosversion = gd['centosversion']
7ae64c
35f2c1
            # Users have the option to specify (or not specify) common in their
35f2c1
            # git repos. Ww need to handle these cases because common is not a
35f2c1
            # project nor is it a release.
9af8c4
            if gd['projectname'] != 'common':
9af8c4
                self.projectname = gd['projectname']
9af8c4
            if gd['releasename'] != 'common':
9af8c4
                self.releasename = gd['releasename']
639034
        elif distromatch:
639034
            gd = distromatch.groupdict()
639034
            self.distrobranch = True
639034
            self.signame = 'centos'
639034
            self.centosversion = gd['centosversion']
639034
639034
            if gd['projectname'] != 'common':
639034
                self.projectname = gd['projectname']
e7fd56
        elif oldbranchmatch:
e7fd56
            warnings.warn("This branch is deprecated and will be removed soon",
e7fd56
                          DeprecationWarning)
639034
        else:
639034
            raise ValueError("Branchname: {0} is not valid".format(branchtext))
9af8c4
9af8c4
    @property
9af8c4
    def target(self):
9af8c4
        projectorcommon = self.projectname
9af8c4
        releaseorcommon = self.releasename
9af8c4
639034
        if self.distrobranch:
639034
            return '-'.join(filter(None, ['c'+self.centosversion,
639034
                                          projectorcommon]))
639034
9af8c4
        if not releaseorcommon:
9af8c4
            if not projectorcommon or projectorcommon == 'common':
9af8c4
                projectorcommon = 'common'
9af8c4
            else:
9af8c4
                releaseorcommon = 'common'
9af8c4
9af8c4
        return '-'.join(filter(None, [self.signame+self.centosversion,
9af8c4
                                      projectorcommon, releaseorcommon])) + '-el{0}'.format(self.centosversion)
9af8c4
a394b1
9af8c4
class Commands(Commands):
85a850
    '''
85a850
        For the pyrpkg commands with centpkg behavior
85a850
    '''
a394b1
    def __init__(self, *args, **kwargs):
85a850
        '''
85a850
            Init the object and some configuration details.
85a850
        '''
a394b1
        super(Commands, self).__init__(*args, **kwargs)
a394b1
a394b1
        self.source_entry_type = 'old'
a394b1
a394b1
    @property
a394b1
    def distgitdir(self):
a394b1
        return DistGitDirectory(self.branch_merge)
Brian Stinson 2fb8a5
a394b1
    @cached_property
a394b1
    def lookasidecache(self):
a394b1
        return CentOSLookasideCache(self.lookasidehash,
a394b1
                                    self.lookaside,
a394b1
                                    self.lookaside_cgi,
a394b1
                                    self.repo_name,
a394b1
                                    self.branch_merge)
639034
Brian Stinson ca61eb
    # redefined loaders
Brian Stinson ca61eb
    def load_rpmdefines(self):
85a850
        '''
85a850
            Populate rpmdefines based on branch data
85a850
        '''
a1a2e2
a1a2e2
        if not self.distgitdir.centosversion:
a1a2e2
            raise rpkgError('Could not get the OS version from the branch:{0}'.format(self.branch_merge))
a1a2e2
a394b1
        self._distvar = self.distgitdir.centosversion
a394b1
        self._distval = self._distvar.replace('.', '_')
Brian Stinson f12d46
Brian Stinson d6d6d7
        self._disttag = 'el%s' % self._distval
a394b1
        self._rpmdefines = ["--define '_sourcedir %s'" % self.layout.sourcedir,
a394b1
                            "--define '_specdir %s'" % self.layout.specdir,
a394b1
                            "--define '_builddir %s'" % self.layout.builddir,
a394b1
                            "--define '_srcrpmdir %s'" % self.layout.srcrpmdir,
a394b1
                            "--define '_rpmdir %s'" % self.layout.rpmdir,
a394b1
                            "--define 'dist .%s'" % self._disttag,
Brian Stinson ca61eb
                            # int and float this to remove the decimal
a394b1
                            "--define '%s 1'" % self._disttag]
a394b1
        self.log.debug("RPMDefines: %s" % self._rpmdefines)
Brian Stinson ca61eb
Brian Stinson 6ba768
    def load_target(self):
Brian Stinson 6ba768
        """ This sets the target attribute (used for mock and koji) """
Brian Stinson 3f76b3
Brian Stinson 3f76b3
        # Distribution branches start with c and may or may not end in -plus
a394b1
        # otherwise, it's a sig branch
3ab1c8
        if not self.distgitdir.distrobranch:
Brian Stinson 3f76b3
            # send distribution packages to build on the the bananas tags for now
Brian Stinson 3f76b3
            self._target = 'bananas{0}-{1}'.format(self.distval, self.disttag)
Brian Stinson 3f76b3
        else:
Brian Stinson 3f76b3
            # sig packages are built in the tag that matches the git branch
3ab1c8
            self._target = self.distgitdir.target
Brian Stinson 6ba768
Brian Stinson 046d91
    def load_user(self):
Brian Stinson 046d91
        try:
0da767
            self._user = centos_cert.CentOSUserCert().CN
a394b1
        except Exception:
0da767
            print >>sys.stderr, "Could not load user from cert file"
Brian Stinson 046d91
            super(Commands, self).load_user()
Brian Stinson 046d91
85a850
    # These are the commands defined in the base pyrpkg.Commands class
85a850
    # and have been implemented here
85a850
a394b1
    def upload(self, *args, **kwargs):
a394b1
        if not self.distgitdir.distrobranch:
a394b1
            self.source_entry_type = 'bsd'
a394b1
        return super(Commands, self).upload(*args, **kwargs)
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def import_srpm(self, *args, **kwargs):
Brian Stinson ae56d4
        raise NotImplementedError("import_srpm is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def patch(self, *args, **kwargs):
Brian Stinson ae56d4
        raise NotImplementedError("patch is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def install(self, *args, **kwargs):
Brian Stinson ae56d4
        raise NotImplementedError("install is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def lint(self, *args, **kwargs):
Brian Stinson ae56d4
        raise NotImplementedError("lint is not yet implemented in centpkg")