Beispiel #1
0
def main(argv: Optional[List[str]] = None) -> Optional[int]:
    import breezy

    breezy.initialize()
    parser = argparse.ArgumentParser(prog="svp", add_help=False)
    parser.add_argument("--version",
                        action="version",
                        version="%(prog)s " + version_string)
    parser.add_argument("--help",
                        action="store_true",
                        help="show this help message and exit")
    parser.add_argument("subcommand",
                        type=str,
                        choices=list(subcommands.keys()))
    logging.basicConfig(level=logging.INFO, format="%(message)s")
    args, rest = parser.parse_known_args(argv)
    if args.help:
        if args.subcommand is None:
            parser.print_help()
            parser.exit()
        else:
            rest.append("--help")
    if args.subcommand is None:
        parser.print_usage()
        return 1
    return subcommands[args.subcommand](rest)
Beispiel #2
0
def main(argv: Optional[List[str]] = None) -> Optional[int]:
    import breezy

    breezy.initialize()

    from ..__main__ import subcommands as main_subcommands

    subcommands: Dict[str, Callable[[List[str]], Optional[int]]] = {
        "upload-pending": debian_uploader.main,
    }

    parser = argparse.ArgumentParser(prog="debian-svp", add_help=False)
    parser.add_argument(
        "--version",
        action="version",
        version="%(prog)s " + silver_platter.version_string,
    )
    parser.add_argument("--debug", action="store_true", help="Be more verbose")
    parser.add_argument("--help",
                        action="store_true",
                        help="show this help message and exit")

    subcommands.update(main_subcommands.items())

    # We have a debian-specific run command
    del subcommands["run"]

    parser.add_argument("subcommand",
                        type=str,
                        choices=list(subcommands.keys()) +
                        changer_subcommands())
    args, rest = parser.parse_known_args()
    if args.help:
        if args.subcommand is None:
            parser.print_help()
            parser.exit()
        else:
            rest.append("--help")

    if args.subcommand is None:
        parser.print_usage()
        return 1
    if args.subcommand in subcommands:
        return subcommands[args.subcommand](rest)
    try:
        subcmd = changer_subcommand(args.subcommand)
    except KeyError:
        pass
    else:
        if args.debug:
            level = logging.DEBUG
        else:
            level = logging.INFO
        logging.basicConfig(level=level, format="%(message)s")
        return run_changer_subcommand(args.subcommand, subcmd, rest)
    parser.print_usage()
    return 1
Beispiel #3
0
def main(argv):
    parser = OptionParser(usage="""%prog [options] OUTPUT_FORMAT

Available OUTPUT_FORMAT:

    man              man page
    rstx             man page in ReStructuredText format
    bash_completion  bash completion script""")

    parser.add_option("-s",
                      "--show-filename",
                      action="store_true",
                      dest="show_filename",
                      default=False,
                      help="print default filename on stdout")

    parser.add_option("-o",
                      "--output",
                      dest="filename",
                      metavar="FILE",
                      help="write output to FILE")

    parser.add_option("-b",
                      "--brz-name",
                      dest="brz_name",
                      default="brz",
                      metavar="EXEC_NAME",
                      help="name of brz executable")

    parser.add_option("-e",
                      "--examples",
                      action="callback",
                      callback=print_extended_help,
                      help="Examples of ways to call generate_doc")

    (options, args) = parser.parse_args(argv)

    if len(args) != 2:
        parser.print_help()
        sys.exit(1)

    with breezy.initialize(), ExitStack() as es:
        # Import breezy.bzr for format registration, see <http://pad.lv/956860>
        from breezy import bzr as _
        commands.install_bzr_command_hooks()
        infogen_type = args[1]
        infogen_mod = doc_generate.get_module(infogen_type)
        if options.filename:
            outfilename = options.filename
        else:
            outfilename = infogen_mod.get_filename(options)
        if outfilename == "-":
            outfile = sys.stdout
        else:
            outfile = es.enter_context(open(outfilename, "w"))
        if options.show_filename and (outfilename != "-"):
            sys.stdout.write(outfilename)
            sys.stdout.write('\n')
        infogen_mod.infogen(options, outfile)
