]> khamidou — GitHub mirrors - liszt.git/commitdiff
everything works as expected
authorkhamidou <khamidou@gmail.com>
Mon, 15 Feb 2010 10:24:35 +0000 (11:24 +0100)
committerkhamidou <khamidou@gmail.com>
Mon, 15 Feb 2010 10:24:35 +0000 (11:24 +0100)
libliszt/utils.py
liszt
liszt-daemon

index f2314c7dff236fe5d58e0fd3809c8b4e502ee660..bd8bacc62c23d17398fa4b2420710f36987ae630 100644 (file)
@@ -88,8 +88,7 @@ class Daemon:
                        pid = None
        
                if pid:
-                       message = "pidfile %s already exist. Daemon already running?\n"
-                       sys.stderr.write(message % self.pidfile)
+                       # Exit silently
                        sys.exit(1)
                
                # Start the daemon
@@ -190,10 +189,13 @@ class LisztSession:
         return json.load(req)
 
     def get_list(self, listname):
+        req = None
+
         try:
             req = urllib2.urlopen(base + "/get/" + quote(listname) + "/")
-        except HTTPError:
+        except URLError:
             bailout("Unable to open the list " + listname)
+            sys.exit(-1)
 
         return json.load(req)
 
@@ -202,6 +204,7 @@ class LisztSession:
             req = urllib2.urlopen(base + "/get/" + quote(listname) + "/" + str(index) + "/")
         except HTTPError:
             bailout("Unable to get entry " + str(index) + " from list " + listname)
+            return
 
         return json.load(req)
 
diff --git a/liszt b/liszt
index 0354dadc78383d8693be64470671f3a3e17ee02b..a89a8318ec178a7c590eca53b1dcd1f255a54597 100755 (executable)
--- a/liszt
+++ b/liszt
@@ -302,4 +302,5 @@ if __name__ == "__main__":
         help()
         sys.exit(0)
 
+    os.system("./liszt-daemon")
     parser = CommandParser(sys.argv[1:])
index 03e135ac0ccfca46158540ecbcad0ffaa022e542..2591fa818afa7149156003456bfeb04cb33fd519 100755 (executable)
@@ -31,6 +31,12 @@ conf.read(os.path.expanduser('~/.liszt/config'))
 username = conf.get('Credentials', 'username')
 password = conf.get('Credentials', 'password')
 
+session = LisztSession()
+session.login(username, password)
+
+
+update_interval = 30
+
 def process_json_delayed_file(path, session):
     try:
         fd = open(path)
@@ -71,7 +77,7 @@ def watch_spool_dir():
             process_json_delayed_file(os.path.expanduser('~/.liszt/delayed/') + file, session)
 
         
-        time.sleep(15 * 60) # Sync the files with the server every 15 minutes.
+        time.sleep(update_interval) # Sync the files with the server every 15 minutes.
 
 def cache_new_lists():
     # This thread caches lists that were recently created on the server but are not available
@@ -92,18 +98,18 @@ def cache_new_lists():
     cl.contents = list(cl.contents)
     cl.save()
 
-    time.sleep(15 * 60)
+    time.sleep(update_interval)
         
-def sync_cached_list(list):
-    def isentrydefined(title, list):
+def sync_cached_list(listname):
+    def isentrydefined(title, l):
         # Is an entry in a list ? Yes if it's title is in the list
-        for e in list:
+        for e in l:
             if e["title"] == title:
                 return True
 
         return False
 
-    cached_list = CachedList(list)
+    cached_list = CachedList(listname)
     server_list = session.get_list(listname)
 
     for entry in server_list:
@@ -116,18 +122,17 @@ def sync_cached_list(list):
         if not isentrydefined(entry["title"], cached_list.contents["contents"]):
             cached_list.contents["contents"].push(entry)
 
-    json.dump(fd)
+    cached_list.save()
     
-def watch_cache_dir(name, session):
+def watch_cache_dir():
     while True:
-        for list in os.listdir(os.path.expanduser('~/.liszt/cached/')):
-            sync_cached_list(list)
-        
-        time.sleep(20 * 60) # Sync the files with the server every 20 minutes.
+        for cached_list in os.listdir(os.path.expanduser('~/.liszt/cached/')):
+            if cached_list == "lists_list":
+                continue
 
-# class LisztDaemon(Daemon):
-#     def run(self):
-#         pass
+            sync_cached_list(cached_list)
+        
+        time.sleep(update_interval)
 
 class SpoolThread(threading.Thread):
     def run(self):
@@ -141,18 +146,18 @@ class SyncListsThread(threading.Thread):
     def run(self):
         watch_cache_dir()
 
-if __name__ == "__main__":
-    session = LisztSession()
-    session.login(username, password)
+class LisztDaemon(Daemon):
+    def run(self):
+        st = SpoolThread()
+        st.start()
 
-#    st = SpoolThread()
-#    st.run()
+        clt = CacheNewListsThread()
+        clt.start()
 
-    clt = CacheNewListsThread()
-    clt.run()
-
-#     slt = SyncListsThread()
-#     slt.run()
-    
-#    daemon = LisztDaemon(pidfile="/var/lock/liszt-daemon.pidfile")
+        slt = SyncListsThread()
+        slt.start()
 
+if __name__ == "__main__":
+    daemon = LisztDaemon(pidfile="/var/lock/liszt-daemon.pidfile")
+    daemon.run()
+    daemon.start()