Пример #1
0
    def test_update_changelog(self):
        self.build_tree_contents([
            ("debian/", ),
            (
                "debian/lintian-brush.conf",
                """\
update-changelog = True
""",
            ),
        ])
        cfg = Config("debian/lintian-brush.conf")
        self.assertEqual(True, cfg.update_changelog())
Пример #2
0
    def test_minimum_certainty(self):
        self.build_tree_contents([
            ("debian/", ),
            (
                "debian/lintian-brush.conf",
                """\
minimum-certainty = possible
""",
            ),
        ])
        cfg = Config("debian/lintian-brush.conf")
        self.assertEqual("possible", cfg.minimum_certainty())
Пример #3
0
    def test_compat_release(self):
        debian = DebianDistroInfo()
        self.build_tree_contents([
            ("debian/", ),
            (
                "debian/lintian-brush.conf",
                """\
compat-release = testing
""",
            ),
        ])
        cfg = Config("debian/lintian-brush.conf")
        self.assertEqual(debian.testing(), cfg.compat_release())
Пример #4
0
    def test_unknown(self):
        self.build_tree_contents([
            ("debian/", ),
            (
                "debian/lintian-brush.conf",
                """\
unknown = dunno
""",
            ),
        ])
        with self.assertWarns(Warning):
            Config("debian/lintian-brush.conf")
Пример #5
0
    def make_changes(
        self,
        local_tree,
        subpath,
        update_changelog,
        reporter,
        committer,
        base_proposal=None,
    ):
        from lintian_brush import NoChanges
        from lintian_brush.multiarch_hints import (
            MultiArchHintFixer, )

        base_revid = local_tree.last_revision()
        minimum_certainty = self.minimum_certainty
        allow_reformatting = self.allow_reformatting
        try:
            cfg = Config.from_workingtree(local_tree, subpath)
        except FileNotFoundError:
            pass
        else:
            if minimum_certainty is None:
                minimum_certainty = cfg.minimum_certainty()
            if allow_reformatting is None:
                allow_reformatting = cfg.allow_reformatting()
            if update_changelog is None:
                update_changelog = cfg.update_changelog()

        if control_files_in_root(local_tree, subpath):
            raise ChangerError(
                "control-files-in-root",
                "control files live in root rather than debian/ "
                "(LarstIQ mode)",
            )

        if is_debcargo_package(local_tree, subpath):
            raise ChangerError("nothing-to-do", "Package uses debcargo")
        elif not control_file_present(local_tree, subpath):
            raise ChangerError("missing-control-file",
                               "Unable to find debian/control")

        try:
            with local_tree.lock_write():
                result, summary = run_lintian_fixer(
                    local_tree,
                    MultiArchHintFixer(self.hints),
                    update_changelog=update_changelog,
                    minimum_certainty=minimum_certainty,
                    subpath=subpath,
                    allow_reformatting=allow_reformatting,
                    net_access=True,
                    committer=committer,
                    changes_by="apply-multiarch-hints",
                )
        except NoChanges:
            raise ChangerError("nothing-to-do", "no hints to apply")
        except FormattingUnpreservable as e:
            raise ChangerError(
                "formatting-unpreservable",
                "unable to preserve formatting while editing %s" % e.path,
            )
        except GeneratedFile as e:
            raise ChangerError("generated-file",
                               "unable to edit generated file: %r" % e)

        applied_hints = []
        hint_names = []
        for (binary, hint, description, certainty) in result.changes:
            hint_names.append(hint["link"].split("#")[-1])
            entry = dict(hint.items())
            hint_names.append(entry["link"].split("#")[-1])
            entry["action"] = description
            entry["certainty"] = certainty
            applied_hints.append(entry)
            logging.info("%s: %s" % (binary["Package"], description))

        reporter.report_metadata("applied-hints", applied_hints)

        branches = [("main", None, base_revid, local_tree.last_revision())]

        tags = []

        return ChangerResult(
            description="Applied multi-arch hints.",
            mutator=result,
            branches=branches,
            tags=tags,
            value=calculate_value(hint_names),
            sufficient_for_proposal=True,
            proposed_commit_message="Apply multi-arch hints.",
        )
