]> khamidou — GitHub mirrors - liszt.git/commitdiff
porting to liszt-daemon, part 2
authorkhamidou <khamidou@gmail.com>
Tue, 9 Feb 2010 17:49:33 +0000 (18:49 +0100)
committerkhamidou <khamidou@gmail.com>
Tue, 9 Feb 2010 17:49:33 +0000 (18:49 +0100)
liszt

diff --git a/liszt b/liszt
index 35ad795623ffe8bdde5ee8134c639a263a2d107e..9d7532e5320e3e54600f52cf76d0811467be6819 100755 (executable)
--- a/liszt
+++ b/liszt
@@ -42,8 +42,8 @@ def bailout(msg):
 def create_spool_file(dict):
 # Create a spool file and save dict inside as a json dict.
     fd, filename = tempfile.mkstemp(dir=os.path.expanduser('~/.liszt/delayed/'))
-    json.dump(dict, fd)
-    fd.close()
+    os.write(fd, json.dumps(dict))
+    os.close(fd)
     
     
 class CommandParser(object):
@@ -122,19 +122,24 @@ class CommandParser(object):
 
     def parse_remove(self, args):
         listname = ""
-        entryname = ""
+        index = ""
+        spldict = {} # The dictionnary saved in a spool file.
 
-        if len(args) == 0:
-            bailout("liszt rm listname [optional entry index]")
+        if len(args) == 0 or len(args) > 2:
+            bailout("liszt remove listname [optional entry index]")
 
-        if len(args) == 1:
-            session.remove_list(args[0])
-            print "removed list " + args[0]
+        listname = args[0]
+
+        if len(args) == 2:
+            index = int(args[1])
+            spldict["request"] = "delete-entry"
+            spldict["index"] = index
+            spldict["listname"] = listname
+        else:
+            spldict["request"] = "delete-list"
+            spldict["listname"] = listname
 
-        elif len(args) == 2:
-            session.remove_list_entry(args[0], args[1])
-            print "removed from list " + args[0] + " entry #" + args[1] 
-        pass
+        create_spool_file(spldict)
     
     def parse_update(self, args):
 
@@ -160,17 +165,17 @@ class CommandParser(object):
             
             # Now, reopen the fd, as a python file handle.
             fd = open(filename)
-            dict = {"contents" : []}
-            lines = fd.readlines()
+            lines = fd.read().split('+')
 
             for i in range(len(lines)):
                 fields = lines[i].split("\t")
                 if len(fields) != 4:
                     bailout("Error : one of the fields is not correctly formatted.") # FIXME : display the line number too.
 
-                dict = {"title" : fields[1], "date" : fields[2], "done": fields[3]}
-                print dict
-                session.update_list_entry(listname, i, dict)
+                dict = {"request" : "update-entry", "listname" : listname,
+                        "index" : i, "contents" : {"title" : fields[1], "date" : fields[2], "done": fields[3]}}
+
+                create_spool_file(dict)
 
             os.unlink(filename)
 
@@ -197,6 +202,8 @@ class CommandParser(object):
             
             if lines[i] != '':
                 session.create_list_entry(listname, lines[i].rstrip().lstrip())
+                dict = {"request" : "create-entry", "listname" : listname, "contents" : {"title" : lines[i]}}
+                create_spool_file(dict)
 
         os.unlink(filename)