]> khamidou — GitHub mirrors - liszt.git/commitdiff
added a new CachedList class
authorkhamidou <khamidou@gmail.com>
Wed, 10 Feb 2010 17:16:06 +0000 (18:16 +0100)
committerkhamidou <khamidou@gmail.com>
Wed, 10 Feb 2010 17:16:06 +0000 (18:16 +0100)
liszt
liszt-daemon

diff --git a/liszt b/liszt
index 3b664296edf3dacfe22038a3ff1f3973ad697ca5..c55732c18c4ab3813177a64e7844b6303e9f566c 100755 (executable)
--- a/liszt
+++ b/liszt
@@ -48,15 +48,31 @@ def create_spool_file(dict):
 class CachedList(object):
     def __init__(self, listname):
         try:
+            self.listname = listname
             fd = open(os.path.expanduser('~/.liszt/cached/%s' % listname))
         except IOError:
             bailout("Unable to open cached list " + listname)
 
         try:
-            self.list = json.load(fd)
+            self.cached_list = json.load(fd)
         except ValueError:
-            bailout("List %s is not a valid json file" % listname)
-        fd.close()
+            bailout("List <%s> is not a valid json file" % listname)
+
+    def save(self):
+        fd = open(os.path.expanduser('~/.liszt/cached/%s' % listname), 'w+')
+        json.dump(self.cached_list, fd)
+    
+    def fget(self):
+        return self.cached_list
+    
+    def fset(self, list):
+        self.cached_list = list
+
+    def fdel(self):
+        del self.cached_list
+        
+    contents = property(fget, fset, fdel)
+
 class CommandParser(object):
     def __init__(self, args):
         self.dispatch = {"create" : self.parse_create,
@@ -111,25 +127,31 @@ class CommandParser(object):
         listname = ""
         entryname = ""
 
-        if sys.stdin.isatty():
-            sys.stdin = os.popen('/bin/sh -c less -', 'w')
+        if sys.stdout.isatty():
+            sys.stdout = os.popen('/bin/sh -c less -', 'w')
 
         if len(args) == 0:
             print "List of the created lists :"
-            lists = open(os.path.expanduser('~/.liszt/cache/lists_list'))
-            for list in lists.readlines():
+            lists_list = CachedList("lists_list")
+
+            for list in lists_list.contents:
                 print list
 
         if len(args) == 1:
-            listfd = open(os.path.expanduser('~/.liszt/cache/lists_list') + args[0])
-            list = json.load(listfd)
-            print list
-#             for entry in entries["contents"]:
-#                 print entry["title"] + "\t" + entry["date"]
-
-#         elif len(args) == 2:
-#             entry = session.get_entry(args[0], args[1])
-#             print entry["title"] + "\t" + entry["date"]
+            list = CachedList(args[0])
+
+            for entry in list.contents["contents"]:
+                print entry["title"] + "\t" + entry["date"]
+
+        elif len(args) == 2:
+            list = CachedList(args[0])
+            index = int(args[1])
+            try:
+                entry = list.contents["contents"][index]
+            except IndexError:
+                bailout("Invalid entry index.")
+
+            print entry["title"] + "\t" + entry["date"]
 
     def parse_remove(self, args):
         listname = ""
index c021b59a9bb63992745265dbbeb9855b4aa6493e..34058fee0e1ef0987ed98152a7d5adbd26548430 100755 (executable)
@@ -335,6 +335,11 @@ def cache_new_lists():
         json.dump(dict, fd)
         fd.close()
 
+    # Also save a list of the lists :
+    fd = open(os.path.expanduser('~/.liszt/cached/lists_list'), 'w+')
+    json.dump(session.get_lists_list(), fd)
+    fd.close()
+
     time.sleep(15 * 60)
         
 def sync_cached_list(path):