def test_is_native_file_3_git(self):
        """Test native package of format 3 from git"""
        self._commit_format('3.0', 'native')
        source = DebianSource(GitVfs(self.repo))
        self.assertTrue(source.is_native(False))

        self._commit_format('3.0', 'quilt')
        source = DebianSource(GitVfs(self.repo))
        self.assertFalse(source.is_native(True))
Exemplo n.º 2
0
def source_vfs(repo, options, tree):
    """Init source package info either from git or from working copy"""
    vfs = GitVfs(repo, tree) if tree else FileVfs('.')
    try:
        source = DebianSource(vfs)
        source.is_native()  # check early if this works
    except Exception as e:
        raise GbpError("Can't determine package type: %s" % e)
    return source
Exemplo n.º 3
0
def source_vfs(repo, options, tree):
    """Init source package info either from git or from working copy"""
    vfs = GitVfs(repo, tree) if tree else FileVfs('.')
    try:
        source = DebianSource(vfs)
        source.is_native()  # check early if this works
    except Exception as e:
        raise GbpError("Can't determine package type: %s" % e)
    return source
def source_vfs(repo, options, tree):
    """Init source package info either from git or from working copy"""
    # FIXME: just init the correct vfs
    try:
        if tree:
            source = DebianSource(GitVfs(repo, tree))
        else:
            source = DebianSource('.')
            source.is_native() # check early if this works
    except Exception as e:
        raise GbpError("Can't determine package type: %s" % e)
    return source
    def test_is_releasable(self):
        os.makedirs('debian/')
        with open('debian/changelog', 'w') as f:
            f.write("""git-buildpackage (0.2.3) unstable; urgency=low

  * git doesn't like '~' in tag names so replace this with a dot when tagging

 -- Guido Guenther <*****@*****.**>  Mon,  2 Oct 2006 18:30:20 +0200
""")
        source = DebianSource('.')
        self.assertEquals(source.changelog.distribution, "unstable")
        self.assertTrue(source.is_releasable())
    def test_is_native_file_3_file(self):
        """Test native package of format 3"""
        source = DebianSource('.')
        os.makedirs('debian/source')

        dsf = DebianSourceFormat.from_content("3.0", "native")
        self.assertEqual(dsf.type, 'native')
        self.assertTrue(source.is_native(False))

        dsf = DebianSourceFormat.from_content("3.0", "quilt")
        self.assertEqual(dsf.type, 'quilt')
        self.assertFalse(source.is_native(True))
    def test_is_native_file_3_file(self):
        """Test native package of format 3"""
        source = DebianSource('.')
        os.makedirs('debian/source')
        self.assertRaises(DebianSourceError, source.is_native)

        dsf = DebianSourceFormat.from_content("3.0", "native")
        self.assertEqual(dsf.type, 'native')
        self.assertTrue(source.is_native())

        dsf = DebianSourceFormat.from_content("3.0", "quilt")
        self.assertEqual(dsf.type, 'quilt')
        self.assertFalse(source.is_native())
Exemplo n.º 8
0
def source_vfs(repo, options, tree):
    """Init source package info either from git or from working copy"""
    # FIXME: just init the correct vfs
    try:
        if tree:
            gbp.log.debug('source_vfs returning DebianSource(GitVfs(repo=%s, tree=%s))' % (repo, tree))
            source = DebianSource(GitVfs(repo, tree))
        else:
            gbp.log.debug('source_vfs returning DebianSource(\'.\') with cwd = %s' % (os.getcwd(),))
            source = DebianSource('.')
            source.is_native() # check early if this works
    except Exception as e:
        raise GbpError("Can't determine package type: %s" % e)
    return source
Exemplo n.º 9
0
def main(argv):
    retval = 0
    source = None

    options, args = parse_args(argv, '')

    if args or not options:
        return ExitCodes.parse_error

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

    try:
        try:
            source = DebianSource(repo.path)
            source.is_native()
        except Exception as e:
            raise GbpError("Can't determine package type: %s" % e)

        if options.tarball_dir and source.upstream_version is not None:
            options.tarball_dir = PkgPolicy.version_subst(options.tarball_dir,
                                                          source.upstream_version)

        output_dir = options.tarball_dir or os.path.join(repo.path, '..')

        if source.is_native():
            gbp.log.info("Nothing to be done for native package")
            return 0

        prepare_upstream_tarballs(repo, source, options, output_dir,
                                  output_dir)
    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

    return retval
    def test_is_native_fallback_file(self):
        """Test native package without a debian/source/format file"""
        source = DebianSource('.')
        os.makedirs('debian/')
        self.assertRaises(DebianSourceError, source.is_native)

        with open('debian/changelog', 'w') as f:
            f.write("""git-buildpackage (0.2.3) git-buildpackage; urgency=low

  * git doesn't like '~' in tag names so replace this with a dot when tagging

 -- Guido Guenther <*****@*****.**>  Mon,  2 Oct 2006 18:30:20 +0200
""")
        source = DebianSource('.')
        self.assertTrue(source.is_native())
    def test_is_native_fallback_file(self):
        """Test native package without a debian/source/format file"""
        source = DebianSource('.')
        os.makedirs('debian/')
        self.assertRaises(DebianSourceError,
                          source.is_native)

        with open('debian/changelog', 'w') as f:
            f.write("""git-buildpackage (0.2.3) git-buildpackage; urgency=low

  * git doesn't like '~' in tag names so replace this with a dot when tagging

 -- Guido Guenther <*****@*****.**>  Mon,  2 Oct 2006 18:30:20 +0200
""")
        source = DebianSource('.')
        self.assertTrue(source.is_native())
 def test_control(self):
     os.makedirs('debian/')
     with open('debian/control', 'w') as f:
         f.write("Source: foo")
     source = DebianSource('.')
     self.assertIsNotNone(source.control)
     self.assertEquals(source.control.name, "foo")
