Blame src/centpkg/__init__.py

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 2fb8a5
import pyrpkg
Brian Stinson ca61eb
import os
Brian Stinson ca61eb
import re
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
from . import cli
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
class Commands(pyrpkg.Commands):
85a850
    '''
85a850
        For the pyrpkg commands with centpkg behavior
85a850
    '''
Brian Stinson 2fb8a5
    def __init__(self, path, lookaside, lookasidehash, lookaside_cgi,
Brian Stinson 2fb8a5
                 gitbaseurl, anongiturl, branchre, kojiconfig,
Brian Stinson 2fb8a5
                 build_client, user=None, dist=None, target=None,
Brian Stinson 2fb8a5
                 quiet=False):
85a850
        '''
85a850
            Init the object and some configuration details.
85a850
        '''
85a850
        super(Commands, self).__init__(path, lookaside, lookasidehash,
Brian Stinson 2fb8a5
                                      lookaside_cgi, gitbaseurl, anongiturl,
Brian Stinson 2fb8a5
                                      branchre, kojiconfig, build_client,
85a850
                                      user, dist, target, quiet)
Brian Stinson 2fb8a5
Brian Stinson ca61eb
    # redefined loaders
Brian Stinson ca61eb
    def load_rpmdefines(self):
85a850
        '''
85a850
            Populate rpmdefines based on branch data
85a850
        '''
Brian Stinson ca61eb
        try:
Brian Stinson ca61eb
            osver = re.search(r'\d.*$', self.branch_merge).group()
Brian Stinson ca61eb
        except AttributeError:
Brian Stinson ca61eb
            raise pyrpkg.rpkgError('Could not find the base OS ver from branch name'
Brian Stinson ca61eb
                            ' %s' % self.branch_merge)
Brian Stinson ca61eb
        self._distval = osver
Brian Stinson ca61eb
        self._distval = self._distval.replace('.', '_')
Brian Stinson ca61eb
        self._disttag = 'el%s' % self._distval
Brian Stinson 2eaea9
        self._rpmdefines = ["--define '_topdir {0}'".format(self.path),
Brian Stinson 2eaea9
                            "--define 'dist .{0}'".format(self._disttag),
Brian Stinson ca61eb
                            # int and float this to remove the decimal
Brian Stinson 2eaea9
                            "--define '{0} 1'".format(self._disttag)]
Brian Stinson ca61eb
Brian Stinson ca61eb
    def load_spec(self):
Brian Stinson ca61eb
        """This sets the spec attribute"""
Brian Stinson ca61eb
Brian Stinson ca61eb
        # We are not using the upstream load_spec because the file structure is
Brian Stinson ca61eb
        # hard-coded
Brian Stinson ca61eb
Brian Stinson ca61eb
        # Get a list of files in the path we're looking at
Brian Stinson ca61eb
        files = os.listdir(os.path.join(self.path,'SPECS'))
Brian Stinson ca61eb
        # Search the files for the first one that ends with ".spec"
85a850
        for __f in files:
85a850
            if __f.endswith('.spec') and not __f.startswith('.'):
85a850
                self._spec = os.path.join('SPECS', __f)
Brian Stinson ca61eb
                return
Brian Stinson 8f2a1a
Brian Stinson 8f2a1a
        raise pyrpkg.rpkgError('No spec file found.')
Brian Stinson ca61eb
85a850
    # These are the commands defined in the base pyrpkg.Commands class
85a850
    # and have been implemented here
85a850
    def clone(self, *args, **kwargs):
85a850
        super(Commands, self).clone(*args, **kwargs)
85a850
85a850
    def sources(self, outdir=None):
85a850
        """Download source files"""
85a850
85a850
        # in 'super' the sources function expects a file named 'sources' to be in the base directory.
85a850
        # A patch has been sent to upstream to allow a more flexible location.
85a850
        #
85a850
        # This code doesn't work due to:
85a850
        #              archive.strip().split('  ', 1) # patch provided to upstream to fix
85a850
        #
85a850
        #              url = '%s/%s/%s/%s/%s' % (self.lookaside, self.module_name,
85a850
        #                                        file.replace(' ', '%20'),
85a850
        #                                        csum, file.replace(' ', '%20'))
85a850
        #
85a850
        #os.symlink(os.path.join(self.path, '.{0}.metadata'.format(self.module_name)), os.path.join(self.path, 'sources'))
85a850
        #super(Commands, self).sources(outdir=None)
85a850
        #os.unlink(os.path.join(self.path, 'sources'))
85a850
85a850
        # The following is copied from rpkg/__init__.py:sources with minor changes
85a850
        try:
85a850
            archives = open(os.path.join(self.path,
85a850
                                         '.{0}.metadata'.format(self.module_name)),
85a850
                            'r').readlines()
85a850
        except IOError, e:
85a850
            raise pyrpkg.rpkgError('%s is not a valid repo: %s' % (self.path, e))
85a850
        # Default to putting the files where the module is
85a850
        if not outdir:
85a850
            outdir = self.path
85a850
        for archive in archives:
85a850
            try:
85a850
                # This strip / split is kind a ugly, but checksums shouldn't have
85a850
                # two spaces in them.  sources file might need more structure in the
85a850
                # future
85a850
                csum, file = archive.strip().split(None, 1)
85a850
            except ValueError:
85a850
                raise pyrpkg.rpkgError('Malformed sources file.')
85a850
            # See if we already have a valid copy downloaded
85a850
            outfile = os.path.join(outdir, file)
85a850
            if os.path.exists(outfile):
85a850
                if self._verify_file(outfile, csum, self.lookasidehash):
85a850
                    continue
85a850
            self.log.info("Downloading %s" % (file))
85a850
            url = '%s/%s/%s/%s' % (self.lookaside, self.module_name,
85a850
                                      self.branch_merge,
85a850
                                      csum,
85a850
                                      )
85a850
            command = ['curl', '-H', 'Pragma:', '-o', outfile, '-R', '-S', '--fail']
85a850
            if self.quiet:
85a850
                command.append('-s')
85a850
            command.append(url)
85a850
            self._run_command(command)
85a850
            if not self._verify_file(outfile, csum, self.lookasidehash):
85a850
                raise pyrpkg.rpkgError('%s failed checksum' % file)
85a850
85a850
        return
Brian Stinson ca61eb
Brian Stinson 2fb8a5
    # These are the commands defined in the base pyrpkg.Commands class
85a850
    # and have not been implemented here, yet
85a850
Brian Stinson 2fb8a5
    def load_kojisession(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def add_tag(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def clean(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def clone_with_dirs(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def commit(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def delete_tag(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def get_latest_commit(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def gitbuildhash(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def import_srpm(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def list_tag(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def new(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def patch(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def pull(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def push(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def switch_branch(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def file_exists(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def upload_file(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def build(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def clog(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def compile(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def giturl(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def koji_upload(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def install(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def lint(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def local(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def mock_config(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def mockbuild(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def upload(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def prep(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def srpm(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def unused_patches(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")
Brian Stinson 2fb8a5
Brian Stinson 2fb8a5
    def verify_files(self, *args, **kwargs):
Brian Stinson 2fb8a5
        raise NotImplementedError("This command is not yet implemented in centpkg")