jp (base): refactored need_loop so it is set only when the command is run. It can now be set in __init__ methods of commands classes
This commit is contained in:
parent
19bdc872c6
commit
89f6fe8605
1 changed files with 9 additions and 12 deletions
|
|
@ -76,7 +76,6 @@ class Jp(object):
|
|||
def __init__(self):
|
||||
"""
|
||||
|
||||
@attribute need_loop(bool): to set by commands when loop is needed
|
||||
@attribute quit_on_progress_end (bool): set to False if you manage yourself exiting,
|
||||
or if you want the user to stop by himself
|
||||
@attribute progress_success(callable): method to call when progress just started
|
||||
|
|
@ -102,7 +101,7 @@ class Jp(object):
|
|||
self.add_parser_options()
|
||||
self.subparsers = self.parser.add_subparsers(title=_('Available commands'), dest='subparser_name')
|
||||
self._auto_loop = False # when loop is used for internal reasons
|
||||
self.need_loop = False # to set by commands when loop is needed
|
||||
self._need_loop = False
|
||||
|
||||
# progress attributes
|
||||
self._progress_id = None # TODO: manage several progress ids
|
||||
|
|
@ -242,7 +241,7 @@ class Jp(object):
|
|||
def run(self, args=None):
|
||||
self.args = self.parser.parse_args(args)
|
||||
self.args.func()
|
||||
if self.need_loop or self._auto_loop:
|
||||
if self._need_loop or self._auto_loop:
|
||||
self._start_loop()
|
||||
|
||||
def _start_loop(self):
|
||||
|
|
@ -263,7 +262,7 @@ class Jp(object):
|
|||
|
||||
/!\: return must be used after calling this method !
|
||||
"""
|
||||
assert self.need_loop
|
||||
assert self._need_loop
|
||||
# XXX: python-dbus will show a traceback if we exit in a signal handler with an error code
|
||||
# so we use this little timeout trick to avoid it
|
||||
GLib.timeout_add(0, self.quit, errcode)
|
||||
|
|
@ -412,8 +411,10 @@ class CommandBase(object):
|
|||
Can't be set if use_profile is False
|
||||
@param help(unicode): help message to display
|
||||
@param **kwargs: args passed to ArgumentParser
|
||||
@attribute need_loop(bool): to set by commands when loop is needed
|
||||
|
||||
"""
|
||||
self.need_loop = False # to be set by commands when loop is needed
|
||||
try: # If we have subcommands, host is a CommandBase and we need to use host.host
|
||||
self.host = host.host
|
||||
except AttributeError:
|
||||
|
|
@ -448,14 +449,6 @@ class CommandBase(object):
|
|||
def args(self):
|
||||
return self.host.args
|
||||
|
||||
@property
|
||||
def need_loop(self):
|
||||
return self.host.need_loop
|
||||
|
||||
@need_loop.setter
|
||||
def need_loop(self, value):
|
||||
self.host.need_loop = value
|
||||
|
||||
@property
|
||||
def profile(self):
|
||||
return self.host.profile
|
||||
|
|
@ -588,6 +581,10 @@ class CommandBase(object):
|
|||
It set stuff like progression callbacks and profile connection
|
||||
You should not overide this method: you should call self.start instead
|
||||
"""
|
||||
# host._need_loop is set here from our current value and not before
|
||||
# as the need_loop decision must be taken only by then running command
|
||||
self.host._need_loop = self.need_loop
|
||||
|
||||
try:
|
||||
show_progress = self.args.progress
|
||||
except AttributeError:
|
||||
|
|
|
|||
Loading…
Reference in a new issue