Exemplo n.º 13
0
def find_upstream_commit(repo, branch, upstream_tag):
    """
    Find commit corresponding to upstream version based on changelog
    """
    vfs = gbp.git.vfs.GitVfs(repo, pq_branch_base(branch))
    cl = DebianSource(vfs).changelog
    upstream_commit = repo.find_version(upstream_tag, cl.upstream_version)
    if not upstream_commit:
        raise GbpError("Couldn't find upstream version %s" %
                       cl.upstream_version)
    return upstream_commit
    def test_cur_dir_not_toplevel(self):
        """
        Check if we can parse files if workdir != debian toplevel dir
        """
        os.makedirs('debian/')
        with open('debian/changelog', 'w') as f:
            f.write("""foo (0.2.3) unstable; urgency=low

  * git doesn't like '~' in tag names so replace this with a dot when tagging

 -- Guido Guenther <*****@*****.**>  Mon,  2 Oct 2006 18:30:20 +0200
""")
        with open('debian/control', 'w') as f:
            f.write("Source: foo")
        os.chdir('debian/')
        source = DebianSource('..')
        self.assertEquals(source.changelog.name, "foo")
        self.assertEquals(source.control.name, "foo")

        source = DebianSource(os.path.abspath('..'))
        self.assertEquals(source.changelog.name, "foo")
        self.assertEquals(source.control.name, "foo")
    def test_is_native_file_3_git(self):
        """Test native package of format 3 from git"""
        self._commit_format('3.0', 'native')
        source = DebianSource(GitVfs(self.repo))
        self.assertTrue(source.is_native())

        self._commit_format('3.0', 'quilt')
        source = DebianSource(GitVfs(self.repo))
        self.assertFalse(source.is_native())
Exemplo n.º 16
0
def source_vfs(repo, options, tree):
    """Init source package info either from git or from working copy"""
    # FIXME: just init the correct vfs
    try:
        if tree:
            source = DebianSource(GitVfs(repo, tree))
        else:
            source = DebianSource('.')
            source.is_native()  # check early if this works
    except Exception as e:
        raise GbpError("Can't determine package type: %s" % e)
    return source
Exemplo n.º 17
0
def main(argv):
    ret = 1
    repo = None

    (options, args) = parse_args(argv)
    if not options:
        return ExitCodes.parse_error

    if len(args) != 2 or args[0] not in ['commit']:
        gbp.log.err("No action given")
        return 1
    else:
        tarball = args[1]

    try:
        try:
            repo = DebianGitRepository('.')
        except GitRepositoryError:
            raise GbpError("%s is not a git repository" %
                           (os.path.abspath('.')))

        debsource = DebianSource('.')
        # FIXME: this should be a single call
        sources = [DebianUpstreamSource(tarball)]
        sources += get_component_tarballs(debsource.sourcepkg,
                                          debsource.upstream_version,
                                          sources[0].path, options.components)
        upstream_tag = repo.version_to_tag(options.upstream_tag,
                                           debsource.upstream_version)
        repo.create_pristine_tar_commits(upstream_tag, sources)
        ret = 0
    except (GitRepositoryError, GbpError, CommandExecFailed) as err:
        if str(err):
            gbp.log.err(err)
    except KeyboardInterrupt:
        gbp.log.err("Interrupted. Aborting.")

    if not ret:
        comp_msg = (' with additional tarballs for %s' %
                    ", ".join([os.path.basename(t.path)
                               for t in sources[1:]])) if sources[1:] else ''
        gbp.log.info(
            "Successfully committed pristine-tar data for version %s of %s%s" %
            (debsource.version, tarball, comp_msg))
    return ret
Exemplo n.º 18
0
def main(argv):
    ret = 0
    repo = None

    (options, args) = parse_args(argv)
    if not options:
        return ExitCodes.parse_error

    if len(args) != 2 or args[0] not in ['commit']:
        gbp.log.err("No action given")
        return 1
    else:
        tarball = args[1]

    try:
        try:
            repo = DebianGitRepository('.')
        except GitRepositoryError:
            raise GbpError("%s is not a git repository" %
                           (os.path.abspath('.')))

        source = DebianSource('.')
        component_tarballs = get_component_tarballs(source.sourcepkg,
                                                    source.upstream_version,
                                                    tarball,
                                                    options.components)
        upstream_tag = repo.version_to_tag(options.upstream_tag,
                                           source.upstream_version)
        repo.create_pristine_tar_commits(upstream_tag, tarball,
                                         component_tarballs)
    except (GitRepositoryError, GbpError, CommandExecFailed) as err:
        if str(err):
            gbp.log.err(err)
        ret = 1

    if not ret:
        comp_msg = (' with additional tarballs for %s' % ", ".join(
            [os.path.basename(t[1])
             for t in component_tarballs])) if component_tarballs else ''
        gbp.log.info(
            "Successfully committed pristine-tar data for version %s of %s%s" %
            (source.upstream_version, tarball, comp_msg))
    return ret
Exemplo n.º 19
0
def main(argv):
    retval = 1

    (options, args) = parse_args(argv)
    if not options:
        return ExitCodes.parse_error

    gbp.log.setup(options.color, options.verbose, options.color_scheme)
    try:
        repo = DebianGitRepository(os.path.curdir, toplevel=False)
    except GitRepositoryError:
        gbp.log.err("%s is not inside a git repository" %
                    (os.path.abspath('.')))
        return 1

    try:
        source = DebianSource(repo.path)
        if not (options.ignore_branch or options.ignore_new):
            if repo.branch != options.debian_branch:
                gbp.log.err(
                    "You are not on branch '%s' but on '%s'" %
                    (options.debian_branch, repo.branch or 'no branch'))
                raise GbpError("Use --ignore-branch to ignore or "
                               "--debian-branch to set the branch name.")

        if not options.ignore_new:
            (ret, out) = repo.is_clean()
            if not ret:
                gbp.log.err(
                    "You have uncommitted changes in your source tree:")
                gbp.log.err(out)
                raise GbpError("Use --ignore-new to ignore.")

        perform_tagging(repo, source, options)
        retval = 0
    except (GbpError, GitRepositoryError, DebianSourceError) as err:
        if str(err):
            gbp.log.err(err)
    except KeyboardInterrupt:
        gbp.log.err("Interrupted. Aborting.")

    return retval