Пример #6
0
    def make_changes(  # noqa: C901
            self,
            local_tree,
            subpath,
            update_changelog,
            reporter,
            committer,
            base_proposal=None):
        base_revid = local_tree.last_revision()
        upstream_base_revid = NULL_REVISION

        reporter.report_metadata(
            "versions",
            {
                "lintian-brush": lintian_brush_version_string,
                "silver-platter": silver_platter.version_string,
                "breezy": breezy.version_string,
            },
        )

        import distro_info

        debian_info = distro_info.DebianDistroInfo()

        compat_release = self.compat_release
        try:
            cfg = Config.from_workingtree(local_tree, subpath)
        except FileNotFoundError:
            pass
        else:
            compat_release = cfg.compat_release()
            if compat_release:
                compat_release = debian_info.codename(compat_release,
                                                      default=compat_release)
        if compat_release is None:
            compat_release = debian_info.stable()

        # For now...
        upstream_branch = local_tree.branch
        upstream_subpath = subpath

        with local_tree.lock_write():
            try:
                result = debianize(
                    local_tree,
                    subpath=subpath,
                    upstream_branch=upstream_branch,
                    upstream_subpath=upstream_subpath,
                    compat_release=self.compat_release,
                    schroot=self.schroot,
                    diligence=self.diligence,
                    trust=self.trust,
                    verbose=self.verbose,
                    force_new_directory=self.force_new_directory,
                    create_dist=getattr(self, 'create_dist', None))
            except OSError as e:
                if e.errno == errno.ENOSPC:
                    raise ChangerError('no-space-on-device', str(e))
                else:
                    raise
            except DebianDirectoryExists:
                raise ChangerError(
                    'debian-directory-exists',
                    "A debian/ directory already exists in the upstream project."
                )
            except SourcePackageNameInvalid as e:
                raise ChangerError(
                    'invalid-source-package-name',
                    "Generated source package name %r is not valid." %
                    e.source)
            except NoBuildToolsFound:
                raise ChangerError(
                    'no-build-tools',
                    "Unable to find any build systems in upstream sources.")
            except NoUpstreamReleases:
                raise ChangerError(
                    'no-upstream-releases',
                    'The upstream project does not appear to have made any releases.'
                )
            except DistCommandFailed as e:
                raise ChangerError("dist-command-failed", str(e), e)
            except DetailedFailure as e:
                raise ChangerError('dist-%s' % e.error.kind, str(e.error))
            except UnidentifiedError as e:
                if e.secondary:
                    raise ChangerError('dist-command-failed',
                                       str(e.secondary.line))
                else:
                    raise ChangerError('dist-command-failed', e.lines[-1])
            except DistCreationFailed as e:
                if e.inner:
                    raise ChangerError('dist-%s' % e.inner.kind, e.msg)
                else:
                    raise ChangerError('dist-command-failed', e.msg)

        # TODO(jelmer): Pristine tar branch?
        branches = [
            ("main", None, base_revid, local_tree.last_revision()),
        ]
        if result.upstream_branch_name:
            branches.append((
                "upstream",
                result.upstream_branch_name,
                upstream_base_revid,
                local_tree.controldir.open_branch(
                    result.upstream_branch_name).last_revision(),
            ))

        tags = [(("upstream", str(result.upstream_version), component), tag,
                 local_tree.branch.tags.lookup_tag(tag))
                for (component, tag) in result.tag_names.items()]

        reporter.report_metadata("wnpp_bugs", result.wnpp_bugs)

        return ChangerResult(
            description="Debianized package.",
            mutator=None,
            branches=branches,
            tags=tags,
            value=None,
            sufficient_for_proposal=True,
        )
