示例#1
0
def main(argv):
    retval = 0
    prefix = "git-"
    source = None
    hook_env = {}

    options, gbp_args, dpkg_args = parse_args(argv, prefix)

    if not options:
        return ExitCodes.parse_error

    try:
        repo = DebianGitRepository(os.path.curdir)
    except GitRepositoryError:
        gbp.log.err("%s is not a git repository" % (os.path.abspath('.')))
        return 1

    try:
        clean_working_tree(options, repo)
        check_branch(repo, options)
        tree = maybe_write_tree(repo, options)
        source = source_vfs(repo, options, tree)

        check_tag(options, repo, source)

        if not options.tag_only:
            output_dir = prepare_output_dir(options.export_dir)
            tarball_dir = options.tarball_dir or output_dir
            tmp_dir = os.path.join(output_dir, "%s-tmp" % source.sourcepkg)
            build_env, hook_env = setup_pbuilder(options, repo,
                                                 source.is_native())
            major = (source.debian_version
                     if source.is_native() else source.upstream_version)
            export_dir = os.path.join(output_dir,
                                      "%s-%s" % (source.sourcepkg, major))
            build_dir = export_dir if options.export_dir else repo.path
            changes_file = changes_file_name(source, build_dir, dpkg_args)

            # Get/build the upstream tarball if necessary. We delay this in
            # case of a postexport hook so the hook gets a chance to modify the
            # sources and create different tarballs (#640382)
            # We don't delay it in general since we want to fail early if the
            # tarball is missing.
            if not source.is_native():
                if options.postexport:
                    gbp.log.info(
                        "Postexport hook set, delaying tarball creation")
                else:
                    prepare_upstream_tarballs(repo, source, options,
                                              tarball_dir, output_dir)

            # Export to another build dir if requested:
            if options.export_dir:
                export_source(repo, tree, source, options, tmp_dir,
                              tarball_dir)

                # Run postexport hook
                if options.postexport:
                    Hook('Postexport',
                         options.postexport,
                         extra_env=Hook.md(hook_env, {
                             'GBP_GIT_DIR': repo.git_dir,
                             'GBP_TMP_DIR': tmp_dir
                         }))(dir=tmp_dir)

                gbp.log.info("Moving '%s' to '%s'" % (tmp_dir, export_dir))
                move_old_export(export_dir)
                os.rename(tmp_dir, export_dir)

                # Delayed tarball creation in case a postexport hook is used:
                if not source.is_native() and options.postexport:
                    prepare_upstream_tarballs(repo, source, options,
                                              tarball_dir, output_dir)
            if options.prebuild:
                Hook('Prebuild',
                     options.prebuild,
                     extra_env=Hook.md(hook_env, {
                         'GBP_GIT_DIR': repo.git_dir,
                         'GBP_BUILD_DIR': build_dir
                     }))(dir=build_dir)

            # Finally build the package:
            RunAtCommand(
                options.builder, [pipes.quote(arg) for arg in dpkg_args],
                shell=True,
                extra_env=Hook.md(build_env,
                                  {'GBP_BUILD_DIR': build_dir}))(dir=build_dir)
            if options.postbuild:
                gbp.log.debug("Looking for changes file %s" % changes_file)
                Hook('Postbuild',
                     options.postbuild,
                     extra_env=Hook.md(
                         hook_env, {
                             'GBP_CHANGES_FILE': changes_file,
                             'GBP_BUILD_DIR': build_dir
                         }))()
        if options.tag or options.tag_only:
            perform_tagging(repo, source, options, hook_env)

    except KeyboardInterrupt:
        retval = 1
        gbp.log.err("Interrupted. Aborting.")
    except CommandExecFailed:
        retval = 1
    except (GbpError, GitRepositoryError) as err:
        if str(err):
            gbp.log.err(err)
        retval = 1
    except DebianSourceError as err:
        gbp.log.err(err)
        source = None
        retval = 1
    finally:
        drop_index(repo)

    if not options.tag_only:
        if options.export_dir and options.purge and not retval:
            RemoveTree(export_dir)()

        if source:
            summary, msg = gbp.notifications.build_msg(source.changelog,
                                                       not retval)
            if not gbp.notifications.notify(summary, msg, options.notify):
                gbp.log.err("Failed to send notification")
                retval = 1

    return retval
