Beispiel #1
0
def main(argv=None):
    """Main function"""

    ret = EXIT_OK
    args = parse_args(argv)
    args.outdir = os.path.abspath(args.outdir)

    if args.verbose == 'yes':
        gbplog.setup(color='auto', verbose=True)
        LOGGER.setLevel(gbplog.DEBUG)
        gbp_repocache.LOGGER.setLevel(gbplog.DEBUG)
        gbs_log.setup(verbose=True)
    else:
        gbplog.setup(color='auto', verbose=False)
        gbs_log.setup(verbose=False)
    # Add a new handler writing to a tempfile into the root logger
    file_log = tempfile.NamedTemporaryFile(prefix='gbs-service_')
    file_handler = gbplog.GbpStreamHandler(file_log)
    gbplog.getLogger().addHandler(file_handler)

    LOGGER.info('Starting GBS source service')

    # Create outdir
    try:
        os.makedirs(args.outdir)
    except OSError as err:
        if err.errno != os.errno.EEXIST:
            LOGGER.error('Failed to create outdir: %s', err)
            return EXIT_ERR_SERVICE

    try:
        config = read_config(args.config)
        # Create / update cached repository
        refs_hack = str_to_bool(config['repo-cache-refs-hack'])
        try:
            repo = CachedRepo(config['repo-cache-dir'],
                              args.url,
                              refs_hack=refs_hack)
            args.revision = repo.update_working_copy(args.revision,
                                                     submodules=False)
        except CachedRepoError as err:
            raise ServiceError('RepoCache: %s' % err, EXIT_ERR_SERVICE)

        # Export sources with GBS
        gbs_export(repo, args, config)

        # Write git-meta
        if args.git_meta:
            try:
                write_treeish_meta(repo.repo, args.revision, args.outdir,
                                   args.git_meta)
            except GbpServiceError as err:
                raise ServiceError(str(err), EXIT_ERR_SERVICE)
    except ServiceError as err:
        LOGGER.error(err[0])
        if err[1] in args.error_pkg:
            file_handler.flush()
            error_fn = os.path.join(args.outdir, 'service-error')
            shutil.copy2(file_log.name, error_fn)
            with open(error_fn + '.spec', 'w') as error_spec:
                error_spec.write(ERROR_PKG_SPEC)
            ret = EXIT_OK
        else:
            ret = err[1]
    finally:
        gbplog.getLogger().removeHandler(file_handler)
        file_log.close()

    return ret
Beispiel #2
0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!
!!!
!!! OBS-SERVICE-GBS FAILED
!!!
!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
--- SERVICE ERROR LOG --------------------------------------------------------
`sed s'/^/  /' %{SOURCE0}`
--- END OF SERVICE ERROR LOG -------------------------------------------------
EOF
exit 1
"""

# Setup logging
LOGGER = gbplog.getLogger('source_service')
LOGGER.setLevel(gbplog.INFO)


class ServiceError(Exception):
    """Source service errors"""
    pass


def construct_gbs_args(args, outdir, gitdir):
    """Construct args list for GBS"""
    # Replicate gbs export command line arguments
    gbs_args = {
        'outdir': outdir,
        'gitdir': gitdir,
        'spec': None,
# vim:fileencoding=utf-8:et:ts=4:sw=4:sts=4
#
# Copyright (C) 2013 Intel Corporation <*****@*****.**>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""Helpers for the git-buildpackage OBS source service"""

import gbp.log as gbplog


# Setup logging
LOGGER = gbplog.getLogger('source_service')
LOGGER.setLevel(gbplog.INFO)

# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""Git repository cache"""

import os
import hashlib
import shutil
import fcntl

import gbp.log as gbplog
from gbp.git.repository import GitRepository, GitRepositoryError


# Setup logging
LOGGER = gbplog.getLogger('gbp-repocache')
LOGGER.setLevel(gbplog.INFO)


class MirrorGitRepository(GitRepository): # pylint: disable=R0904
    """Special Git repository to enable a mirrored clone with a working copy"""

    def set_config(self, name, value, replace=False):
        """Add a config value"""
        args = ['--replace-all'] if replace else ['--add']
        args.extend([name, value])
        stderr, ret = self._git_inout('config', args)[1:]
        if ret:
            raise GitRepositoryError('Failed to set config %s=%s (%s)' %
                                     (name, value, stderr))
Beispiel #5
0
def main(argv=None):
    """Main function"""

    ret = EXIT_OK
    args = parse_args(argv)
    args.outdir = os.path.abspath(args.outdir)

    if args.verbose == 'yes':
        gbplog.setup(color='auto', verbose=True)
        LOGGER.setLevel(gbplog.DEBUG)
        gbp_repocache.LOGGER.setLevel(gbplog.DEBUG)
        gbs_log.setup(verbose=True)
    else:
        gbplog.setup(color='auto', verbose=False)
        gbs_log.setup(verbose=False)
    # Add a new handler writing to a tempfile into the root logger
    file_log = tempfile.NamedTemporaryFile(prefix='gbs-service_')
    file_handler = gbplog.GbpStreamHandler(file_log)
    gbplog.getLogger().addHandler(file_handler)

    LOGGER.info('Starting GBS source service')

    # Create outdir
    try:
        os.makedirs(args.outdir)
    except OSError as err:
        if err.errno != os.errno.EEXIST:
            LOGGER.error('Failed to create outdir: %s', err)
            return EXIT_ERR_SERVICE

    try:
        config = read_config(args.config)
        # Create / update cached repository
        refs_hack = str_to_bool(config['repo-cache-refs-hack'])
        try:
            repo = CachedRepo(config['repo-cache-dir'], args.url,
                              refs_hack=refs_hack)
            args.revision = repo.update_working_copy(args.revision,
                                                     submodules=False)
        except CachedRepoError as err:
            raise ServiceError('RepoCache: %s' % err, EXIT_ERR_SERVICE)

        # Export sources with GBS
        gbs_export(repo, args, config)

        # Write git-meta
        if args.git_meta:
            try:
                write_treeish_meta(repo.repo, args.revision, args.outdir,
                                   args.git_meta)
            except GbpServiceError as err:
                raise ServiceError(str(err), EXIT_ERR_SERVICE)
    except ServiceError as err:
        LOGGER.error(err[0])
        if err[1] in args.error_pkg:
            file_handler.flush()
            error_fn = os.path.join(args.outdir, 'service-error')
            shutil.copy2(file_log.name, error_fn)
            with open(error_fn + '.spec', 'w') as error_spec:
                error_spec.write(ERROR_PKG_SPEC)
            ret = EXIT_OK
        else:
            ret = err[1]
    finally:
        gbplog.getLogger().removeHandler(file_handler)
        file_log.close()

    return ret