changeset 1863:b2ddd7f5dcdf

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
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 16:52:51 +0100
parents 6d9c87bdc452
children 96ba685162f6
files frontends/src/jp/base.py
diffstat 1 files changed, 9 insertions(+), 12 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
@@ -76,7 +76,6 @@
     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 @@
         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 @@
     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 @@
 
         /!\: 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 @@
             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:
@@ -449,14 +450,6 @@
         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 @@
         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: