]> git.madduck.net Git - etc/taskwarrior.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

TaskWarrior: Use config propery instead of get_config call
authorTomas Babej <tomasbabej@gmail.com>
Sat, 15 Aug 2015 01:41:08 +0000 (03:41 +0200)
committerTomas Babej <tomasbabej@gmail.com>
Sat, 26 Dec 2015 03:17:33 +0000 (04:17 +0100)
tasklib/backends.py

index 32a8018acb142ddb1257e0fe3916089bde2ecf70..fbe3ba336e53b50f92a08874c0d1a9b9cec5e7c9 100644 (file)
@@ -103,6 +103,7 @@ class TaskWarrior(Backend):
         if not os.path.exists(self.taskrc_location):
             self.taskrc_location = '/'
 
+        self._config = None
         self.version = self._get_version()
         self.config = {
             'confirmation': 'no',
@@ -229,7 +230,13 @@ class TaskWarrior(Backend):
 
     # Public interface
 
-    def get_config(self):
+    @property
+    def config(self):
+        # First, check if memoized information is available
+        if self._config:
+            return copy.deepcopy(self._config)
+
+        # If not, fetch the config using the 'show' command
         raw_output = self.execute_command(
             ['show'],
             config_override={'verbose': 'nothing'}
@@ -243,7 +250,10 @@ class TaskWarrior(Backend):
             if match:
                 config[match.group('key')] = match.group('value').strip()
 
-        return config
+        # Memoize the config dict
+        self._config = config
+
+        return copy.deepcopy(config)
 
     def execute_command(self, args, config_override=None, allow_failure=True,
                         return_all=False):