From 19bdc872c6bd8690e6468d95b55f4dfc97abccbc Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 29 Feb 2016 16:52:51 +0100 Subject: [PATCH] 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) --- frontends/src/jp/base.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/frontends/src/jp/base.py b/frontends/src/jp/base.py index 596754fb..69bf2f2e 100644 --- a/frontends/src/jp/base.py +++ b/frontends/src/jp/base.py @@ -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):