jp (base): added a CommandBase.start method which is called by run or connected, so subclasses can implement it (this is for simplicity sake, as it's not always clear if run or connected must be used)
This commit is contained in:
parent
5a81941c33
commit
19bdc872c6
1 changed files with 24 additions and 2 deletions
|
|
@ -583,9 +583,11 @@ class CommandBase(object):
|
|||
cls(self)
|
||||
|
||||
def run(self):
|
||||
if self.need_connect is not None:
|
||||
self.host.connect_profile(self.connected)
|
||||
"""this method is called when a command is actually run
|
||||
|
||||
It set stuff like progression callbacks and profile connection
|
||||
You should not overide this method: you should call self.start instead
|
||||
"""
|
||||
try:
|
||||
show_progress = self.args.progress
|
||||
except AttributeError:
|
||||
|
|
@ -599,9 +601,29 @@ class CommandBase(object):
|
|||
self.host.bridge.register("progressFinished", self.progressFinishedHandler)
|
||||
self.host.bridge.register("progressError", self.progressErrorHandler)
|
||||
|
||||
if self.need_connect is not None:
|
||||
self.host.connect_profile(self.connected)
|
||||
else:
|
||||
self.start()
|
||||
|
||||
def connected(self):
|
||||
"""this method is called when profile is connected (or session is started)
|
||||
|
||||
this method is only called when use_profile is True
|
||||
most of time you should override self.start instead of this method, but if loop
|
||||
if not always needed depending on your arguments, you may override this method,
|
||||
but don't forget to call the parent one (i.e. this one) after self.need_loop is set
|
||||
"""
|
||||
if not self.need_loop:
|
||||
self.host.stop_loop()
|
||||
self.start()
|
||||
|
||||
def start(self):
|
||||
"""This is the starting point of the command, this method should be overriden
|
||||
|
||||
at this point, profile are connected if needed
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class CommandAnswering(CommandBase):
|
||||
|
|
|
|||
Loading…
Reference in a new issue