Ejemplo n.º 1
0
def main(argv=None):
    """Main function"""

    ret = 0
    try:
        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)

        LOGGER.info('Starting GBS source service')

        config = read_config(args.config)
        # Create / update cached repository
        repo = CachedRepo(config['repo-cache-dir'], args.url)
        args.revision = repo.update_working_copy(args.revision,
                                                 submodules=False)
        # Create outdir
        try:
            os.makedirs(args.outdir)
        except OSError as err:
            if err.errno != os.errno.EEXIST:
                raise ServiceError('Failed to create outdir: %s' % err, 1)
        os.chdir(repo.repodir)
        LOGGER.info('args.spec %s' % args.spec)
        if args.spec is None:
            spec_name=os.path.basename(args.url)
            if spec_name.endswith(".git"):
                  spec_name=spec_name[:-4]
            args.spec = findBestSpecFile('./packaging', spec_name)
        else:
            args.spec = findBestSpecFile('./packaging', args.spec)
        if args.spec is None:
            LOGGER.error('no spec file available in packaging'
                                                         ' directory')
            return 2

        read_localconf(".")
        # Export sources with GBS
        gbs_export(repo, args)

    except ServiceError as err:
        LOGGER.error(err[0])
        ret = err[1]
    except CachedRepoError as err:
        LOGGER.error('RepoCache: %s' % err)
        ret = 1

    return ret
def main(argv=None):
    """Main function"""

    args = parse_args(argv)

    logging.basicConfig(level=logging.INFO,
                        format='%(name)s:%(levelname)s: %(message)s')
    LOGGER.info('Starting git-buildpackage source service')
    if args.verbose == 'yes':
        gbplog.setup(color='auto', verbose=True)
        logging.root.setLevel(logging.DEBUG)

    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)
    except CachedRepoError as err:
        LOGGER.error('RepoCache: %s', str(err))
        return 1

    # Run GBP
    try:
        gbp_export(repo, args, config)

        # Write git meta file
        if args.git_meta:
            write_treeish_meta(repo.repo, args.revision, args.outdir,
                               args.git_meta)
    except ExportError as err:
        LOGGER.error(err[0])
        ret = err[1]
    except GbpServiceError as err:
        LOGGER.error(err)
        ret = EXIT_ERR_SERVICE
    else:
        ret = EXIT_OK
    return ret
Ejemplo n.º 3
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
Ejemplo n.º 4
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