Beispiel #4
0
def main():  # noqa: C901
    import argparse
    import breezy  # noqa: E402
    import logging

    breezy.initialize()
    import breezy.git  # noqa: E402
    import breezy.bzr  # noqa: E402

    from breezy.workingtree import WorkingTree
    from breezy.workspace import (
        check_clean_tree,
        WorkspaceDirty,
    )
    from . import (
        get_committer,
        version_string,
    )
    from .config import Config

    parser = argparse.ArgumentParser(prog="deb-update-watch")
    parser.add_argument(
        "--directory",
        metavar="DIRECTORY",
        help="directory to run in",
        type=str,
        default=".",
    )
    parser.add_argument(
        "--no-update-changelog",
        action="store_false",
        default=None,
        dest="update_changelog",
        help="do not update the changelog",
    )
    parser.add_argument(
        "--update-changelog",
        action="store_true",
        dest="update_changelog",
        help="force updating of the changelog",
        default=None,
    )
    parser.add_argument(
        "--allow-reformatting",
        default=None,
        action="store_true",
        help=argparse.SUPPRESS,
    )
    parser.add_argument("--version",
                        action="version",
                        version="%(prog)s " + version_string)
    parser.add_argument(
        "--identity",
        help="Print user identity that would be used when committing",
        action="store_true",
        default=False,
    )
    parser.add_argument("--debug",
                        help="Describe all considerd changes.",
                        action="store_true")

    args = parser.parse_args()

    wt, subpath = WorkingTree.open_containing(args.directory)
    if args.identity:
        logging.info('%s', get_committer(wt))
        return 0

    try:
        check_clean_tree(wt, wt.basis_tree(), subpath)
    except WorkspaceDirty:
        logging.info("%s: Please commit pending changes first.", wt.basedir)
        return 1

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO, format='%(message)s')

    update_changelog = args.update_changelog
    allow_reformatting = args.allow_reformatting
    try:
        cfg = Config.from_workingtree(wt, subpath)
    except FileNotFoundError:
        pass
    else:
        if update_changelog is None:
            update_changelog = cfg.update_changelog()
        if allow_reformatting is None:
            allow_reformatting = cfg.allow_reformatting()

    if allow_reformatting is None:
        allow_reformatting = False

    try:
        with WatchEditor() as updater:
            fix_watch_issues(updater)
    except FileNotFoundError:
        # TODO(jelmer): Reuse logic from ../fixers/debian-watch-file-is-missing.py
        pass

    if os.environ.get("SVP_API") == "1":
        with open(os.environ["SVP_RESULT"], "w") as f:
            json.dump({"description": "Update watch file.", "context": {}}, f)

    return 0
Beispiel #5
0
if __name__=='__main__':
    import breezy
    breezy.initialize()
    import breezy.plugin
    breezy.plugin.set_plugins_path()
    breezy.plugin.load_plugins()

import os, tempfile
from breezy.plugins.qbrz.lib.tests import QTestCase
from breezy.plugins.qbrz.lib.tests.mock import MockFunction
from breezy.plugins.qbrz.lib import diff
from breezy.workingtree import WorkingTree
from contextlib import contextmanager


class TestCommandString(QTestCase):
    def setUp(self):
        QTestCase.setUp(self)
        self.tree = self.make_branch_and_tree('tree')
        self.build_tree_contents([('tree/a', b"content")])
        self.tree.add(["a"])
        self.tree.commit(message='1')
        self.differ = diff._ExtDiffer("test", self.tree.basis_tree(), self.tree)
        self.addCleanup(self.differ.finish)

    def test_no_arguments(self):
        self.differ.set_command_string("test")
        self.assertEqual(self.differ.command_template, ["test", "@old_path", "@new_path"])

    def test_has_arguments(self):
        self.differ.set_command_string("test --old @old_path --new @new_path")
Beispiel #6
0
def main():  # noqa: C901
    import argparse
    import breezy  # noqa: E402

    breezy.initialize()
    import breezy.git  # noqa: E402
    import breezy.bzr  # noqa: E402

    parser = argparse.ArgumentParser(prog="deb-transition-apply")
    parser.add_argument(
        "--directory",
        metavar="DIRECTORY",
        help="directory to run in",
        type=str,
        default=".",
    )
    parser.add_argument(
        "--no-update-changelog",
        action="store_false",
        default=None,
        dest="update_changelog",
        help="do not update the changelog",
    )
    parser.add_argument(
        "--update-changelog",
        action="store_true",
        dest="update_changelog",
        help="force updating of the changelog",
        default=None,
    )
    parser.add_argument(
        "--allow-reformatting",
        default=None,
        action="store_true",
        help=argparse.SUPPRESS,
    )
    parser.add_argument("--version",
                        action="version",
                        version="%(prog)s " + version_string)
    parser.add_argument(
        "--identity",
        help="Print user identity that would be used when committing",
        action="store_true",
        default=False,
    )
    parser.add_argument("--debug",
                        help="Describe all considered changes.",
                        action="store_true")
    parser.add_argument("benfile",
                        help="Benfile to read transition from.",
                        type=str)

    args = parser.parse_args()

    with open(args.benfile, 'r') as f:
        ben = parse_ben(f)

    wt, subpath = WorkingTree.open_containing(args.directory)
    if args.identity:
        logging.info('%s', get_committer(wt))
        return 0

    try:
        check_clean_tree(wt, wt.basis_tree(), subpath)
    except WorkspaceDirty:
        logging.info("%s: Please commit pending changes first.", wt.basedir)
        return 1

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO, format='%(message)s')

    update_changelog = args.update_changelog
    allow_reformatting = args.allow_reformatting

    try:
        cfg = Config.from_workingtree(wt, subpath)
    except FileNotFoundError:
        pass
    else:
        if update_changelog is None:
            update_changelog = cfg.update_changelog()
        if allow_reformatting is None:
            allow_reformatting = cfg.allow_reformatting()

    if allow_reformatting is None:
        allow_reformatting = False

    if control_files_in_root(wt, subpath):
        debian_path = subpath
    else:
        debian_path = os.path.join(subpath, 'debian')

    try:
        result = apply_transition(wt,
                                  debian_path,
                                  ben,
                                  update_changelog=args.update_changelog,
                                  allow_reformatting=allow_reformatting)
    except PackageNotAffected:
        report_okay("nothing-to-do", "Package not affected by transition")
        return 0
    except PackageAlreadyGood:
        report_okay("nothing-to-do", "Transition already applied to package")
        return 0
    except PackageNotBad:
        report_okay("nothing-to-do", "Package not bad")
        return 0
    except FormattingUnpreservable as e:
        report_fatal(
            "formatting-unpreservable",
            "unable to preserve formatting while editing %s" % e.path,
        )
        return 1
    except GeneratedFile as e:
        report_fatal("generated-file", "unable to edit generated file: %r" % e)
        return 1
    except NotDebianPackage:
        report_fatal('not-debian-package', 'Not a Debian package.')
        return 1
    except ChangeConflict as e:
        report_fatal('change-conflict',
                     'Generated file changes conflict: %s' % e)
        return 1

    if not result:
        report_okay("nothing-to-do", "no changes from transition")
        return 0

    changelog_path = os.path.join(debian_path, "changelog")

    if update_changelog is None:
        from .detect_gbp_dch import guess_update_changelog
        from debian.changelog import Changelog

        with wt.get_file(changelog_path) as f:
            cl = Changelog(f, max_blocks=1)

        dch_guess = guess_update_changelog(wt, debian_path, cl)
        if dch_guess:
            update_changelog = dch_guess[0]
            _note_changelog_policy(update_changelog, dch_guess[1])
        else:
            # Assume we should update changelog
            update_changelog = True

    if update_changelog:
        summary = 'Apply transition %s.' % ben['title']
        if result.bugno:
            summary += ' Closes: #%d' % result.bugno
        add_changelog_entry(wt, changelog_path, [summary])

    if os.environ.get("SVP_API") == "1":
        with open(os.environ["SVP_RESULT"], "w") as f:
            json.dump(
                {
                    "description": "Apply transition.",
                    "value": result.value(),
                    "context": ben
                }, f)

    logging.info("Applied transition %s", ben['title'])
    return 0