Exemplo n.º 20
0
def main(argv):
    retval = 1
    branch = None
    dest = None
    to_push = {
        'refs': [],
        'tags': [],
    }

    (options, args) = parse_args(argv)
    if not options:
        return ExitCodes.parse_error

    if len(args) > 2:
        gbp.log.err("Only a single remote repository can be given")
    elif len(args) == 2:
        dest = args[1]

    gbp.log.setup(options.color, options.verbose, options.color_scheme)
    try:
        repo = DebianGitRepository(os.path.curdir, toplevel=False)
    except GitRepositoryError:
        gbp.log.err("%s is not inside a git repository" % (os.path.abspath('.')))
        return 1

    try:
        source = DebianSource(repo.path)
        branch = repo.branch
        if not options.ignore_branch:
            if branch != options.debian_branch:
                gbp.log.err("You are not on branch '%s' but %s" %
                            (options.debian_branch,
                             "on '%s'" % branch if branch else 'in detached HEAD state'))
                raise GbpError("Use --ignore-branch to ignore or --debian-branch to set the branch name.")

        if not dest:
            dest = get_remote(repo, branch)

        if options.debian_tag != '':
            dtag = repo.version_to_tag(options.debian_tag, source.version)
            if repo.has_tag(dtag):
                to_push['tags'].append(dtag)

        if source.is_releasable() and branch:
            ref = 'refs/heads/%s' % branch
            to_push['refs'].append((ref, get_push_src(repo, ref, dtag)))

        if not source.is_native():
            if options.upstream_tag != '':
                utag = repo.version_to_tag(options.upstream_tag,
                                           source.upstream_version)
                if repo.has_tag(utag):
                    to_push['tags'].append(utag)

            if options.upstream_branch != '':
                ref = 'refs/heads/%s' % options.upstream_branch
                to_push['refs'].append((ref, get_push_src(repo, ref, utag)))

            if options.pristine_tar:
                commit = repo.get_pristine_tar_commit(source)
                if commit:
                    ref = 'refs/heads/pristine-tar'
                    to_push['refs'].append((ref, get_push_src(repo, ref, commit)))

        if do_push(repo, [dest], to_push, dry_run=options.dryrun):
            retval = 0
        else:
            gbp.log.err("Failed to push some refs.")
            retval = 1
    except (GbpError, GitRepositoryError, DebianSourceError) as err:
        if str(err):
            gbp.log.err(err)
    except KeyboardInterrupt:
        gbp.log.err("Interrupted. Aborting.")

    return retval
Exemplo n.º 21
0
def main(argv):
    ret = 0
    changelog = 'debian/changelog'
    until = 'HEAD'
    found_snapshot_banner = False
    version_change = {}
    branch = None

    options, args, dch_options, editor_cmd = parse_args(argv)

    if not options:
        return ExitCodes.parse_error

    try:
        old_cwd = os.path.abspath(os.path.curdir)
        try:
            repo = DebianGitRepository('.', toplevel=False)
            os.chdir(repo.path)
        except GitRepositoryError:
            raise GbpError("%s is not a git repository" %
                           (os.path.abspath('.')))

        get_customizations(options.customization_file)
        try:
            branch = repo.get_branch()
        except GitRepositoryError:
            # Not being on any branch is o.k. with --ignore-branch
            if not options.ignore_branch:
                raise

        if options.debian_branch != branch and not options.ignore_branch:
            gbp.log.err("You are not on branch '%s' but on '%s'" %
                        (options.debian_branch, branch))
            raise GbpError(
                "Use --ignore-branch to ignore or --debian-branch to set the branch name."
            )

        source = DebianSource('.')
        cp = maybe_create_changelog(repo, source, options)

        if options.since:
            since = options.since
        else:
            since = guess_documented_commit(cp, repo, options.debian_tag)
            if since:
                msg = "Continuing from commit '%s'" % since
            else:
                msg = "Starting from first commit"
            gbp.log.info(msg)
            found_snapshot_banner = has_snapshot_banner(cp)

        if args:
            gbp.log.info("Only looking for changes on '%s'" % " ".join(args))
        commits = repo.get_commits(since=since,
                                   until=until,
                                   paths=args,
                                   options=options.git_log.split(" "))
        commits.reverse()

        add_section = False
        # add a new changelog section if:
        if (options.new_version or options.bpo or options.nmu or options.qa
                or options.team or options.security or options.local_suffix):
            if options.bpo:
                version_change['increment'] = '--bpo'
            elif options.nmu:
                version_change['increment'] = '--nmu'
            elif options.qa:
                version_change['increment'] = '--qa'
            elif options.team:
                version_change['increment'] = '--team'
            elif options.security:
                version_change['increment'] = '--security'
            elif options.local_suffix:
                version_change[
                    'increment'] = '--local=%s' % options.local_suffix
            else:
                version_change['version'] = options.new_version
            # the user wants to force a new version
            add_section = True
        elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner:
            if commits:
                # the last version was a release and we have pending commits
                add_section = True
            if options.snapshot:
                # the user want to switch to snapshot mode
                add_section = True

        if add_section and not version_change and not source.is_native():
            # Get version from upstream if none provided
            v = guess_version_from_upstream(repo, options.upstream_tag,
                                            options.upstream_branch, cp)
            if v:
                version_change['version'] = v

        i = 0
        for c in commits:
            i += 1
            parsed = parse_commit(repo,
                                  c,
                                  options,
                                  last_commit=(i == len(commits)))
            commit_msg, (commit_author, commit_email) = parsed
            if not commit_msg:
                # Some commits can be ignored
                continue

            if add_section:
                # Add a section containing just this message (we can't
                # add an empty section with dch)
                cp.add_section(distribution="UNRELEASED",
                               msg=commit_msg,
                               version=version_change,
                               author=commit_author,
                               email=commit_email,
                               dch_options=dch_options)
                # Adding a section only needs to happen once.
                add_section = False
            else:
                cp.add_entry(commit_msg, commit_author, commit_email,
                             dch_options)

        # Show a message if there were no commits (not even ignored
        # commits).
        if not commits:
            gbp.log.info("No changes detected from %s to %s." % (since, until))

        if add_section:
            # If we end up here, then there were no commits to include,
            # so we put a dummy message in the new section.
            cp.add_section(distribution="UNRELEASED",
                           msg=["UNRELEASED"],
                           version=version_change,
                           dch_options=dch_options)

        fixup_section(repo,
                      use_git_author=options.use_git_author,
                      options=options,
                      dch_options=dch_options)

        if options.release:
            do_release(changelog,
                       repo,
                       cp,
                       use_git_author=options.use_git_author,
                       dch_options=dch_options)
        elif options.snapshot:
            (snap, commit, version) = do_snapshot(changelog, repo,
                                                  options.snapshot_number)
            gbp.log.info("Changelog %s (snapshot #%d) prepared up to %s" %
                         (version, snap, commit[:7]))

        if editor_cmd:
            gbpc.Command(editor_cmd, ["debian/changelog"])()

        if options.postedit:
            cp = ChangeLog(filename=changelog)
            Hook('Postimport',
                 options.postedit,
                 extra_env={'GBP_DEBIAN_VERSION': cp.version})()

        if options.commit:
            # Get the version from the changelog file (since dch might
            # have incremented it, there's no way we can already know
            # the version).
            version = ChangeLog(filename=changelog).version
            # Commit the changes to the changelog file
            msg = changelog_commit_msg(options, version)
            repo.commit_files([changelog], msg)
            gbp.log.info("Changelog committed for version %s" % version)
    except KeyboardInterrupt:
        ret = 1
        gbp.log.err("Interrupted. Aborting.")
    except (gbpc.CommandExecFailed, GbpError, GitRepositoryError,
            DebianSourceError, NoChangeLogError) as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
        maybe_debug_raise()
    finally:
        os.chdir(old_cwd)
    return ret
