changeset 1862:6d9c87bdc452

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)
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 16:52:51 +0100
parents 3b2a236fa743
children b2ddd7f5dcdf
files frontends/src/jp/base.py
diffstat 1 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/base.py	Mon Feb 29 16:52:51 2016 +0100
+++ b/frontends/src/jp/base.py	Mon Feb 29 16:52:51 2016 +0100
@@ -583,9 +583,11 @@
             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 @@
             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):