← Back to team overview

gtg team mailing list archive

[Merge] lp:~parinporecha/gtg/config_parser_bug into lp:gtg

 

Parin Porecha has proposed merging lp:~parinporecha/gtg/config_parser_bug into lp:gtg.

Requested reviews:
  Gtg developers (gtg)

For more details, see:
https://code.launchpad.net/~parinporecha/gtg/config_parser_bug/+merge/183771

Patch for Bug #1218093 and Bug #1218708.

If you ran GTG while facing the bugs, it might've messed up your config files '~/.config/gtg/gtg.conf', '~/.config/gtg/tasks.conf'

This patch will give errors if those malformed strings are present in them. Please delete your 'tasks.conf' and remove the list of expanded tags in 'gtg.conf', or delete the file itself.

After removing those config files, no errors should be displayed and the state of expanded and collapsed tags in sidebar, and tasks should be remembered upon restarting GTG.
-- 
https://code.launchpad.net/~parinporecha/gtg/config_parser_bug/+merge/183771
Your team Gtg developers is requested to review the proposed merge of lp:~parinporecha/gtg/config_parser_bug into lp:gtg.
=== modified file 'GTG/core/__init__.py'
--- GTG/core/__init__.py	2013-08-25 20:07:47 +0000
+++ GTG/core/__init__.py	2013-09-03 21:31:52 +0000
@@ -36,6 +36,8 @@
 """
 
 #=== IMPORT ===================================================================
+from re import findall
+
 import ConfigParser
 from xdg.BaseDirectory import xdg_data_home, xdg_config_home, xdg_data_dirs
 import os
@@ -114,7 +116,11 @@
                     # This is just for backward compatibility
                     if toreturn and toreturn[0] == '[' and toreturn[-1] == ']':
                         toreturn = toreturn[1:-1]
-                    toreturn = toreturn.split(',')
+
+                    # Splitting by ',' caused bugs #1218093 and #1216807.
+                    # Parsing the below way
+                    # does not split "('string1', 'string2', ... )" further
+                    toreturn = findall(r'\(.*?\)', toreturn)
                     while toreturn and toreturn[-1] == '':
                         toreturn = toreturn[:-1]
                 elif ntype == bool and type(toreturn) == str:
@@ -168,7 +174,7 @@
         return value.split(', ')
 
     def set(self, tid, option, value):
-        value = ','.join(str(x) for x in value)
+        value = ', '.join(str(x) for x in value)
         self._conf.set(tid, option, value)
         self.save()
 

=== modified file 'GTG/gtk/browser/browser.py'
--- GTG/gtk/browser/browser.py	2013-08-20 09:07:15 +0000
+++ GTG/gtk/browser/browser.py	2013-09-03 21:31:52 +0000
@@ -24,6 +24,7 @@
 import time
 import threading
 from webbrowser import open as openurl
+from re import search, escape, findall
 
 import pygtk
 pygtk.require('2.0')
@@ -783,14 +784,29 @@
 
     def on_tag_expanded(self, sender, tag):
         colt = self.config.get("expanded_tags")
+
+        # Directly appending tag to colt causes GTG to forget the state of
+        # sub-tags (expanded/collapsed) in specific scenarios. Below is an
+        # updated way which checks if any children of the tag is in colt or not
+        # If yes, then the tag is inserted before the first child.
+        # If no, it's appended to colt
         if tag not in colt:
-            colt.append(tag)
+            first_child = search("\(" + escape(tag[1:-1]) + ".*?\)", \
+                                 ','.join(colt))
+            if first_child:
+                colt.insert(colt.index(first_child.group()), tag)
+            else:
+                colt.append(tag)
         self.config.set("expanded_tags", colt)
 
     def on_tag_collapsed(self, sender, tag):
         colt = self.config.get("expanded_tags")
-        if tag in colt:
-            colt.remove(str(tag))
+
+        # When a tag is collapsed, we should also remove it's children
+        # from colt, otherwise when parent tag is expanded, they also get
+        # expanded (unwanted situation)
+        children = findall("\(" + escape(tag[1:-1]) + ".*?\)", ','.join(colt))
+        colt = [tag for tag in colt if tag not in children]
         self.config.set("expanded_tags", colt)
 
     def on_quickadd_activate(self, widget):


Follow ups