Exemplo n.º 22
0
def main(argv):
    ret = 0
    changelog = 'debian/changelog'
    until = 'HEAD'
    found_snapshot_banner = False
    version_change = {}
    branch = None

    options, args, dch_options, editor_cmd = parse_args(argv)

    try:
        try:
            repo = DebianGitRepository('.')
        except GitRepositoryError:
            raise GbpError("%s is not a git repository" %
                           (os.path.abspath('.')))

        try:
            branch = repo.get_branch()
        except GitRepositoryError:
            # Not being on any branch is o.k. with --ignore-branch
            if not options.ignore_branch:
                raise

        if options.packaging_branch != branch and not options.ignore_branch:
            gbp.log.err("You are not on branch '%s' but on '%s'" %
                        (options.packaging_branch, branch))
            raise GbpError("Use --ignore-branch to ignore or --debian-branch "
                           "to set the branch name.")

        source = DebianSource('.')
        cp = source.changelog

        if options.since:
            since = options.since
        else:
            since = ''
            if options.auto:
                since = guess_documented_commit(cp, repo,
                                                options.packaging_tag)
                if since:
                    msg = "Continuing from commit '%s'" % since
                else:
                    msg = "Starting from first commit"
                gbp.log.info(msg)
                found_snapshot_banner = has_snapshot_banner(cp)
            else:  # Fallback: continue from last tag
                since = repo.find_version(options.packaging_tag, cp['Version'])
                if not since:
                    raise GbpError("Version %s not found" % cp['Version'])

        if args:
            gbp.log.info("Only looking for changes on '%s'" % " ".join(args))
        commits = repo.get_commits(since=since,
                                   until=until,
                                   paths=args,
                                   options=options.git_log.split(" "))
        commits.reverse()

        # add a new changelog section if:
        if (options.new_version or options.bpo or options.nmu or options.qa
                or options.team or options.security):
            if options.bpo:
                version_change['increment'] = '--bpo'
            elif options.nmu:
                version_change['increment'] = '--nmu'
            elif options.qa:
                version_change['increment'] = '--qa'
            elif options.team:
                version_change['increment'] = '--team'
            elif options.security:
                version_change['increment'] = '--security'
            else:
                version_change['version'] = options.new_version
            # the user wants to force a new version
            add_section = True
        elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner and commits:
            # the last version was a release and we have pending commits
            add_section = True
        elif options.snapshot and not found_snapshot_banner:
            # the user want to switch to snapshot mode
            add_section = True
        else:
            add_section = False

        if add_section and not version_change and not source.is_native():
            # Get version from upstream if none provided
            v = guess_version_from_upstream(repo, options.upstream_tag, cp)
            if v:
                version_change['version'] = v

        i = 0
        for c in commits:
            i += 1
            parsed = parse_commit(repo,
                                  c,
                                  options,
                                  last_commit=i == len(commits))
            commit_msg, (commit_author, commit_email) = parsed
            if not commit_msg:
                # Some commits can be ignored
                continue

            if add_section:
                # Add a section containing just this message (we can't
                # add an empty section with dch)
                cp.add_section(distribution="UNRELEASED",
                               msg=commit_msg,
                               version=version_change,
                               author=commit_author,
                               email=commit_email,
                               dch_options=dch_options)
                # Adding a section only needs to happen once.
                add_section = False
            else:
                cp.add_entry(commit_msg, commit_author, commit_email,
                             dch_options)

        # Show a message if there were no commits (not even ignored
        # commits).
        if not commits:
            gbp.log.info("No changes detected from %s to %s." % (since, until))

        if add_section:
            # If we end up here, then there were no commits to include,
            # so we put a dummy message in the new section.
            cp.add_section(distribution="UNRELEASED",
                           msg=["UNRELEASED"],
                           version=version_change,
                           dch_options=dch_options)

        fixup_section(repo,
                      use_git_author=options.use_git_author,
                      options=options,
                      dch_options=dch_options)

        if options.release:
            do_release(changelog,
                       repo,
                       cp,
                       use_git_author=options.use_git_author,
                       dch_options=dch_options)
        elif options.snapshot:
            (snap, version) = do_snapshot(changelog, repo,
                                          options.snapshot_number)
            gbp.log.info("Changelog has been prepared for snapshot #%d at %s" %
                         (snap, version))

        if editor_cmd:
            gbpc.Command(editor_cmd, ["debian/changelog"])()

        if options.commit:
            # Get the version from the changelog file (since dch might
            # have incremented it, there's no way we can already know
            # the version).
            version = ChangeLog(filename=changelog).version
            # Commit the changes to the changelog file
            msg = changelog_commit_msg(options, version)
            repo.commit_files([changelog], msg)
            gbp.log.info("Changelog has been committed for version %s" %
                         version)

    except (gbpc.CommandExecFailed, GbpError, GitRepositoryError,
            DebianSourceError, NoChangeLogError) as err:
        if len(err.__str__()):
            gbp.log.err(err)
        ret = 1
    return ret
