356
365
# their groups individually. But for consistency of this
357
366
# function's API, it's better to sort both than just 'nonexistent'.
358
367
return sorted(remaining), sorted(nonexistent)
370
class StatusHooks(_mod_hooks.Hooks):
371
"""A dictionary mapping hook name to a list of callables for status hooks.
373
e.g. ['post_status'] Is the list of items to be called when the
374
status command has finished printing the status.
378
"""Create the default hooks.
380
These are all empty initially, because by default nothing should get
383
_mod_hooks.Hooks.__init__(self)
384
self.create_hook(_mod_hooks.HookPoint('post_status',
385
"Called with argument StatusHookParams after Bazaar has "
386
"displayed the status. StatusHookParams has the attributes "
387
"(old_tree, new_tree, to_file, versioned, show_ids, short, "
388
"verbose). The last four arguments correspond to the command "
389
"line options specified by the user for the status command. "
390
"to_file is the output stream for writing.",
392
self.create_hook(_mod_hooks.HookPoint('pre_status',
393
"Called with argument StatusHookParams before Bazaar "
394
"displays the status. StatusHookParams has the attributes "
395
"(old_tree, new_tree, to_file, versioned, show_ids, short, "
396
"verbose). The last four arguments correspond to the command "
397
"line options specified by the user for the status command. "
398
"to_file is the output stream for writing.",
402
class StatusHookParams(object):
403
"""Object holding parameters passed to post_status hooks.
405
:ivar old_tree: Start tree (basis tree) for comparison.
406
:ivar new_tree: Working tree.
407
:ivar to_file: If set, write to this file.
408
:ivar versioned: Show only versioned files.
409
:ivar show_ids: Show internal object ids.
410
:ivar short: Use short status indicators.
411
:ivar verbose: Verbose flag.
414
def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
416
"""Create a group of post_status hook parameters.
418
:param old_tree: Start tree (basis tree) for comparison.
419
:param new_tree: Working tree.
420
:param to_file: If set, write to this file.
421
:param versioned: Show only versioned files.
422
:param show_ids: Show internal object ids.
423
:param short: Use short status indicators.
424
:param verbose: Verbose flag.
426
self.old_tree = old_tree
427
self.new_tree = new_tree
428
self.to_file = to_file
429
self.versioned = versioned
430
self.show_ids = show_ids
432
self.verbose = verbose
434
def __eq__(self, other):
435
return self.__dict__ == other.__dict__
438
return "<%s(%s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
439
self.old_tree, self.new_tree, self.to_file, self.versioned,
440
self.show_ids, self.short, self.verbose)
443
def _show_shelve_summary(params):
444
"""post_status hook to display a summary of shelves.
446
:param params: StatusHookParams.
448
shelves = shelf.list_shelves(params.new_tree)
450
params.to_file.write('%d shelves exist. '
451
'See "bzr shelve --list" for details.\n' % len(shelves))
454
hooks = StatusHooks()
457
hooks.install_named_hook('post_status', _show_shelve_summary,