Beispiel #7
0
def main():
    import argparse
    parser = argparse.ArgumentParser()

    parser.add_argument(
        "--identity",
        help="Print user identity that would be used when committing",
        action="store_true",
        default=False,
    )
    parser.add_argument("--debug",
                        help="Describe all considerd changes.",
                        action="store_true")
    parser.add_argument('--create',
                        help='Create the repository',
                        action='store_true')
    parser.add_argument('--force', action='store_true')
    parser.add_argument('--push', help='Push branch', action='store_true')

    parser.add_argument(
        "--directory",
        metavar="DIRECTORY",
        help="directory to run in",
        type=str,
        default=".",
    )
    parser.add_argument('url', type=str, help='URL to publish to.', nargs='?')

    args = parser.parse_args()

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)

    import breezy  # noqa: E402

    breezy.initialize()
    import breezy.git  # noqa: E402
    import breezy.bzr  # noqa: E402
    import breezy.plugins.gitlab

    wt, subpath = WorkingTree.open_containing(args.directory)
    if args.identity:
        print(get_committer(wt))
        return 0

    try:
        repo_url = update_offical_vcs(wt,
                                      subpath,
                                      repo_url=args.url,
                                      force=args.force,
                                      create=args.create)
    except WorkspaceDirty:
        logging.info("%s: Please commit pending changes first.", wt.basedir)
        return 1
    except NoVcsLocation:
        parser.print_usage()
        return 1
    except VcsAlreadySpecified as e:
        logging.fatal('Package already in %s at %s', e.args[0], e.args[1])
        return 1
    except AlreadyBranchError as e:
        logging.fatal('Repository already exists at %s', e.path)
        return 1

    controldir = ControlDir.open(repo_url)
    try:
        branch = controldir.create_branch()
    except AlreadyBranchError:
        branch = controldir.open_branch()
    wt.branch.push(branch)
def main(argv=None):  # noqa: C901
    import argparse
    from breezy.workingtree import WorkingTree

    import breezy  # noqa: E402

    breezy.initialize()
    import breezy.git  # noqa: E402
    import breezy.bzr  # noqa: E402

    from .config import Config

    parser = argparse.ArgumentParser(prog="multi-arch-fixer")
    parser.add_argument(
        "--directory",
        metavar="DIRECTORY",
        help="directory to run in",
        type=str,
        default=".",
    )
    parser.add_argument(
        "--disable-inotify", action="store_true", default=False, help=argparse.SUPPRESS
    )
    parser.add_argument(
        "--identity",
        help="Print user identity that would be used when committing",
        action="store_true",
        default=False,
    )
    # Hide the minimum-certainty option for the moment.
    parser.add_argument(
        "--minimum-certainty",
        type=str,
        choices=SUPPORTED_CERTAINTIES,
        default=None,
        help=argparse.SUPPRESS,
    )
    parser.add_argument(
        "--no-update-changelog",
        action="store_false",
        default=None,
        dest="update_changelog",
        help="do not update the changelog",
    )
    parser.add_argument(
        "--update-changelog",
        action="store_true",
        dest="update_changelog",
        help="force updating of the changelog",
        default=None,
    )
    parser.add_argument(
        "--version", action="version", version="%(prog)s " + version_string
    )
    parser.add_argument(
        "--allow-reformatting",
        default=None,
        action="store_true",
        help=argparse.SUPPRESS,
    )

    args = parser.parse_args(argv)

    logging.basicConfig(level=logging.INFO, format='%(message)s')

    minimum_certainty = args.minimum_certainty
    wt, subpath = WorkingTree.open_containing(args.directory)
    if args.identity:
        logging.info('%s', get_committer(wt))
        return 0

    update_changelog = args.update_changelog
    allow_reformatting = args.allow_reformatting
    try:
        cfg = Config.from_workingtree(wt, 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()

    use_inotify = ((False if args.disable_inotify else None),)
    try:
        check_clean_tree(wt, wt.basis_tree(), subpath)
    except WorkspaceDirty:
        logging.info("%s: Please commit pending changes first.", wt.basedir)
        return 1

    dirty_tracker = get_dirty_tracker(wt, subpath, use_inotify)
    if dirty_tracker:
        dirty_tracker.mark_clean()

    with cache_download_multiarch_hints() as f:
        hints = multiarch_hints_by_binary(parse_multiarch_hints(f))

    if control_files_in_root(wt, subpath):
        report_fatal(
            "control-files-in-root",
            "control files live in root rather than debian/ " "(LarstIQ mode)",
        )
        return 1

    if is_debcargo_package(wt, subpath):
        report_okay("nothing-to-do", "Package uses debcargo")
        return 0
    if not control_file_present(wt, subpath):
        report_fatal("missing-control-file", "Unable to find debian/control")
        return 1

    try:
        result, summary = run_lintian_fixer(
            wt,
            MultiArchHintFixer(hints),
            update_changelog=update_changelog,
            minimum_certainty=minimum_certainty,
            dirty_tracker=dirty_tracker,
            subpath=subpath,
            allow_reformatting=allow_reformatting,
            net_access=True,
            changes_by="apply-multiarch-hints",
        )
    except NoChanges:
        report_okay("nothing-to-do", "no hints to apply")
        return 0
    except FormattingUnpreservable as e:
        report_fatal(
            "formatting-unpreservable",
            "unable to preserve formatting while editing %s" % e.path,
        )
        return 1
    except GeneratedFile as e:
        report_fatal(
            "generated-file", "unable to edit generated file: %r" % e)
        return 1
    except NotDebianPackage:
        logging.info("%s: Not a debian package.", wt.basedir)
        return 1
    else:
        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))
        if os.environ.get('SVP_API') == '1':
            with open(os.environ['SVP_RESULT'], 'w') as f:
                json.dump({
                    'description': "Applied multi-arch hints.",
                    'value': calculate_value(hint_names),
                    'commit-message': 'Apply multi-arch hints',
                    'context': {
                        'applied-hints': applied_hints,
                    }}, f)