Exemplo n.º 23
0
def main(argv):
    ret = 0
    changelog = 'debian/changelog'
    until = 'HEAD'
    found_snapshot_banner = False
    version_change = {}
    branch = None

    try:
        parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
                                       usage='%prog [options] paths')
    except ConfigParser.ParsingError as err:
        gbp.log.err(err)
        return 1
    range_group = GbpOptionGroup(parser, "commit range options",
                                 "which commits to add to the changelog")
    version_group = GbpOptionGroup(parser, "release & version number options",
                                   "what version number and release to use")
    commit_group = GbpOptionGroup(parser, "commit message formatting",
                                  "howto format the changelog entries")
    naming_group = GbpOptionGroup(parser, "branch and tag naming",
                                  "branch names and tag formats")
    custom_group = GbpOptionGroup(parser, "customization",
                                  "options for customization")
    parser.add_option_group(range_group)
    parser.add_option_group(version_group)
    parser.add_option_group(commit_group)
    parser.add_option_group(naming_group)
    parser.add_option_group(custom_group)

    parser.add_boolean_config_file_option(option_name = "ignore-branch", dest="ignore_branch")
    naming_group.add_config_file_option(option_name="debian-branch", dest="debian_branch")
    naming_group.add_config_file_option(option_name="upstream-tag", dest="upstream_tag")
    naming_group.add_config_file_option(option_name="debian-tag", dest="debian_tag")
    naming_group.add_config_file_option(option_name="snapshot-number", dest="snapshot_number",
                      help="expression to determine the next snapshot number, default is '%(snapshot-number)s'")
    parser.add_config_file_option(option_name="git-log", dest="git_log",
                      help="options to pass to git-log, default is '%(git-log)s'")
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
                      help="verbose command execution")
    parser.add_config_file_option(option_name="color", dest="color", type='tristate')
    parser.add_config_file_option(option_name="color-scheme",
                                  dest="color_scheme")
    range_group.add_option("-s", "--since", dest="since", help="commit to start from (e.g. HEAD^^^, debian/0.4.3)")
    range_group.add_option("-a", "--auto", action="store_true", dest="auto", default=False,
                      help="autocomplete changelog from last snapshot or tag")
    version_group.add_option("-R", "--release", action="store_true", dest="release", default=False,
                      help="mark as release")
    version_group.add_option("-S", "--snapshot", action="store_true", dest="snapshot", default=False,
                      help="mark as snapshot build")
    version_group.add_option("-D", "--distribution", dest="distribution", help="Set distribution")
    version_group.add_option("--force-distribution", action="store_true", dest="force_distribution", default=False,
                      help="Force the provided distribution to be used, even if it doesn't match the list of known distributions")
    version_group.add_option("-N", "--new-version", dest="new_version",
                      help="use this as base for the new version number")
    version_group.add_option("-U", "--urgency", dest="urgency", help="Set urgency level")
    version_group.add_option("--bpo", dest="bpo", action="store_true", default=False,
                      help="Increment the Debian release number for an upload to backports, and add a backport upload changelog comment.")
    version_group.add_option("--nmu", dest="nmu", action="store_true", default=False,
                      help="Increment the Debian release number for a non-maintainer upload")
    version_group.add_option("--qa", dest="qa", action="store_true", default=False,
                      help="Increment the Debian release number for a Debian QA Team upload, and add a QA upload changelog comment.")
    version_group.add_option("--team", dest="team", action="store_true", default=False,
                      help="Increment the Debian release number for a Debian Team upload, and add a Team upload changelog comment.")
    version_group.add_option("--security", dest="security", action="store_true", default=False,
                      help="Increment the Debian release number for a security upload and add a security upload changelog comment.")
    version_group.add_boolean_config_file_option(option_name="git-author", dest="git_author")
    commit_group.add_boolean_config_file_option(option_name="meta", dest="meta")
    commit_group.add_config_file_option(option_name="meta-closes", dest="meta_closes",
                      help="Meta tags for the bts close commands, default is '%(meta-closes)s'")
    commit_group.add_boolean_config_file_option(option_name="full", dest="full")
    commit_group.add_config_file_option(option_name="id-length", dest="idlen",
                      help="include N digits of the commit id in the changelog entry, default is '%(id-length)s'",
                      type="int", metavar="N")
    commit_group.add_config_file_option(option_name="ignore-regex", dest="ignore_regex",
                      help="Ignore commit lines matching regex, default is '%(ignore-regex)s'")
    commit_group.add_boolean_config_file_option(option_name="multimaint", dest="multimaint")
    commit_group.add_boolean_config_file_option(option_name="multimaint-merge", dest="multimaint_merge")
    commit_group.add_config_file_option(option_name="spawn-editor", dest="spawn_editor")
    parser.add_config_file_option(option_name="commit-msg",
                      dest="commit_msg")
    parser.add_option("-c", "--commit", action="store_true", dest="commit", default=False,
                      help="commit changelog file after generating")

    help_msg = ('Load Python code from CUSTOMIZATION_FILE.  At the moment,'
                ' the only useful thing the code can do is define a custom'
                ' format_changelog_entry() function.')
    custom_group.add_config_file_option(option_name="customizations",
                                        dest="customization_file",
                                        help=help_msg)

    (options, args) = parser.parse_args(argv[1:])
    gbp.log.setup(options.color, options.verbose, options.color_scheme)
    dch_options = process_options(options, parser)
    editor_cmd = process_editor_option(options)

    try:
        try:
            repo = DebianGitRepository('.')
        except GitRepositoryError:
            raise GbpError("%s is not a git repository" % (os.path.abspath('.')))

        try:
            branch = repo.get_branch()
        except GitRepositoryError:
            # Not being on any branch is o.k. with --ignore-branch
            if not options.ignore_branch:
                raise

        if options.debian_branch != branch and not options.ignore_branch:
            gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch))
            raise GbpError("Use --ignore-branch to ignore or --debian-branch to set the branch name.")

        source = DebianSource('.')
        cp = source.changelog

        if options.since:
            since = options.since
        else:
            since = ''
            if options.auto:
                since = guess_documented_commit(cp, repo, options.debian_tag)
                if since:
                    msg = "Continuing from commit '%s'" % since
                else:
                    msg = "Starting from first commit"
                gbp.log.info(msg)
                found_snapshot_banner = has_snapshot_banner(cp)
            else: # Fallback: continue from last tag
                since = repo.find_version(options.debian_tag, cp['Version'])
                if not since:
                    raise GbpError("Version %s not found" % cp['Version'])

        if args:
            gbp.log.info("Only looking for changes on '%s'" % " ".join(args))
        commits = repo.get_commits(since=since, until=until, paths=args,
                                   options=options.git_log.split(" "))
        commits.reverse()

        # add a new changelog section if:
        if (options.new_version or options.bpo or options.nmu or options.qa or
            options.team or options.security):
            if options.bpo:
                version_change['increment'] = '--bpo'
            elif options.nmu:
                version_change['increment'] = '--nmu'
            elif options.qa:
                version_change['increment'] = '--qa'
            elif options.team:
                version_change['increment'] = '--team'
            elif options.security:
                version_change['increment'] = '--security'
            else:
                version_change['version'] = options.new_version
            # the user wants to force a new version
            add_section = True
        elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner and commits:
            # the last version was a release and we have pending commits
            add_section = True
        elif options.snapshot and not found_snapshot_banner:
            # the user want to switch to snapshot mode
            add_section = True
        else:
            add_section = False

        has_upstream_tag = repo.has_upstream_tag(options.upstream_tag)
        if add_section and not version_change and not source.is_native(has_upstream_tag):
            # Get version from upstream if none provided
            v = guess_version_from_upstream(repo, options.upstream_tag, cp)
            if v:
                version_change['version'] = v

        i = 0
        for c in commits:
            i += 1
            parsed = parse_commit(repo, c, options,
                                  last_commit = i == len(commits))
            commit_msg, (commit_author, commit_email) = parsed
            if not commit_msg:
                # Some commits can be ignored
                continue

            if add_section:
                # Add a section containing just this message (we can't
                # add an empty section with dch)
                cp.add_section(distribution="UNRELEASED", msg=commit_msg,
                               version=version_change,
                               author=commit_author,
                               email=commit_email,
                               dch_options=dch_options)
                # Adding a section only needs to happen once.
                add_section = False
            else:
                cp.add_entry(commit_msg, commit_author, commit_email, dch_options)


        # Show a message if there were no commits (not even ignored
        # commits).
        if not commits:
            gbp.log.info("No changes detected from %s to %s." % (since, until))

        if add_section:
            # If we end up here, then there were no commits to include,
            # so we put a dummy message in the new section.
            cp.add_section(distribution="UNRELEASED", msg=["UNRELEASED"],
                           version=version_change,
                           dch_options=dch_options)

        fixup_section(repo, git_author=options.git_author, options=options,
                      dch_options=dch_options)

        if options.release:
            do_release(changelog, repo, cp, git_author=options.git_author,
                       dch_options=dch_options)
        elif options.snapshot:
            (snap, version) = do_snapshot(changelog, repo, options.snapshot_number)
            gbp.log.info("Changelog has been prepared for snapshot #%d at %s" % (snap, version))

        if editor_cmd:
            gbpc.Command(editor_cmd, ["debian/changelog"])()

        if options.commit:
            # Get the version from the changelog file (since dch might
            # have incremented it, there's no way we can already know
            # the version).
            version = ChangeLog(filename=changelog).version
            # Commit the changes to the changelog file
            msg = changelog_commit_msg(options, version)
            repo.commit_files([changelog], msg)
            gbp.log.info("Changelog has been committed for version %s" % version)

    except (gbpc.CommandExecFailed,
            GbpError,
            GitRepositoryError,
            DebianSourceError,
            NoChangeLogError) as err:
        if len(err.__str__()):
            gbp.log.err(err)
        ret = 1
    return ret
