def load(self): self.wt = wt = WorkingTree.open_containing(self.wt_dir)[0] self.set_title([gettext("Conflicts"), wt.basedir]) conflicts = self.wt.conflicts() items = [] for conflict in conflicts: item = QtWidgets.QTreeWidgetItem() item.setText(0, conflict.path) item.setText(1, gettext(conflict.typestring)) item.setData( 0, QtCore.Qt.UserRole, conflict.file_id or '' ) # file_id is None for non-versioned items, so we force it to be empty string to avoid Qt error item.setData(1, QtCore.Qt.UserRole, conflict.typestring) items.append(item) if len(items) == 0 and self.conflicts_list.topLevelItemCount() > 0: self.allResolved.emit(True) self.conflicts_list.clear() self.conflicts_list.addTopLevelItems(items)
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
def run_mutator(changer_cls, argv=None): import json import argparse import os from breezy.workingtree import WorkingTree parser = argparse.ArgumentParser() changer_cls.setup_parser(parser) args = parser.parse_args(argv) wt, subpath = WorkingTree.open_containing(".") changer = changer_cls.from_args(args) try: update_changelog_str = (os.environ["UPDATE_CHANGELOG"], ) except KeyError: update_changelog = None else: if update_changelog_str == "leave_changelog": update_changelog = False elif update_changelog_str == "update_changelog": update_changelog = True else: # TODO(jelmer): Warn update_changelog = None try: base_metadata_path = os.environ["BASE_METADATA"] except KeyError: existing_proposal = None else: with open(base_metadata_path, "r") as f: base_metadata = json.load(f) class PreviousProposal(MergeProposal): def __init__(self, metadata): self.metadata = metadata def get_description(self): return self.metadata.get("description") def get_commit_message(self): return self.metadata.get("commit-message") existing_proposal = PreviousProposal(base_metadata["merge-proposal"]) mutator_metadata = {} try: result = changer.make_changes( wt, subpath, update_changelog=update_changelog, committer=os.environ.get("COMMITTER"), base_proposal=existing_proposal, reporter=DummyChangerReporter(), ) except ChangerError as e: result_json = { "result-code": e.category, "description": e.summary, "details": e.details, } else: result_json = { "result-code": None, "description": result.description, "suggested-branch-name": changer.suggest_branch_name(), "tags": result.tags, "branches": result.branches, "value": result.value, "mutator": mutator_metadata, "merge-proposal": { "sufficient": changer.sufficient_for_proposal, "commit-message": result.proposed_commit_message, "title": result.title, "labels": result.labels, "description-plain": changer.get_proposal_description(result.mutator, "plain", existing_proposal), "description-markdown": changer.get_proposal_description(result.mutator, "markdown", existing_proposal), }, } json.dump(result_json, sys.stdout, indent=4) return 0
def main(argv: List[str]) -> Optional[int]: # noqa: C901 import argparse parser = argparse.ArgumentParser() parser.add_argument( "--command", help="Path to script to run.", type=str) parser.add_argument( "--diff", action="store_true", help="Show diff of generated changes." ) 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( "--commit-pending", help="Commit pending changes after script.", choices=["yes", "no", "auto"], default=None, type=str, ) parser.add_argument( "--build-verify", help="Build package to verify it.", dest="build_verify", action="store_true", ) parser.add_argument( "--builder", default=DEFAULT_BUILDER, type=str, help="Build command to use when verifying build.", ) parser.add_argument( "--build-target-dir", type=str, help=( "Store built Debian files in specified directory " "(with --build-verify)" ), ) parser.add_argument( "--install", "-i", action="store_true", help="Install built package (implies --build-verify)") parser.add_argument( "--dump-context", action="store_true", help="Report context on success") parser.add_argument( "--recipe", type=str, help="Recipe to use.") args = parser.parse_args(argv) if args.recipe: from ..recipe import Recipe recipe = Recipe.from_path(args.recipe) else: recipe = None if args.commit_pending: commit_pending = {"auto": None, "yes": True, "no": False}[args.commit_pending] elif recipe: commit_pending = recipe.commit_pending else: commit_pending = None if args.command: command = args.command elif recipe and recipe.command: command = recipe.command else: logging.exception('No command or recipe specified.') return 1 local_tree, subpath = WorkingTree.open_containing('.') check_clean_tree(local_tree) try: try: result = script_runner( local_tree, script=command, commit_pending=commit_pending, subpath=subpath, update_changelog=args.update_changelog) except MissingChangelog as e: logging.error('No debian changelog file (%s) present', e.args[0]) return False except ScriptMadeNoChanges: logging.info('Script made no changes') return False if result.description: logging.info('Succeeded: %s', result.description) if args.build_verify or args.install: try: build(local_tree, subpath, builder=args.builder, result_dir=args.build_target_dir) except BuildFailedError: logging.error("%s: build failed", result.source) return False except MissingUpstreamTarball: logging.error("%s: unable to find upstream source", result.source) return False except Exception: reset_tree(local_tree, subpath) raise if args.install: install_built_package(local_tree, subpath, args.build_target_dir) if args.diff: from breezy.diff import show_diff_trees old_tree = local_tree.revision_tree(result.old_revision) new_tree = local_tree.revision_tree(result.new_revision) show_diff_trees( old_tree, new_tree, sys.stdout.buffer, old_label='old/', new_label='new/') if args.dump_context: json.dump(result.context, sys.stdout, indent=5) return 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
def pull(self): from breezy.workingtree import WorkingTree from breezy.plugins.qbrz.lib.pull import QBzrPullWindow tree = WorkingTree.open_containing(self.currentDirectory)[0] self.window = QBzrPullWindow(tree.branch, parent=self) self.window.show()
def commit(self): from breezy.workingtree import WorkingTree from breezy.plugins.qbrz.lib.commit import CommitWindow tree = WorkingTree.open_containing(self.currentDirectory)[0] self.window = CommitWindow(tree, [], parent=self) self.window.show()
def main(argv=None): # noqa: C901 parser = argparse.ArgumentParser(prog="lintian-brush") fixer_group = parser.add_argument_group("fixer selection") fixer_group.add_argument("fixers", metavar="FIXER", nargs="*", help="specific fixer to run") fixer_group.add_argument( "--fixers-dir", type=str, help="path to fixer scripts. [%(default)s]", default=find_fixers_dir(), ) fixer_group.add_argument( "--exclude", metavar="EXCLUDE", type=str, action="append", help="Exclude a fixer.", ) fixer_group.add_argument( "--modern", help=("Use features/compatibility levels that are not available in " "stable. (makes backporting harder)"), action="store_true", default=False, ) fixer_group.add_argument("--compat-release", type=str, help=argparse.SUPPRESS) # Hide the minimum-certainty option for the moment. fixer_group.add_argument( "--minimum-certainty", type=str, choices=SUPPORTED_CERTAINTIES, default=None, help=argparse.SUPPRESS, ) fixer_group.add_argument("--opinionated", action="store_true", help=argparse.SUPPRESS) fixer_group.add_argument( "--diligent", action="count", default=0, dest="diligence", help=argparse.SUPPRESS, ) fixer_group.add_argument("--uncertain", action="store_true", help="Include changes with lower certainty.") fixer_group.add_argument("--yolo", action="store_true", help=argparse.SUPPRESS) fixer_group.add_argument("--force-subprocess", action="store_true", default=False, help=argparse.SUPPRESS) package_group = parser.add_argument_group("package preferences") package_group.add_argument( "--allow-reformatting", default=None, action="store_true", help="Allow file reformatting and stripping of comments.") package_group.add_argument( "--no-update-changelog", action="store_false", default=None, dest="update_changelog", help="do not update the changelog", ) package_group.add_argument( "--update-changelog", action="store_true", dest="update_changelog", help="force updating of the changelog", default=None, ) package_group.add_argument("--trust", action="store_true", help=argparse.SUPPRESS) output_group = parser.add_argument_group("output") output_group.add_argument("--verbose", help="be verbose", action="store_true", default=('SVP_API' in os.environ)) output_group.add_argument("--diff", help="Print resulting diff afterwards.", action="store_true") output_group.add_argument("--version", action="version", version="%(prog)s " + version_string) output_group.add_argument("--list-fixers", action="store_true", help="list available fixers") output_group.add_argument( "--list-tags", action="store_true", help="list lintian tags for which fixers are available", ) output_group.add_argument( "--dry-run", help=("Do not make any changes to the current repository. " "Note: currently creates a temporary clone of the repository."), action="store_true", ) output_group.add_argument( "--identity", help="Print user identity that would be used when committing", action="store_true", default=False, ) parser.add_argument( "-d", "--directory", metavar="DIRECTORY", help="directory to run in", type=str, default=".", ) parser.add_argument( "--disable-net-access", help="Do not probe external services.", action="store_true", default=False, ) parser.add_argument("--disable-inotify", action="store_true", default=False, help=argparse.SUPPRESS) args = parser.parse_args(argv) logging.basicConfig(level=logging.INFO, format='%(message)s') if args.list_fixers and args.list_tags: parser.print_usage() return 1 fixers = available_lintian_fixers(args.fixers_dir, force_subprocess=args.force_subprocess) if args.list_fixers: for script in sorted([fixer.name for fixer in fixers]): print(script) elif args.list_tags: tags = set() for fixer in fixers: tags.update(fixer.lintian_tags) for tag in sorted(tags): print(tag) else: try: if args.dry_run: branch, subpath = Branch.open_containing(args.directory) td = tempfile.mkdtemp() atexit.register(shutil.rmtree, td) # TODO(jelmer): Make a slimmer copy to_dir = branch.controldir.sprout( td, None, create_tree_if_local=True, source_branch=branch, stacked=branch._format.supports_stacking(), ) wt = to_dir.open_workingtree() else: wt, subpath = WorkingTree.open_containing(args.directory) except NotBranchError: logging.error( "No version control directory found (e.g. a .git directory).") return 1 except DependencyNotPresent as e: logging.error( "Unable to open tree at %s: missing package %s", args.directory, e.library, ) return 1 if args.identity: print("Committer identity: %s" % get_committer(wt)) print("Changelog identity: %s <%s>" % get_maintainer()) return 0 since_revid = wt.last_revision() if args.fixers: try: fixers = select_fixers(fixers, args.fixers, args.exclude) except KeyError as e: logging.error("Unknown fixer specified: %s", e.args[0]) return 1 debian_info = distro_info.DebianDistroInfo() if args.modern: if args.compat_release: logging.error( "--compat-release and --modern are incompatible.") return 1 compat_release = debian_info.devel() else: compat_release = args.compat_release minimum_certainty = args.minimum_certainty allow_reformatting = args.allow_reformatting update_changelog = args.update_changelog try: cfg = Config.from_workingtree(wt, subpath) except FileNotFoundError: pass else: if minimum_certainty is None: minimum_certainty = cfg.minimum_certainty() if compat_release is None: compat_release = cfg.compat_release() if allow_reformatting is None: allow_reformatting = cfg.allow_reformatting() if update_changelog is None: update_changelog = cfg.update_changelog() if minimum_certainty is None: if args.uncertain or args.yolo: minimum_certainty = "possible" else: minimum_certainty = DEFAULT_MINIMUM_CERTAINTY if compat_release is None: compat_release = debian_info.stable() if allow_reformatting is None: allow_reformatting = False with wt.lock_write(): if control_files_in_root(wt, subpath): report_fatal( "control-files-in-root", "control files live in root rather than debian/ " "(LarstIQ mode)", ) try: overall_result = run_lintian_fixers( wt, fixers, update_changelog=update_changelog, compat_release=compat_release, verbose=args.verbose, minimum_certainty=minimum_certainty, trust_package=args.trust, allow_reformatting=allow_reformatting, use_inotify=(False if args.disable_inotify else None), subpath=subpath, net_access=not args.disable_net_access, opinionated=args.opinionated, diligence=args.diligence, ) except NotDebianPackage: report_fatal("not-debian-package", "Not a Debian package") return 1 except WorkspaceDirty: logging.error("%s: Please commit pending changes first.", wt.basedir) if args.verbose: from breezy.status import show_tree_status show_tree_status(wt) return 1 except ChangelogCreateError as e: report_fatal("changelog-create-error", "Error creating changelog entry: %s" % e) return 1 except DescriptionMissing as e: report_fatal( "fixer-description-missing", "Fixer %s made changes but did not provide description." % e.fixer) return 1 if overall_result.overridden_lintian_issues: if len(overall_result.overridden_lintian_issues) == 1: logging.info("%d change skipped because of lintian overrides.", len(overall_result.overridden_lintian_issues)) else: logging.info( "%d changes skipped because of lintian overrides.", len(overall_result.overridden_lintian_issues)) if overall_result.success: all_tags = set() for result, summary in overall_result.success: all_tags.update(result.fixed_lintian_tags) if all_tags: logging.info("Lintian tags fixed: %r", all_tags) else: logging.info("Some changes were made, " "but there are no affected lintian tags.") min_certainty = overall_result.minimum_success_certainty() if min_certainty != "certain": logging.info( "Some changes were made with lower certainty (%s); " "please double check the changes.", min_certainty, ) else: report_fatal("nothing-to-do", "No changes made.") return 0 if overall_result.failed_fixers and not args.verbose: logging.info( "Some fixer scripts failed to run: %r. " "Run with --verbose for details.", set(overall_result.failed_fixers.keys()), ) if overall_result.formatting_unpreservable and not args.verbose: logging.info( "Some fixer scripts were unable to preserve formatting: %r. " "Run with --allow-reformatting to reformat %r.", set(overall_result.formatting_unpreservable), set(overall_result.formatting_unpreservable.values()), ) if args.diff: from breezy.diff import show_diff_trees show_diff_trees(wt.branch.repository.revision_tree(since_revid), wt, sys.stdout.buffer) if os.environ.get('SVP_API') == '1': applied = [] if 'SVP_RESUME' in os.environ: with open(os.environ['SVP_RESUME'], 'r') as f: base = json.load(f) applied.extend(base['applied']) all_fixed_lintian_tags = set() 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, }) all_fixed_lintian_tags.update(result.fixed_lintian_tags) failed = { name: str(e) for (name, e) in overall_result.failed_fixers.items() } debian_context = {} if overall_result.changelog_behaviour: debian_context[ 'changelog'] = overall_result.changelog_behaviour.json() with open(os.environ['SVP_RESULT'], 'w') as f: json.dump( { 'value': calculate_value(all_fixed_lintian_tags), 'debian': debian_context, 'context': { 'applied': applied, 'failed': failed, "versions": { "lintian-brush": lintian_brush_version_string, "breezy": breezy.version_string, } } }, f)
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: List[str]) -> Optional[int]: # noqa: C901 import argparse parser = argparse.ArgumentParser() parser.add_argument("command", help="Path to script to run.", type=str, nargs='?') parser.add_argument("--diff", action="store_true", help="Show diff of generated changes.") parser.add_argument( "--commit-pending", help="Commit pending changes after script.", choices=["yes", "no", "auto"], default=None, type=str, ) parser.add_argument("--verify-command", type=str, help="Command to run to verify changes.") parser.add_argument("--recipe", type=str, help="Recipe to use.") args = parser.parse_args(argv) if args.recipe: from .recipe import Recipe recipe = Recipe.from_path(args.recipe) else: recipe = None if args.commit_pending: commit_pending = { "auto": None, "yes": True, "no": False }[args.commit_pending] elif recipe: commit_pending = recipe.commit_pending else: commit_pending = None if args.command: command = args.command elif recipe.command: command = recipe.command else: logging.exception('No command specified.') return 1 local_tree, subpath = WorkingTree.open_containing('.') check_clean_tree(local_tree) try: result = script_runner(local_tree, script=command, commit_pending=commit_pending, subpath=subpath) if result.description: logging.info('Succeeded: %s', result.description) if args.verify_command: try: subprocess.check_call(args.verify_command, shell=True, cwd=local_tree.abspath(subpath)) except subprocess.CalledProcessError: logging.exception("Verify command failed.") return 1 except Exception: reset_tree(local_tree, subpath) raise if args.diff: from breezy.diff import show_diff_trees old_tree = local_tree.revision_tree(result.old_revision) new_tree = local_tree.revision_tree(result.new_revision) show_diff_trees(old_tree, new_tree, sys.stdout.buffer, old_label='old/', new_label='new/') return 0
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)
) if mixed == 0 and changelog_only > 0 and other_only > 0: # changelog is *always* updated in a separate commit. return ChangelogBehaviour( False, "Assuming changelog does not need to be updated, since " "changelog entries are always updated in separate commits.", ) # Is this a reasonable threshold? if changelog_only > mixed and other_only > mixed: return ChangelogBehaviour( False, "Assuming changelog does not need to be updated, since " "changelog entries are usually updated in separate commits.", ) return None if __name__ == "__main__": import argparse parser = argparse.ArgumentParser() args = parser.parse_args() wt, subpath = WorkingTree.open_containing(".") from . import control_files_in_root if control_files_in_root(wt, subpath): debian_path = subpath else: debian_path = os.path.join(subpath, "debian") print(guess_update_changelog(wt, debian_path))
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
description = "Upgrade to newer source format %s." % format else: from lintian_brush.patches import ( tree_non_patches_changes, find_patches_directory, ) from breezy import errors from breezy.workingtree import WorkingTree patches_directory = find_patches_directory('.') if patches_directory not in ('debian/patches', None): # Non-standard patches directory. warn('Tree has non-standard patches directory %s.' % (patches_directory)) else: try: tree, path = WorkingTree.open_containing('.') except errors.NotBranchError as e: if not meets_minimum_certainty('possible'): warn('unable to open vcs to check for delta: %s' % e) sys.exit(0) format = "3.0 (quilt)" description = "Upgrade to newer source format %s." % format else: delta = list(tree_non_patches_changes(tree, patches_directory)) if delta: warn('Tree has non-quilt changes against upstream.') if opinionated(): format = "3.0 (quilt)" description = ("Upgrade to newer source format %s." % format) try: