Debian Codegraph @

lib/commands.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2006 Lukáš Lalinský <[email protected]om>
5 # Copyright (C) 2008, 2009 Alexander Belchenko
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 import signal
22
23 from breezy import errors
24 from breezy.commands import Command
25 from breezy.option import Option
26 import breezy.builtins
27
28 import sys
29
30 from PyQt5 import QtCore, QtWidgets
31
32 from breezy import osutils, ui, gpg
33 from breezy.branch import Branch
34 from breezy.controldir import ControlDir
35 from breezy.workingtree import WorkingTree
36 from breezy.diff import get_trees_and_branches_to_diff_locked
37
38 from breezy.plugins.qbrz.lib import i18n
39 from breezy.plugins.qbrz.lib.add import AddWindow
40 from breezy.plugins.qbrz.lib.annotate import AnnotateWindow
41 from breezy.plugins.qbrz.lib.branch import QBzrBranchWindow
42 from breezy.plugins.qbrz.lib.browse import BrowseWindow
43 from breezy.plugins.qbrz.lib.cat import (
44 QBzrCatWindow,
45 QBzrViewWindow,
46 cat_to_native_app,
47 )
48 from breezy.plugins.qbrz.lib.commit import CommitWindow
49 from breezy.plugins.qbrz.lib.config import QBzrConfigWindow
50 from breezy.plugins.qbrz.lib.diffwindow import DiffWindow
51 from breezy.plugins.qbrz.lib.getupdates import UpdateBranchWindow, UpdateCheckoutWindow
52 from breezy.plugins.qbrz.lib.help import show_help
53 from breezy.plugins.qbrz.lib.log import LogWindow
54 from breezy.plugins.qbrz.lib.info import QBzrInfoWindow
55 from breezy.plugins.qbrz.lib.init import QBzrInitWindow
56 from breezy.plugins.qbrz.lib.main import QBzrMainWindow
57 from breezy.plugins.qbrz.lib.verify_signatures import QBzrVerifySignaturesWindow
58 from breezy.plugins.qbrz.lib.pull import (
59 QBzrPullWindow,
60 QBzrPushWindow,
61 QBzrMergeWindow,
62 )
63 from breezy.plugins.qbrz.lib.revert import RevertWindow
64 from breezy.plugins.qbrz.lib.tag import TagWindow
65 from breezy.plugins.qbrz.lib.tree_branch import TreeBranch
66 from breezy.plugins.qbrz.lib.uncommit import QBzrUncommitWindow
67 from breezy.plugins.qbrz.lib.update import QBzrUpdateWindow
68 from breezy.plugins.qbrz.lib.util import (
69 FilterOptions,
70 is_valid_encoding,
71 open_tree,
72 )
73 from breezy.plugins.qbrz.lib.uifactory import QUIFactory
74 from breezy.plugins.qbrz.lib.send import SendWindow
75 from breezy.plugins.qbrz.lib.shelvewindow import ShelveWindow
76
77
78 from breezy.plugins.qbrz.lib.diff_arg import DiffArgProvider
79
80 CUR_DIR = '.'
81
82
83 class InvalidEncodingOption(errors.BzrError):
84
85 _fmt = 'Invalid encoding: %(encoding)s\nValid encodings are:\n%(valid)s'
86
87 def __init__(self, encoding):
88 errors.BzrError.__init__(self)
89 self.encoding = encoding
90 import encodings
91 self.valid = ', '.join(sorted(list(set(encodings.aliases.aliases.values())))).replace('_','-')
92
93
94 def check_encoding(encoding):
95 if is_valid_encoding(encoding):
96 return encoding
97 raise InvalidEncodingOption(encoding)
98
99
100 class PyQt4NotInstalled(errors.BzrError):
101
102 _fmt = 'QBrz requires at least PyQt 4.4 and Qt 4.4 to run. Please check your install'
103
104
105 # TODO: test this with qt5
106 def report_missing_pyqt(unbound):
107 """Decorator for q-commands run method to catch ImportError PyQt4
108 and show explanation to user instead of scary traceback.
109 See bugs: #240123, #163728
110 """
111 def run(self, *args, **kwargs):
112 try:
113 return unbound(self, *args, **kwargs)
114 except ImportError as e:
115 if str(e).endswith('PyQt4'):
116 raise PyQt4NotInstalled
117 raise
118 return run
119
120
121 def install_gettext(unbound):
122 """Decorator for q-commands run method to enable gettext translations."""
123 def run(self, *args, **kwargs):
124 i18n.install()
125 try:
126 return unbound(self, *args, **kwargs)
127 finally:
128 i18n.uninstall()
129 return run
130
131
132 class QBzrCommand(Command):
133 """Base class for all q-commands.
134
135 NOTES:
136 1) q-command should define method '_qbrz_run' instead of 'run' (as in
137 breezy).
138 2) The _qbrz_run method should return 0 for successfull exit
139 and 1 if operation was cancelled by user.
140 3) The _qbrz_run method can return None, in this case return code will be
141 asked from self.main_window instance (if there is one).
142 self.main_window should be instance of QBzrWindow or QBzrDialog
143 with attribute "return_code" set to 0 or 1.
144 """
145
146 @install_gettext
147 @report_missing_pyqt
148 def run(self, *args, **kwargs):
149 # We must create the QApplication before we install the QUIFactory.
150 # This is because once the factory is installed, it is possible that
151 # opening a branch, etc will go to the ui_factory to request a
152 # password, and the app must exist before the dialog can be created.
153 self._application = QtWidgets.QApplication(sys.argv)
154 std_ui_factory = ui.ui_factory
155 try:
156 ui.ui_factory = QUIFactory()
157
158 # Handle interupt signal correctly.
159 signal.signal(signal.SIGINT, signal.SIG_DFL)
160
161 # Set up global exception handling.
162 from breezy.plugins.qbrz.lib.trace import excepthook
163 sys.excepthook = excepthook
164
165 try:
166 try:
167 ret_code = self._qbrz_run(*args, **kwargs)
168 finally:
169 # ensure we flush clipboard data (see bug #503401)
170 clipboard = self._application.clipboard()
171 clipEvent = QtCore.QEvent(QtCore.QEvent.Clipboard)
172 self._application.sendEvent(clipboard, clipEvent)
173 if ret_code is None:
174 main_window = getattr(self, "main_window", None)
175 if main_window is not None:
176 # 0.20 special: We check hasattr() first to work around
177 # <http://bugs.python.org/issue4230>
178 if hasattr(main_window, "return_code"):
179 ret_code = main_window.return_code
180 return ret_code
181 except Exception:
182 ui_mode = kwargs.get("ui_mode", False)
183 from breezy.plugins.qbrz.lib.trace import report_exception
184 return report_exception(ui_mode=ui_mode)
185 finally:
186 ui.ui_factory = std_ui_factory
187
188
189 ui_mode_option = Option("ui-mode", help="Causes dialogs to wait after the operation is complete.")
190 execute_option = Option("execute", short_name='e', help="Causes dialogs to start the underlying action immediately without waiting for user input.")
191
192 # A special option so 'revision' can be passed as a simple string, when we do
193 # *not* want breezy's feature of parsing the revision string before passing it.
194 # This is used when we just want a plain string to pass to our dialog for it to
195 # display in the UI, and we will later pass it to bzr for parsing. If you want
196 # breezy to parse and pass a revisionspec object, just pass the string
197 # 'revision' as normal.
198 simple_revision_option = Option("revision", short_name='r', type=str, help='See "help revisionspec" for details.')
199
200
201 def brz_option(cmd_name, opt_name):
202 """Helper so we can 'borrow' options from brz itself without needing to
203 duplicate the help text etc. Pass the builtin bzr command name and an
204 option name.
205
206 eg:
207 takes_options = [brz_option("push", "create-prefix")]
208
209 would give a command the exact same '--create-prefix' option as bzr's
210 push command has, including help text, parsing, etc.
211 """
212 from breezy.commands import get_cmd_object
213 cmd = get_cmd_object(cmd_name, False)
214 return cmd.options()[opt_name]
215
216
217 class cmd_qannotate(QBzrCommand):
218 """Show the origin of each line in a file."""
219 takes_args = ['filename']
220 takes_options = ['revision',
221 Option('encoding', type=check_encoding, help='Encoding of files content (default: utf-8).'),
222 ui_mode_option, Option('no-graph', help="Shows the log with no graph."),
223 Option('line', short_name='L', type=int, argname='N', param_name='activate_line', help='Activate line N on start.'),
224 ]
225 aliases = ['qann', 'qblame']
226
227 def _load_branch(self, filename, revision):
228 """To assist in getting a UI up as soon as possible, the UI calls
229 back to this function to process the command-line args and convert
230 them into the branch and tree etc needed by the UI.
231 """
232 wt, branch, relpath = ControlDir.open_containing_tree_or_branch(filename)
233 if wt is not None:
234 wt.lock_read()
235 else:
236 branch.lock_read()
237 try:
238 if revision is None:
239 if wt is not None:
240 tree = wt
241 else:
242 tree = branch.repository.revision_tree(branch.last_revision())
243 elif len(revision) != 1:
244 raise errors.BzrCommandError('brz qannotate --revision takes exactly 1 argument')
245 else:
246 tree = branch.repository.revision_tree(revision_id = revision[0].in_history(branch).rev_id)
247
248 file_id = tree.path2id(relpath)
249 if file_id is None:
250 raise errors.NotVersionedError(filename)
251 [(path, entry)] = list(tree.iter_entries_by_dir(specific_files=[relpath]))
252 if entry.kind != 'file':
253 raise errors.BzrCommandError('brz qannotate only works for files (got %r)' % entry.kind)
254 # repo = branch.repository
255 # w = repo.weave_store.get_weave(file_id, repo.get_transaction())
256 # content = list(w.annotate_iter(entry.revision))
257 # revision_ids = set(o for o, t in content)
258 # revision_ids = [o for o in revision_ids if repo.has_revision(o)]
259 # revisions = branch.repository.get_revisions(revision_ids)
260 finally:
261 if wt is not None:
262 wt.unlock()
263 else:
264 branch.unlock()
265
266 return branch, tree, wt, relpath, file_id
267
268 def _qbrz_run(self, filename=None, revision=None, encoding=None, ui_mode=False, no_graph=False, activate_line=None):
269 win = AnnotateWindow(None, None, None, None, None,
270 encoding=encoding, ui_mode=ui_mode, loader=self._load_branch,
271 loader_args=(filename, revision), no_graph=no_graph, activate_line=activate_line)
272 win.show()
273 self._application.exec_()
274
275
276 class cmd_qadd(QBzrCommand):
277 """GUI for adding files or directories."""
278 takes_args = ['selected*']
279 takes_options = [ui_mode_option]
280
281 def _qbrz_run(self, selected_list=None, ui_mode=False):
282 tree, selected_list = WorkingTree.open_containing_paths(selected_list)
283 if selected_list == ['']:
284 selected_list = None
285 self.main_window = AddWindow(tree, selected_list, dialog=False, ui_mode=ui_mode)
286 self.main_window.show()
287 self._application.exec_()
288
289
290 class cmd_qrevert(QBzrCommand):
291 """Revert changes files."""
292 takes_args = ['selected*']
293 takes_options = [ui_mode_option, brz_option('revert', 'no-backup')]
294
295 def _qbrz_run(self, selected_list=None, ui_mode=False, no_backup=False):
296 tree, selected_list = WorkingTree.open_containing_paths(selected_list)
297 if selected_list == ['']:
298 selected_list = None
299 self.main_window = RevertWindow(tree, selected_list, dialog=False, ui_mode=ui_mode, backup=not no_backup)
300 self.main_window.show()
301 self._application.exec_()
302
303
304 class cmd_qconflicts(QBzrCommand):
305 """Show conflicts."""
306 takes_args = []
307 takes_options = []
308 aliases = ['qresolve']
309
310 def _qbrz_run(self):
311 from breezy.plugins.qbrz.lib.conflicts import ConflictsWindow
312 self.main_window = ConflictsWindow(CUR_DIR)
313 self.main_window.show()
314 self._application.exec_()
315
316
317 class cmd_qbrowse(QBzrCommand):
318 """Show inventory or working tree."""
319 takes_args = ['location?']
320 takes_options = ['revision']
321 aliases = ['qbw']
322
323 def _qbrz_run(self, revision=None, location=None):
324 Branch.open_containing(location or '.') # if there is no branch we want NotBranchError raised
325 if revision is None:
326 self.win = BrowseWindow(location=location)
327 else:
328 self.win = BrowseWindow(location=location, revision=revision[0])
329 self.win.show()
330 self._application.exec()
331
332
333 class cmd_qcommit(QBzrCommand):
334 """GUI for committing revisions."""
335 takes_args = ['selected*']
336 takes_options = [
337 brz_option('commit', 'message'),
338 brz_option('commit', 'local'),
339 brz_option('commit', 'file'),
340 Option('file-encoding', type=check_encoding, help='Encoding of commit message file content.'),
341 ui_mode_option,
342 ]
343 aliases = ['qci']
344
345 def _qbrz_run(self, selected_list=None, message=None, file=None, local=False, ui_mode=False, file_encoding=None):
346 if message is not None and file:
347 raise errors.BzrCommandError("please specify either --message or --file")
348 if file:
349 with open(file) as f:
350 message = f.read().decode(file_encoding or osutils.get_user_encoding())
351 tree, selected_list = WorkingTree.open_containing_paths(selected_list)
352 if selected_list == ['']:
353 selected_list = None
354 self.main_window = CommitWindow(tree, selected_list, dialog=False,
355 message=message, local=local, ui_mode=ui_mode)
356 self.main_window.show()
357 self._application.exec_()
358
359
360 class cmd_qdiff(QBzrCommand, DiffArgProvider):
361 """Show differences in working tree in a GUI window."""
362 takes_args = ['file*']
363 takes_options = [
364 'revision',
365 Option('complete', help='Show complete files.'),
366 Option('encoding', type=check_encoding, help='Encoding of files content (default: utf-8).'),
367 Option('added', short_name='A', help='Show diff for added files.'),
368 Option('deleted', short_name='K', help='Show diff for deleted files.'),
369 Option('modified', short_name='M', help='Show diff for modified files.'),
370 Option('renamed', short_name='R', help='Show diff for renamed files.'),
371 Option('ignore-whitespace', short_name='w', help="Ignore whitespace when finding differences"),
372 brz_option('diff', 'old'),
373 brz_option('diff', 'new'),
374 ]
375 if 'change' in Option.OPTIONS:
376 takes_options.append('change')
377 aliases = ['qdi']
378
379 def get_diff_window_args(self, processEvents, es):
380 args = {}
381 (args["old_tree"], args["new_tree"], args["old_branch"], args["new_branch"],
382 args["specific_files"], _) = get_trees_and_branches_to_diff_locked(self.file_list, self.revision, self.old, self.new, es)
383 args["ignore_whitespace"] = self.ignore_whitespace
384 return args
385
386 def get_ext_diff_args(self, processEvents):
387 args = []
388 if self.revision and len(self.revision) == 1:
389 args.append("-r%s" % (self.revision[0].user_spec,))
390 elif self.revision and len(self.revision) == 2:
391 args.append("-r%s..%s" % (self.revision[0].user_spec, self.revision[1].user_spec))
392 if self.new and not self.new == CUR_DIR:
393 args.append("--new=%s" % self.new)
394 if self.old and not self.old == CUR_DIR:
395 args.append("--old=%s" % self.old)
396 if self.file_list:
397 args.extend(self.file_list)
398 return None, args
399
400 def _qbrz_run(self, revision=None, file_list=None, complete=False,
401 encoding=None, ignore_whitespace=False, added=None, deleted=None, modified=None, renamed=None,
402 old=None, new=None, ui_mode=False):
403
404 if revision and len(revision) > 2:
405 raise errors.BzrCommandError('brz qdiff --revision takes exactly one or two revision specifiers')
406 # changes filter
407 filter_options = FilterOptions(added=added, deleted=deleted,
408 modified=modified, renamed=renamed)
409 if not (added or deleted or modified or renamed):
410 # if no filter option used then turn all on
411 filter_options.all_enable()
412
413 self.revision = revision
414 self.file_list = file_list
415 self.old = old
416 self.new = new
417 self.ignore_whitespace = ignore_whitespace
418
419 window = DiffWindow(self, complete=complete, encoding=encoding, filter_options=filter_options, ui_mode=ui_mode)
420 window.show()
421 self._application.exec_()
422
423
424 class cmd_qlog(QBzrCommand):
425 """Show log of a repository, branch, file, or directory in a Qt window.
426
427 By default show the log of the branch containing the working directory.
428
429 If multiple files are speciffied, they must be from the same branch.
430
431 :Examples:
432 Log the current branch::
433
434 bzr qlog
435
436 Log of files::
437
438 bzr qlog foo.c bar.c
439
440 Log from different branches::
441
442 bzr qlog ~/branch1 ~/branch2
443 """
444
445 takes_args = ['locations*']
446 takes_options = [
447 ui_mode_option,
448 Option('no-graph', help="Shows the log with no graph."),
449 Option('show-trees', help="Show working trees that have changes as nodes in the graph"),
450 ]
451
452 def _qbrz_run(self, locations_list=None, ui_mode=False, no_graph=False, show_trees=False):
453 window = LogWindow(locations_list, None, None, ui_mode=ui_mode, no_graph=no_graph, show_trees=show_trees)
454 window.show()
455 self._application.exec_()
456
457
458 class cmd_qconfig(QBzrCommand):
459 """Configure Bazaar and QBzr."""
460
461 takes_args = []
462 takes_options = []
463 aliases = ['qconfigure']
464
465 def _qbrz_run(self):
466 window = QBzrConfigWindow()
467 window.show()
468 self._application.exec_()
469
470
471 class cmd_qcat(QBzrCommand):
472 """View the contents of a file as of a given revision.
473
474 If no revision is nominated, the last revision is used.
475 """
476
477 takes_options = [
478 'revision',
479 Option('encoding', type=check_encoding, help='Encoding of files content (default: utf-8).'),
480 Option('native', help='Show file with native application.'),
481 ]
482 takes_args = ['filename']
483
484 def _qbrz_run(self, filename, revision=None, encoding=None, native=None):
485 if revision is not None and len(revision) != 1:
486 raise errors.BzrCommandError("brz qcat --revision takes exactly one revision specifier")
487
488 if native:
489 branch, relpath = Branch.open_containing(filename)
490 if revision is None:
491 tree = branch.basis_tree()
492 else:
493 revision_id = revision[0].in_branch(branch).rev_id
494 tree = branch.repository.revision_tree(revision_id)
495 result = cat_to_native_app(tree, relpath)
496 return int(not result)
497
498 window = QBzrCatWindow(filename = filename, revision = revision, encoding = encoding)
499 window.show()
500 self._application.exec_()
501
502
503 class cmd_qpull(QBzrCommand):
504 """Turn this branch into a mirror of another branch."""
505
506 takes_options = [
507 'remember', 'overwrite',
508 simple_revision_option,
509 brz_option('pull', 'directory'),
510 ui_mode_option,
511 ]
512 takes_args = ['location?']
513
514 def _qbrz_run(self, location=None, directory=None, remember=None, overwrite=None, revision=None, ui_mode=False):
515 if directory is None:
516 directory = CUR_DIR
517 try:
518 tree_to = WorkingTree.open_containing(directory)[0]
519 branch_to = tree_to.branch
520 except errors.NoWorkingTree:
521 tree_to = None
522 branch_to = Branch.open_containing(directory)[0]
523 self.main_window = QBzrPullWindow(branch_to, tree_to, location,
524 remember=remember, overwrite=overwrite, revision=revision, ui_mode=ui_mode)
525 self.main_window.show()
526 self._application.exec_()
527
528
529 class cmd_qmerge(QBzrCommand):
530 """Perform a three-way merge."""
531
532 takes_options = [ui_mode_option,
533 simple_revision_option,
534 brz_option('merge', 'directory'),
535 brz_option('merge', 'force'),
536 brz_option('merge', 'uncommitted'),
537 'remember']
538 takes_args = ['location?']
539
540 def _qbrz_run(self, location=None, directory=None, revision=None, remember=None, force=None, uncommitted=None, ui_mode=False):
541 if directory is None:
542 directory = CUR_DIR
543 try:
544 tree_to = WorkingTree.open_containing(directory)[0]
545 branch_to = tree_to.branch
546 except errors.NoWorkingTree:
547 tree_to = None
548 branch_to = Branch.open_containing(directory)[0]
549 self.main_window = QBzrMergeWindow(branch_to, tree_to, location,
550 revision=revision, remember=remember, force=force,
551 uncommitted=uncommitted, ui_mode=ui_mode)
552 self.main_window.show()
553 self._application.exec_()
554
555
556 class cmd_qpush(QBzrCommand):
557 """Update a mirror of this branch."""
558
559 takes_options = ['remember', 'overwrite',
560 brz_option("push", "create-prefix"),
561 brz_option("push", "use-existing-dir"),
562 brz_option("push", "directory"),
563 ui_mode_option]
564 takes_args = ['location?']
565
566 def _qbrz_run(self, location=None, directory=None, remember=None, overwrite=None,
567 create_prefix=None, use_existing_dir=None, ui_mode=False):
568
569 if directory is None:
570 directory = CUR_DIR
571
572 try:
573 tree_to = WorkingTree.open_containing(directory)[0]
574 branch_to = tree_to.branch
575 except errors.NoWorkingTree:
576 tree_to = None
577 branch_to = Branch.open_containing(directory)[0]
578 self.main_window = QBzrPushWindow(branch_to, tree_to, location=location, create_prefix=create_prefix,
579 use_existing_dir=use_existing_dir, remember=remember, overwrite=overwrite,
580 ui_mode=ui_mode)
581 self.main_window.show()
582 self._application.exec_()
583
584
585 class cmd_qbranch(QBzrCommand):
586 """Create a new copy of a branch."""
587
588 takes_options = [simple_revision_option, ui_mode_option]
589 try:
590 takes_options.append(brz_option("branch", "bind"))
591 except KeyError:
592 # older version of bzr that doesn't support the option
593 pass
594 takes_args = ['from_location?', 'to_location?']
595
596 def _qbrz_run(self, from_location=None, to_location=None, revision=None, bind=False, ui_mode=False):
597 self.main_window = QBzrBranchWindow(from_location, to_location, revision=revision, bind=bind, ui_mode=ui_mode)
598 self.main_window.show()
599 self._application.exec_()
600
601
602 class cmd_qinfo(QBzrCommand):
603 """Shows information about the current location."""
604
605 takes_options = []
606 takes_args = ['location?']
607
608 def _qbrz_run(self, location=CUR_DIR):
609 window = QBzrInfoWindow(location)
610 window.show()
611 self._application.exec_()
612
613
614 class cmd_qverify_signatures(QBzrCommand):
615 """Shows digital signature statuses for branch commits"""
616
617 takes_options = [
618 Option('acceptable-keys',
619 help='Comma separated list of GPG key patterns which are acceptable for verification.',
620 short_name='k', type=str,), 'revision',
621 ]
622 takes_args = ['location?']
623
624 def _qbrz_run(self, acceptable_keys=None, revision=None, location=CUR_DIR):
625 if gpg.GPGStrategy.verify_signatures_available():
626 window = QBzrVerifySignaturesWindow(acceptable_keys, revision, location)
627 window.show()
628 self._application.exec_()
629 else:
630 raise errors.DependencyNotPresent("python-gpgme", "python-gpgme not installed")
631
632
633 class cmd_qinit(QBzrCommand):
634 """Initializes a new branch or shared repository."""
635
636 takes_options = [ui_mode_option]
637 takes_args = ['location?']
638
639 def _qbrz_run(self, location=CUR_DIR, ui_mode=False):
640 self.main_window = QBzrInitWindow(location, ui_mode=ui_mode)
641 self.main_window.show()
642 self._application.exec_()
643
644
645 class cmd_merge(breezy.builtins.cmd_merge, DiffArgProvider):
646 __doc__ = breezy.builtins.cmd_merge.__doc__
647
648 takes_options = breezy.builtins.cmd_merge.takes_options + [
649 Option('qpreview', help='Instead of merging, show a diff of the merge in a GUI window.'),
650 Option('encoding', type=check_encoding, help='Encoding of files content, used with --qpreview (default: utf-8).'),
651 ]
652
653 def run(self, *args, **kw):
654 self.qpreview = ('qpreview' in kw)
655 if self.qpreview:
656 kw['preview'] = kw['qpreview']
657 del kw['qpreview']
658 self._encoding = kw.get('encoding')
659 if self._encoding:
660 del kw['encoding']
661 return breezy.builtins.cmd_merge.run(self, *args, **kw)
662
663 def get_diff_window_args(self, processEvents, es):
664 tree_merger = self.merger.make_merger()
665 self.tt = tree_merger.make_preview_transform()
666 result_tree = self.tt.get_preview_tree()
667 return {"old_tree": self.merger.this_tree, "new_tree": result_tree}
668
669 @install_gettext
670 @report_missing_pyqt
671 def _do_qpreview(self, merger):
672 # Set up global execption handeling.
673 from breezy.plugins.qbrz.lib.trace import excepthook
674 sys.excepthook = excepthook
675
676 self.merger = merger
677 try:
678 window = DiffWindow(self, encoding=self._encoding)
679 window.show()
680 self._application.exec_()
681 finally:
682 if self.tt:
683 self.tt.finalize()
684
685 def _do_preview(self, merger, *args, **kw):
686 if self.qpreview:
687 self._do_qpreview(merger)
688 else:
689 breezy.builtins.cmd_merge._do_preview(self, merger, *args, **kw)
690
691
692 class cmd_qmain(QBzrCommand):
693 """The QBzr main application.
694
695 Not finished -- DON'T USE
696 """
697 takes_options = []
698 takes_args = []
699 hidden = True
700
701 def _qbrz_run(self):
702 # Remove svn checkout support
703 try:
704 from breezy.plugins.svn.format import SvnWorkingTreeDirFormat
705 except ImportError:
706 pass
707 else:
708 from breezy.controldir import ControlDirFormat, format_registry
709 ControlDirFormat.unregister_control_format(SvnWorkingTreeDirFormat)
710 format_registry.remove('subversion-wc')
711 # Start QBzr
712 window = QBzrMainWindow()
713 window.setDirectory(osutils.realpath(CUR_DIR))
714 window.show()
715 self._application.exec_()
716
717
718 # [bialix 2010/02/04] body of cmd_qsubprocess has moved to subprocess.py
719 # to see annotation of cmd_qsubprocess before move use:
720 # bzr qannotate commands.py -r1117
721
722 class cmd_qsubprocess(Command):
723 """Run some bzr command as subprocess.
724 Used with most of subprocess-based dialogs of QBzr.
725
726 If CMD argument starts with @ characters then it used as name of file with
727 actual cmd string (in utf-8).
728
729 With --bencode option cmd string interpreted as bencoded list of utf-8
730 strings. This is the recommended way to launch qsubprocess.
731 """
732 takes_args = ['cmd']
733 takes_options = [Option("bencoded", help="Pass command as bencoded string.")]
734 hidden = True
735
736 def run(self, cmd, bencoded=False):
737 from breezy.plugins.qbrz.lib.subprocess import run_subprocess_command
738 return run_subprocess_command(cmd, bencoded)
739
740
741 class cmd_qgetupdates(QBzrCommand):
742 """Fetches external changes into the working tree."""
743
744 takes_args = ['location?']
745 takes_options = [ui_mode_option, execute_option]
746 aliases = ['qgetu', 'qgetup']
747
748 def _qbrz_run(self, location=CUR_DIR, ui_mode=False, execute=False):
749 # branch, relpath = Branch.open_containing(location)
750 tb = TreeBranch.open_containing(location, ui_mode=ui_mode)
751 if tb is None:
752 return errors.EXIT_ERROR
753 if tb.is_lightweight_checkout():
754 window = QBzrUpdateWindow(tb.tree, ui_mode, immediate=execute)
755 elif tb.is_bound():
756 window = UpdateCheckoutWindow(tb.branch, ui_mode=ui_mode)
757 else:
758 window = UpdateBranchWindow(tb.branch, ui_mode=ui_mode)
759 self.main_window = window
760 self.main_window.show()
761 self._application.exec_()
762
763
764 class cmd_qgetnew(QBzrCommand):
765 """Creates a new working tree (either a checkout or full branch)."""
766
767 takes_args = ['location?']
768 takes_options = [ui_mode_option]
769 aliases = ['qgetn']
770
771 def _qbrz_run(self, location=None, ui_mode=False):
772 from breezy.plugins.qbrz.lib.getnew import GetNewWorkingTreeWindow
773 self.main_window = GetNewWorkingTreeWindow(location, ui_mode=ui_mode)
774 self.main_window.show()
775 self._application.exec_()
776
777
778 class cmd_qhelp(QBzrCommand):
779 """Shows a help window"""
780
781 takes_args = ['topic']
782
783 # until we get links and better HTML out of 'topics', this is hidden.
784 hidden = True
785
786 def _qbrz_run(self, topic):
787 show_help(topic)
788 self._application.exec_()
789
790
791 class cmd_qtag(QBzrCommand):
792 """Edit tags."""
793
794 takes_args = ['tag_name?']
795 takes_options = [
796 ui_mode_option,
797 brz_option('tag', 'delete'),
798 brz_option('tag', 'directory'),
799 brz_option('tag', 'force'),
800 'revision',
801 ]
802
803 def _qbrz_run(self, tag_name=None, delete=None, directory=CUR_DIR, force=None, revision=None, ui_mode=False):
804 branch = Branch.open_containing(directory)[0]
805 # determine action based on given options
806 action = TagWindow.action_from_options(force=force, delete=delete)
807 self.main_window = TagWindow(branch, tag_name=tag_name, action=action,
808 revision=revision, ui_mode=ui_mode)
809 self.main_window.show()
810 self._application.exec_()
811
812
813 class cmd_quncommit(QBzrCommand):
814 """Move the tip of a branch to an earlier revision."""
815
816 takes_options = [
817 ui_mode_option,
818 ]
819 takes_args = ["location?"]
820
821 def _qbrz_run(self, location=CUR_DIR, ui_mode=False):
822 window = QBzrUncommitWindow(location, ui_mode=ui_mode)
823 window.show()
824 self._application.exec_()
825
826
827 class cmd_qviewer(QBzrCommand):
828 """Simple file viewer."""
829 aliases = []
830 takes_args = ['filename']
831 takes_options = [
832 Option('encoding', type=check_encoding, help='Encoding of file content (default: utf-8).'),
833 ]
834 _see_also = ['qcat']
835
836 def _qbrz_run(self, filename, encoding=None):
837 window = QBzrViewWindow(filename=filename, encoding=encoding)
838 window.show()
839 self._application.exec_()
840
841
842 class cmd_qversion(QBzrCommand):
843 """Show version/system information."""
844 takes_args = []
845 takes_options = []
846 aliases = []
847
848 def _qbrz_run(self):
849 from breezy.plugins.qbrz.lib.sysinfo import QBzrSysInfoWindow
850 window = QBzrSysInfoWindow()
851 window.show()
852 self._application.exec_()
853
854
855 class cmd_qplugins(QBzrCommand):
856 """Show information about installed plugins."""
857
858 takes_args = []
859 takes_options = []
860 aliases = []
861
862 def _qbrz_run(self):
863 from breezy.plugins.qbrz.lib.plugins import QBzrPluginsWindow
864 window = QBzrPluginsWindow()
865 window.show()
866 self._application.exec_()
867
868
869 class cmd_qupdate(QBzrCommand):
870 """Update working tree with latest changes in the branch."""
871 aliases = ['qup']
872 takes_args = ['directory?']
873 takes_options = [ui_mode_option, execute_option]
874
875 def _qbrz_run(self, directory=None, ui_mode=False, execute=False):
876 tree = open_tree(directory, ui_mode)
877 if tree is None:
878 return
879 self.main_window = QBzrUpdateWindow(tree, ui_mode, execute)
880 self.main_window.show()
881 self._application.exec_()
882
883
884 class cmd_qsend(QBzrCommand):
885 """Mail or create a merge-directive for submitting changes."""
886
887 takes_args = ['submit_branch?', 'public_branch?']
888 takes_options = [ui_mode_option]
889
890 def _qbrz_run(self, submit_branch=CUR_DIR, public_branch=None, ui_mode=False):
891 branch = Branch.open_containing(submit_branch)[0]
892 window = SendWindow(branch, ui_mode)
893 window.show()
894 self._application.exec_()
895
896
897 class cmd_qswitch(QBzrCommand):
898 """Set the branch of a checkout and update."""
899
900 takes_args = ['location?']
901 takes_options = [ui_mode_option]
902
903 def _qbrz_run(self, location=None, ui_mode=False):
904 from breezy.plugins.qbrz.lib.switch import QBzrSwitchWindow
905
906 branch = Branch.open_containing(CUR_DIR)[0]
907 controldir = ControlDir.open_containing(CUR_DIR)[0]
908 self.main_window = QBzrSwitchWindow(branch, controldir, location, ui_mode)
909 self.main_window.show()
910 self._application.exec_()
911
912
913 class cmd_qunbind(QBzrCommand):
914 """Convert the current checkout into a regular branch."""
915 takes_options = [ui_mode_option, execute_option]
916
917 def _qbrz_run(self, ui_mode=False, execute=False):
918 from breezy.plugins.qbrz.lib.unbind import QBzrUnbindDialog
919
920 branch = Branch.open_containing(CUR_DIR)[0]
921 if branch.get_bound_location() is None:
922 raise errors.BzrCommandError("This branch is not bound.")
923
924 self.main_window = QBzrUnbindDialog(branch, ui_mode, execute)
925 self.main_window.show()
926 self._application.exec_()
927
928
929 class cmd_qexport(QBzrCommand):
930 """Export current or past revision to a destination directory or archive.
931
932 DEST is the destination file or dir where the branch will be exported.
933 If BRANCH_OR_SUBDIR is omitted then the branch containing the current working
934 directory will be used.
935 """
936
937 takes_args = ['dest?','branch_or_subdir?']
938 takes_options = [ui_mode_option]
939
940 def _qbrz_run(self, dest=None, branch_or_subdir=None, ui_mode=False):
941 from breezy.plugins.qbrz.lib.export import QBzrExportDialog
942
943 if branch_or_subdir is None:
944 branch = Branch.open_containing(CUR_DIR)[0]
945 else:
946 branch = Branch.open_containing(branch_or_subdir)[0]
947
948 window = QBzrExportDialog(dest, branch, ui_mode)
949 window.show()
950 self._application.exec_()
951
952
953 class cmd_qbind(QBzrCommand):
954 """Convert the current branch into a checkout of the supplied branch.
955
956 LOCATION is the branch where you want to bind your current branch.
957 """
958
959 takes_args = ['location?']
960 takes_options = [ui_mode_option]
961
962 def _qbrz_run(self, location=None, ui_mode=False):
963 from breezy.plugins.qbrz.lib.bind import QBzrBindDialog
964
965 branch = Branch.open_containing(CUR_DIR)[0]
966
967 self.main_window = QBzrBindDialog(branch, location, ui_mode)
968 self.main_window.show()
969 self._application.exec_()
970
971
972 class cmd_qrun(QBzrCommand):
973 """Run arbitrary bzr command.
974
975 If you wish to pass options to COMMAND, use ``--`` beforehand
976 so that the options aren't treated as options to the qrun
977 command itself. For example::
978
979 bzr qrun shelve -- --list
980
981 NOTE: you should use only canonical name of the COMMAND, not the alias.
982 """
983 takes_args = ['command?', 'parameters*']
984 takes_options = [ui_mode_option,
985 Option('directory',
986 help='Working directory.',
987 short_name='d',
988 type=str,
989 ),
990 Option('category',
991 help='Initial category selection.',
992 type=str,
993 ),
994 execute_option,
995 ]
996 aliases = ['qcmd']
997
998 def _qbrz_run(self, command=None, parameters_list=None, ui_mode=False,
999 directory=None, category=None, execute=False):
1000 from breezy.plugins.qbrz.lib.run import QBzrRunDialog
1001 if parameters_list:
1002 def quote_spaces(s):
1003 if " " in s:
1004 s = '"%s"' % s
1005 return s
1006 parameters = " ".join([quote_spaces(i) for i in parameters_list])
1007 else:
1008 parameters = None
1009 if not command:
1010 execute = False
1011 window = QBzrRunDialog(command=command, parameters=parameters,
1012 workdir=directory, category=category, ui_mode=ui_mode,
1013 execute=execute)
1014 window.show()
1015 self._application.exec_()
1016
1017
1018 class cmd_qshelve(QBzrCommand):
1019 """Shelve selected changes away."""
1020 takes_args = ['file*']
1021 takes_options = [
1022 ui_mode_option,
1023 brz_option('shelve', 'list'),
1024 brz_option('shelve', 'directory'),
1025 brz_option('shelve', 'message'),
1026 Option('all', help='Select all changes.'),
1027 Option('complete', help='Show complete files.'),
1028 Option('ignore-whitespace', short_name='w',
1029 help="Ignore whitespace when finding differences.(Only work when --list specified)"),
1030 Option('encoding', type=check_encoding,
1031 help='Encoding of files content (default: utf-8).'),
1032 ]
1033
1034 def _qbrz_run(self, file_list=None, list=False, directory=None, ui_mode=False,
1035 complete=False, ignore_whitespace=False, encoding=None,
1036 all=False, message=None):
1037 if list:
1038 initial_tab = 1
1039 else:
1040 initial_tab = 0
1041 self.main_window = ShelveWindow(file_list=file_list, directory=directory, ui_mode=ui_mode,
1042 initial_tab=initial_tab, complete=complete,
1043 ignore_whitespace=ignore_whitespace, encoding=encoding,
1044 select_all=all, message=message)
1045 self.main_window.show()
1046 self._application.exec_()
1047
1048
1049 class cmd_qunshelve(QBzrCommand):
1050 """Restore shalved changes."""
1051 takes_options = [
1052 ui_mode_option,
1053 brz_option('unshelve', 'directory'),
1054 Option('complete', help='Show complete files.'),
1055 Option('ignore-whitespace', short_name='w',
1056 help="Ignore whitespace when finding differences.(Only work when --list specified)"),
1057 Option('encoding', type=check_encoding,
1058 help='Encoding of files content (default: utf-8).'),
1059 ]
1060
1061 def _qbrz_run(self, directory=None, ui_mode=False,
1062 complete=False, ignore_whitespace=False, encoding=None):
1063 self.main_window = ShelveWindow(directory=directory, ui_mode=ui_mode,
1064 initial_tab=1, complete=complete,
1065 ignore_whitespace=ignore_whitespace, encoding=encoding)
1066 self.main_window.show()
1067 self._application.exec_()
1068
1069
1070 class cmd_qignore(QBzrCommand):
1071 """Ignore files or patterns."""
1072 takes_args = []
1073 takes_options = [
1074 ui_mode_option,
1075 brz_option('ignore', 'directory'),
1076 ]
1077 aliases = []
1078
1079 def _qbrz_run(self, directory=None, ui_mode=False):
1080 from breezy.plugins.qbrz.lib.ignore import IgnoreWindow
1081 wt = WorkingTree.open_containing(directory)[0]
1082 self.main_window = IgnoreWindow(tree=wt, ui_mode=ui_mode)
1083 self.main_window.show()
1084 self._application.exec_()