Exemplo n.º 24
0
def main(argv):
    retval = 0
    prefix = "git-"
    source = None
    branch = None

    options, gbp_args, dpkg_args = parse_args(argv, prefix)
    
    if not options:
        return 1

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

    try:
        Command(options.cleaner, shell=True)()
        if not options.ignore_new:
            (ret, out) = repo.is_clean()
            if not ret:
                gbp.log.err("You have uncommitted changes in your source tree:")
                gbp.log.err(out)
                raise GbpError("Use --git-ignore-new to ignore.")

        try:
            branch = repo.get_branch()
        except GitRepositoryError:
            # Not being on any branch is o.k. with --git-ignore-branch
            if not options.ignore_branch:
                raise

        if not options.ignore_new and not options.ignore_branch:
            if branch != options.debian_branch:
                gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch))
                raise GbpError("Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name.")

        head = repo.head
        tree = 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

            # 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.
            is_native = source.is_native()
            gbp.log.debug('Is the package Debian-native? %s' % (is_native,))
            if not is_native:
                if options.postexport:
                    gbp.log.info("Postexport hook set, delaying tarball creation")
                else:
                    gbp.log.info('Preparing upstream tarball (not delayed)...')
                    prepare_upstream_tarball(repo, source.changelog, options, tarball_dir,
                                             output_dir)

            # Export to another build dir if requested:
            if options.export_dir:
                gbp.log.debug('export_dir is set...')
                sourcepkg = source.sourcepkg
                assert sourcepkg is not None
                gbp.log.debug('sourcepkg = %s' % (sourcepkg,))
                tmp_dir = os.path.join(output_dir, "%s-tmp" % sourcepkg)
                export_source(repo, tree, source, options, tmp_dir, output_dir)

                # XXX: @KK:
                gbp.log.debug('Changing source to use tmp_dir=%s' % (tmp_dir,))
                source = DebianSource(tmp_dir)
                
                # Run postexport hook
                gbp.log.debug('running post-export hook...') 
                if options.postexport:
                    Hook('Postexport', options.postexport, shell=True,
                         extra_env={'GBP_GIT_DIR': repo.git_dir,
                                    'GBP_TMP_DIR': tmp_dir})(dir=tmp_dir)

                    # @KK: This is unnecessary because we are creating a new DebianSource object above now, anyhow.
                    assert source._changelog is None
                    # # XXX: Using source.sourcepkg causes debian/changelog to be parsed (and then
                    # # cached); but we want our post-export hook to be able to change it!
                    # source._changelog = None

                if source.changelog.upstream_version is None and not source.is_native():
                    raise GbpError('This package is not Debian-native (according to debian/source/format), but the '
                                   'last version number in debian/changelog does not seem to contain a dash (-) to  '
                                   'separate the Debian version from the upstream version.  (The raw version string '
                                   'is {!r}.)'.format(source.changelog.version))
                    
                major = (source.changelog.debian_version if source.is_native()
                         else source.changelog.upstream_version)
                if major is None:
                    raise GbpError('Cannot determine upstream version from changelog.')
                
                export_dir = os.path.join(output_dir, "%s-%s" % (source.sourcepkg, major))
                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:
                    gbp.log.debug('Preparing upstream tarball (delayed)...')
                    prepare_upstream_tarball(repo, source.changelog, options, tarball_dir,
                                             output_dir)

            if options.export_dir:
                build_dir = export_dir
            else:
                build_dir = repo_dir

            if options.prebuild:
                Hook('Prebuild', options.prebuild, shell=True,
                     extra_env={'GBP_GIT_DIR': repo.git_dir,
                                'GBP_BUILD_DIR': build_dir,
                                'GBP_PBUILDER_DIST': get_pbuilder_dist(options,
                                                                       repo,
                                                                       source.is_native()),
                                })(dir=build_dir)

            setup_pbuilder(options, repo, source.is_native())
            # Finally build the package:
            RunAtCommand(options.builder, dpkg_args, shell=True,
                         extra_env={'GBP_BUILD_DIR': build_dir})(dir=build_dir)
            if options.postbuild:
                changes = os.path.abspath("%s/../%s_%s_%s.changes" %
                                          (build_dir,
                                           source.sourcepkg,
                                           source.changelog.noepoch,
                                           changes_file_suffix(dpkg_args)))
                gbp.log.debug("Looking for changes file %s" % changes)
                Hook('Postbuild', options.postbuild, shell=True,
                     extra_env={'GBP_CHANGES_FILE': changes,
                                'GBP_BUILD_DIR': build_dir})()
        if options.tag or options.tag_only:
            tag = repo.version_to_tag(options.debian_tag, source.changelog.version)
            gbp.log.info("Tagging %s as %s" % (source.changelog.version, tag))
            if options.retag and repo.has_tag(tag):
                repo.delete_tag(tag)
            tag_msg = format_str(options.debian_tag_msg,
                                 dict(pkg=source.sourcepkg,
                                      version=source.changelog.version))
            repo.create_tag(name=tag,
                            msg=tag_msg,
                            sign=options.sign_tags,
                            commit=head,
                            keyid=options.keyid)
            if options.posttag:
                sha = repo.rev_parse("%s^{}" % tag)
                Hook('Posttag', options.posttag, shell=True,
                     extra_env={'GBP_TAG': tag,
                                'GBP_BRANCH': branch or '(no branch)',
                                'GBP_SHA1': sha})()
    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()

    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