Beispiel #9
0
def main():  # noqa: C901
    import argparse
    import breezy  # noqa: E402

    breezy.initialize()
    import breezy.git  # noqa: E402
    import breezy.bzr  # noqa: E402

    from breezy.workspace import (
        check_clean_tree,
        WorkspaceDirty,
    )
    from . import (
        version_string, )
    from .config import Config

    parser = argparse.ArgumentParser(prog="deb-scrub-obsolete")
    parser.add_argument(
        "--directory",
        metavar="DIRECTORY",
        help="directory to run in",
        type=str,
        default=".",
    )
    parser.add_argument(
        "--upgrade-release",
        metavar="UPGRADE-RELEASE",
        help="Release to allow upgrading from.",
        default="oldstable",
    )
    parser.add_argument('--compat-release',
                        metavar='COMPAT-RELEASE',
                        help="Release to allow building on.",
                        default=None)
    parser.add_argument(
        "--no-update-changelog",
        action="store_false",
        default=None,
        dest="update_changelog",
        help="do not update the changelog",
    )
    parser.add_argument(
        "--update-changelog",
        action="store_true",
        dest="update_changelog",
        help="force updating of the changelog",
        default=None,
    )
    parser.add_argument(
        "--allow-reformatting",
        default=None,
        action="store_true",
        help=argparse.SUPPRESS,
    )
    parser.add_argument("--version",
                        action="version",
                        version="%(prog)s " + version_string)
    parser.add_argument(
        "--identity",
        help="Print user identity that would be used when committing",
        action="store_true",
        default=False,
    )
    parser.add_argument("--debug",
                        help="Describe all considered changes.",
                        action="store_true")

    args = parser.parse_args()

    wt, subpath = WorkingTree.open_containing(args.directory)
    if args.identity:
        logging.info('%s', get_committer(wt))
        return 0

    try:
        check_clean_tree(wt, wt.basis_tree(), subpath)
    except WorkspaceDirty:
        logging.info("%s: Please commit pending changes first.", wt.basedir)
        return 1

    import distro_info
    debian_info = distro_info.DebianDistroInfo()
    upgrade_release = debian_info.codename(args.upgrade_release)

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO, format='%(message)s')

    update_changelog = args.update_changelog
    allow_reformatting = args.allow_reformatting
    if args.compat_release:
        compat_release = debian_info.codename(args.compat_release)
    else:
        compat_release = None
    try:
        cfg = Config.from_workingtree(wt, subpath)
    except FileNotFoundError:
        pass
    else:
        if update_changelog is None:
            update_changelog = cfg.update_changelog()
        if allow_reformatting is None:
            allow_reformatting = cfg.allow_reformatting()
        if compat_release is None:
            compat_release = cfg.compat_release()

    if compat_release is None:
        compat_release = debian_info.codename('oldstable')

    if upgrade_release != compat_release:
        logging.info(
            "Removing run time constraints unnecessary since %s"
            " and build time constraints unnecessary since %s",
            upgrade_release, compat_release)
    else:
        logging.info(
            "Removing run time and build time constraints unnecessary "
            "since %s", compat_release)

    if allow_reformatting is None:
        allow_reformatting = False

    if is_debcargo_package(wt, subpath):
        report_fatal("nothing-to-do", "Package uses debcargo")
        return 1
    elif not control_file_present(wt, subpath):
        report_fatal("missing-control-file", "Unable to find debian/control")
        return 1

    try:
        result = scrub_obsolete(wt,
                                subpath,
                                compat_release,
                                upgrade_release,
                                update_changelog=args.update_changelog,
                                allow_reformatting=allow_reformatting)
    except FormattingUnpreservable as e:
        report_fatal(
            "formatting-unpreservable",
            "unable to preserve formatting while editing %s" % e.path,
        )
        return 1
    except GeneratedFile as e:
        report_fatal("generated-file", "unable to edit generated file: %r" % e)
        return 1
    except NotDebianPackage:
        report_fatal('not-debian-package', 'Not a Debian package.')
        return 1
    except ChangeConflict as e:
        report_fatal('change-conflict',
                     'Generated file changes conflict: %s' % e)
        return 1
    except UddTimeout:
        report_fatal('udd-timeout', 'Timeout communicating with UDD')
        return 1

    if not result:
        report_okay("nothing-to-do", "no obsolete constraints")
        return 0

    debian_context = {}
    if result.changelog_behaviour:
        debian_context['changelog'] = result.changelog_behaviour.json()

    if os.environ.get("SVP_API") == "1":
        with open(os.environ["SVP_RESULT"], "w") as f:
            json.dump(
                {
                    "description": "Remove constraints unnecessary since %s." %
                    upgrade_release,
                    "value": result.value(),
                    "debian": debian_context,
                    "context": {
                        "specific_files": result.specific_files,
                        "maintscript_removed": result.maintscript_removed,
                        "control_removed": result.control_removed,
                    }
                }, f)

    logging.info("Scrub obsolete settings.")
    for release, lines in result.itemized().items():
        for line in lines:
            logging.info("* %s", line)

    return 0