示例#2
0
def main(argv):
    retval = 0
    prefix = "git-"
    source = None
    hook_env = {}

    options, gbp_args, dpkg_args = parse_args(argv, prefix)

    if not options:
        return ExitCodes.parse_error

    try:
        repo = DebianGitRepository(os.path.curdir)
    except GitRepositoryError:
        gbp.log.err("%s is not a git repository" % (os.path.abspath('.')))
        return 1

    try:
        clean_working_tree(options, repo)
        check_branch(repo, options)
        tree = maybe_write_tree(repo, options)
        source = source_vfs(repo, options, tree)

        check_tag(options, repo, source)

        if not options.tag_only:
            output_dir = prepare_output_dir(options.export_dir)
            tarball_dir = output_dir
            if options.tarball_dir and source.upstream_version is not None:
                tarball_dir = PkgPolicy.version_subst(options.tarball_dir, source.upstream_version)
            tmp_dir = os.path.join(output_dir, "%s-tmp" % source.sourcepkg)
            build_env, hook_env = setup_pbuilder(options, repo, source.is_native())
            major = (source.debian_version if source.is_native()
                     else source.upstream_version)
            export_dir = os.path.join(output_dir, "%s-%s" % (source.sourcepkg, major))
            build_dir = export_dir if options.export_dir else repo.path
            changes_file = changes_file_name(source, build_dir, options.builder, dpkg_args)

            # Run preexport hook
            if options.export_dir and options.preexport:
                Hook('Preexport', options.preexport,
                     extra_env=Hook.md(hook_env,
                                       {'GBP_GIT_DIR': repo.git_dir,
                                        'GBP_BUILD_DIR': build_dir})
                     )()

            # Get/build the upstream tarball if necessary. We delay this in
            # case of a postexport hook so the hook gets a chance to modify the
            # sources and create different tarballs (#640382)
            # We don't delay it in general since we want to fail early if the
            # tarball is missing.
            if not source.is_native():
                if options.postexport:
                    gbp.log.info("Postexport hook set, delaying tarball creation")
                else:
                    prepare_upstream_tarballs(repo, source, options, tarball_dir,
                                              output_dir)

            # Export to another build dir if requested:
            if options.export_dir:
                export_source(repo, tree, source, options, tmp_dir, tarball_dir)

                # Run postexport hook
                if options.postexport:
                    Hook('Postexport', options.postexport,
                         extra_env=Hook.md(hook_env,
                                           {'GBP_GIT_DIR': repo.git_dir,
                                            'GBP_TMP_DIR': tmp_dir})
                         )(dir=tmp_dir)

                gbp.log.info("Moving '%s' to '%s'" % (tmp_dir, export_dir))
                move_old_export(export_dir)
                os.rename(tmp_dir, export_dir)

                # Delayed tarball creation in case a postexport hook is used:
                if not source.is_native() and options.postexport:
                    prepare_upstream_tarballs(repo, source, options, tarball_dir,
                                              output_dir)
            if options.prebuild:
                Hook('Prebuild', options.prebuild,
                     extra_env=Hook.md(hook_env,
                                       {'GBP_GIT_DIR': repo.git_dir,
                                        'GBP_BUILD_DIR': build_dir})
                     )(dir=build_dir)

            # Finally build the package:
            gbp.log.info("Performing the build")
            RunAtCommand(options.builder,
                         [pipes.quote(arg) for arg in dpkg_args],
                         shell=True,
                         extra_env=Hook.md(build_env,
                                           {'GBP_BUILD_DIR': build_dir})
                         )(dir=build_dir)
            if options.postbuild:
                gbp.log.debug("Looking for changes file %s" % changes_file)
                Hook('Postbuild', options.postbuild,
                     extra_env=Hook.md(hook_env,
                                       {'GBP_CHANGES_FILE': changes_file,
                                        'GBP_BUILD_DIR': build_dir})
                     )()
        if options.tag or options.tag_only:
            perform_tagging(repo, source, options, hook_env)

    except KeyboardInterrupt:
        retval = 1
        gbp.log.err("Interrupted. Aborting.")
    except CommandExecFailed:
        retval = 1
    except (GbpError, GitRepositoryError) as err:
        if str(err):
            gbp.log.err(err)
        retval = 1
    except DebianSourceError as err:
        gbp.log.err(err)
        source = None
        retval = 1
    finally:
        drop_index(repo)

    if not options.tag_only:
        if options.export_dir and options.purge and not retval:
            RemoveTree(export_dir)()

        if source:
            summary, msg = gbp.notifications.build_msg(source.changelog,
                                                       not retval)
            if not gbp.notifications.notify(summary, msg, options.notify):
                gbp.log.err("Failed to send notification")
                retval = 1

    return retval