Exemplo n.º 25
0
def main(argv):
    retval = 1
    branch = None
    dest = None
    to_push = {
        'refs': [],
        'tags': [],
    }

    (options, args) = parse_args(argv)
    if not options:
        return ExitCodes.parse_error

    if len(args) > 2:
        gbp.log.err("Only a single remote repository can be given")
    elif len(args) == 2:
        dest = args[1]

    gbp.log.setup(options.color, options.verbose, options.color_scheme)
    try:
        repo = DebianGitRepository(os.path.curdir, toplevel=False)
    except GitRepositoryError:
        gbp.log.err("%s is not inside a git repository" %
                    (os.path.abspath('.')))
        return 1

    try:
        source = DebianSource(repo.path)
        branch = repo.branch
        if not options.ignore_branch:
            if branch != options.debian_branch:
                gbp.log.err("You are not on branch '%s' but %s" %
                            (options.debian_branch, "on '%s'" %
                             branch if branch else 'in detached HEAD state'))
                raise GbpError(
                    "Use --ignore-branch to ignore or --debian-branch to set the branch name."
                )

        if not dest:
            dest = get_remote(repo, branch)

        if options.debian_tag != '':
            dtag = repo.version_to_tag(options.debian_tag, source.version)
            if repo.has_tag(dtag):
                to_push['tags'].append(dtag)

        if source.is_releasable() and branch:
            ref = 'refs/heads/%s' % branch
            to_push['refs'].append((ref, get_push_src(repo, ref, dtag)))

        if not source.is_native():
            if options.upstream_tag != '':
                utag = repo.version_to_tag(options.upstream_tag,
                                           source.upstream_version)
                if repo.has_tag(utag):
                    to_push['tags'].append(utag)

            if options.upstream_branch != '':
                ref = 'refs/heads/%s' % options.upstream_branch
                to_push['refs'].append((ref, get_push_src(repo, ref, utag)))

            if options.pristine_tar:
                commit = repo.get_pristine_tar_commit(source)
                if commit:
                    ref = 'refs/heads/pristine-tar'
                    to_push['refs'].append(
                        (ref, get_push_src(repo, ref, commit)))

        if do_push(repo, [dest], to_push, dry_run=options.dryrun):
            retval = 0
        else:
            gbp.log.err("Failed to push some refs.")
            retval = 1
    except (GbpError, GitRepositoryError, DebianSourceError) as err:
        if str(err):
            gbp.log.err(err)
    except KeyboardInterrupt:
        gbp.log.err("Interrupted. Aborting.")

    return retval