Пример #7
0
    def make_changes(  # noqa: C901
        self,
        local_tree,
        subpath,
        update_changelog,
        reporter,
        committer,
        base_proposal=None,
    ):
        base_revid = local_tree.last_revision()

        reporter.report_metadata(
            "versions",
            {
                "lintian-brush": lintian_brush_version_string,
                "silver-platter": silver_platter.version_string,
                "breezy": breezy.version_string,
            },
        )

        import distro_info

        debian_info = distro_info.DebianDistroInfo()

        compat_release = self.compat_release
        allow_reformatting = self.allow_reformatting
        minimum_certainty = None
        try:
            cfg = Config.from_workingtree(local_tree, subpath)
        except FileNotFoundError:
            pass
        else:
            compat_release = cfg.compat_release()
            if compat_release:
                compat_release = debian_info.codename(
                    compat_release, default=compat_release
                )
            allow_reformatting = cfg.allow_reformatting()
            minimum_certainty = cfg.minimum_certainty()
        if compat_release is None:
            compat_release = debian_info.stable()
        if allow_reformatting is None:
            allow_reformatting = False
        if minimum_certainty is None:
            minimum_certainty = DEFAULT_MINIMUM_CERTAINTY

        with local_tree.lock_write():
            if control_files_in_root(local_tree, subpath):
                raise ChangerError(
                    "control-files-in-root",
                    "control files live in root rather than debian/ " "(LarstIQ mode)",
                )

            try:
                overall_result = run_lintian_fixers(
                    local_tree,
                    self.fixers,
                    committer=committer,
                    update_changelog=update_changelog,
                    compat_release=compat_release,
                    allow_reformatting=allow_reformatting,
                    minimum_certainty=minimum_certainty,
                    subpath=subpath,
                    diligence=self.diligence,
                    opinionated=self.opinionated,
                    trust_package=self.trust_package,
                )
            except NotDebianPackage:
                raise ChangerError("not-debian-package", "Not a Debian package")
            except ChangelogCreateError as e:
                raise ChangerError(
                    "changelog-create-error", "Error creating changelog entry: %s" % e
                )

        applied = []
        base_applied = reporter.get_base_metadata("applied", [])
        if base_applied:
            applied.extend(base_applied)
        for result, summary in overall_result.success:
            applied.append(
                {
                    "summary": summary,
                    "description": result.description,
                    "fixed_lintian_tags": result.fixed_lintian_tags,
                    "revision_id": result.revision_id.decode("utf-8"),
                    "certainty": result.certainty,
                }
            )
        reporter.report_metadata("applied", applied)

        if overall_result.failed_fixers:
            for fixer_name, failure in overall_result.failed_fixers.items():
                logging.info("Fixer %r failed to run:", fixer_name)
                sys.stderr.write(str(failure))
        reporter.report_metadata(
            "failed",
            {name: str(e) for (name, e) in overall_result.failed_fixers.items()},
        )

        if not overall_result.success:
            raise ChangerError("nothing-to-do", "no fixers to apply")

        fixed_lintian_tags = set()
        for result, summary in overall_result.success:
            fixed_lintian_tags.update(result.fixed_lintian_tags)

        add_on_only = not has_nontrivial_changes(
            overall_result.success, self.propose_addon_only
        )

        if not reporter.get_base_metadata("add_on_only", False):
            add_on_only = False

        if not add_on_only:
            if overall_result.success:
                logging.info("only add-on fixers found")
            sufficient_for_proposal = False
            reporter.report_metadata("add_on_only", True)
        else:
            sufficient_for_proposal = True
            reporter.report_metadata("add_on_only", False)

        branches = [("main", None, base_revid, local_tree.last_revision())]

        return ChangerResult(
            description="Applied fixes for %r" % fixed_lintian_tags,
            mutator=overall_result.success,
            branches=branches,
            tags=[],
            value=calculate_value(fixed_lintian_tags),
            sufficient_for_proposal=sufficient_for_proposal,
            proposed_commit_message=update_proposal_commit_message(
                base_proposal, overall_result.success
            ),
        )
Пример #8
0
    def make_changes(
        self,
        local_tree,
        subpath,
        update_changelog,
        reporter,
        committer,
        base_proposal=None,
    ):
        from lintian_brush.scrub_obsolete import scrub_obsolete

        import distro_info

        debian_info = distro_info.DebianDistroInfo()
        if self.compat_release:
            compat_release = debian_info.codename(self.compat_release)
        else:
            compat_release = None

        upgrade_release = debian_info.codename(self.upgrade_release)

        base_revid = local_tree.last_revision()
        allow_reformatting = self.allow_reformatting
        try:
            cfg = Config.from_workingtree(local_tree, subpath)
        except FileNotFoundError:
            pass
        else:
            if allow_reformatting is None:
                allow_reformatting = cfg.allow_reformatting()
            if update_changelog is None:
                update_changelog = cfg.update_changelog()
            if compat_release is None:
                compat_release = cfg.compat_release()

        if compat_release is None:
            compat_release = debian_info.stable()

        if is_debcargo_package(local_tree, subpath):
            raise ChangerError("nothing-to-do", "Package uses debcargo")
        elif not control_file_present(local_tree, subpath):
            raise ChangerError("missing-control-file",
                               "Unable to find debian/control")

        try:
            result = scrub_obsolete(
                local_tree,
                subpath,
                compat_release,
                upgrade_release,
                update_changelog=update_changelog,
            )
        except FormattingUnpreservable as e:
            raise ChangerError(
                "formatting-unpreservable",
                "unable to preserve formatting while editing %s" % e.path,
            )
        except GeneratedFile as e:
            raise ChangerError("generated-file",
                               "unable to edit generated file: %r" % e)
        except NotDebianPackage:
            raise ChangerError("not-debian-package", "Not a Debian package")

        if not result:
            raise ChangerError("nothing-to-do", "no obsolete constraints")

        branches = [("main", None, base_revid, local_tree.last_revision())]

        tags = []

        return ChangerResult(
            description="Scrub obsolete settings.",
            mutator=result,
            branches=branches,
            tags=tags,
            value=calculate_value(result),
            sufficient_for_proposal=True,
            proposed_commit_message="Scrub obsolete settings.",
        )