Exemplo n.º 26
0
def main(argv):
    ret = 0
    changelog = "debian/changelog"
    until = "HEAD"
    found_snapshot_banner = False
    version_change = {}
    branch = None

    options, args, dch_options, editor_cmd = parse_args(argv)

    try:
        try:
            repo = DebianGitRepository(".")
        except GitRepositoryError:
            raise GbpError("%s is not a git repository" % (os.path.abspath(".")))

        try:
            branch = repo.get_branch()
        except GitRepositoryError:
            # Not being on any branch is o.k. with --ignore-branch
            if not options.ignore_branch:
                raise

        if options.debian_branch != branch and not options.ignore_branch:
            gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch))
            raise GbpError("Use --ignore-branch to ignore or --debian-branch to set the branch name.")

        source = DebianSource(".")
        cp = source.changelog

        if options.since:
            since = options.since
        else:
            since = ""
            if options.auto:
                since = guess_documented_commit(cp, repo, options.debian_tag)
                if since:
                    msg = "Continuing from commit '%s'" % since
                else:
                    msg = "Starting from first commit"
                gbp.log.info(msg)
                found_snapshot_banner = has_snapshot_banner(cp)
            else:  # Fallback: continue from last tag
                since = repo.find_version(options.debian_tag, cp["Version"])
                if not since:
                    raise GbpError("Version %s not found" % cp["Version"])

        if args:
            gbp.log.info("Only looking for changes on '%s'" % " ".join(args))
        commits = repo.get_commits(since=since, until=until, paths=args, options=options.git_log.split(" "))
        commits.reverse()

        # add a new changelog section if:
        if options.new_version or options.bpo or options.nmu or options.qa or options.team or options.security:
            if options.bpo:
                version_change["increment"] = "--bpo"
            elif options.nmu:
                version_change["increment"] = "--nmu"
            elif options.qa:
                version_change["increment"] = "--qa"
            elif options.team:
                version_change["increment"] = "--team"
            elif options.security:
                version_change["increment"] = "--security"
            else:
                version_change["version"] = options.new_version
            # the user wants to force a new version
            add_section = True
        elif cp["Distribution"] != "UNRELEASED" and not found_snapshot_banner and commits:
            # the last version was a release and we have pending commits
            add_section = True
        elif options.snapshot and not found_snapshot_banner:
            # the user want to switch to snapshot mode
            add_section = True
        else:
            add_section = False

        if add_section and not version_change and not source.is_native():
            # Get version from upstream if none provided
            v = guess_version_from_upstream(repo, options.upstream_tag, cp)
            if v:
                version_change["version"] = v

        i = 0
        for c in commits:
            i += 1
            parsed = parse_commit(repo, c, options, last_commit=i == len(commits))
            commit_msg, (commit_author, commit_email) = parsed
            if not commit_msg:
                # Some commits can be ignored
                continue

            if add_section:
                # Add a section containing just this message (we can't
                # add an empty section with dch)
                cp.add_section(
                    distribution="UNRELEASED",
                    msg=commit_msg,
                    version=version_change,
                    author=commit_author,
                    email=commit_email,
                    dch_options=dch_options,
                )
                # Adding a section only needs to happen once.
                add_section = False
            else:
                cp.add_entry(commit_msg, commit_author, commit_email, dch_options)

        # Show a message if there were no commits (not even ignored
        # commits).
        if not commits:
            gbp.log.info("No changes detected from %s to %s." % (since, until))

        if add_section:
            # If we end up here, then there were no commits to include,
            # so we put a dummy message in the new section.
            cp.add_section(
                distribution="UNRELEASED", msg=["UNRELEASED"], version=version_change, dch_options=dch_options
            )

        fixup_section(repo, git_author=options.git_author, options=options, dch_options=dch_options)

        if options.release:
            do_release(changelog, repo, cp, git_author=options.git_author, dch_options=dch_options)
        elif options.snapshot:
            (snap, version) = do_snapshot(changelog, repo, options.snapshot_number)
            gbp.log.info("Changelog has been prepared for snapshot #%d at %s" % (snap, version))

        if editor_cmd:
            gbpc.Command(editor_cmd, ["debian/changelog"])()

        if options.commit:
            # Get the version from the changelog file (since dch might
            # have incremented it, there's no way we can already know
            # the version).
            version = ChangeLog(filename=changelog).version
            # Commit the changes to the changelog file
            msg = changelog_commit_msg(options, version)
            repo.commit_files([changelog], msg)
            gbp.log.info("Changelog has been committed for version %s" % version)

    except (gbpc.CommandExecFailed, GbpError, GitRepositoryError, DebianSourceError, NoChangeLogError) as err:
        if len(err.__str__()):
            gbp.log.err(err)
        ret = 1
    return ret
 def test_is_native_fallback_file(self):
     """Test native package without a debian/source/format file"""
     source = DebianSource('.')
     os.makedirs('debian/')
     self.assertFalse(source.is_native(True))
     self.assertTrue(source.is_native(False))