psa: remove old event feed items
[feedingit] / src / FeedingIt-Web.py
index 865b27f..e864d97 100644 (file)
@@ -11,6 +11,12 @@ from threading import Thread
 from os.path import isfile, isdir, exists
 from os import mkdir, remove, stat, environ
 
+import logging
+logger = logging.getLogger(__name__)
+
+import debugging
+debugging.init(dot_directory=".feedingit", program_name="feedingit-web")
+
 CONFIGDIR = environ.get("HOME", "/home/user") + "/.feedingit"
 #CONFIGDIR = "/home/user/.feedingit/"
 
@@ -45,7 +51,7 @@ def sanitize(text):
 
 def start_server():
     global listing
-    listing = Listing(CONFIGDIR)
+    listing = Listing(config, CONFIGDIR)
     httpd = BaseHTTPServer.HTTPServer(("127.0.0.1", PORT), Handler)
     httpd.serve_forever()
 
@@ -70,37 +76,11 @@ class App():
 #        download = Download(listing, feeds)
 #        download.start()
     
-class Download(Thread):
-    def __init__(self, listing, keys):
-        Thread.__init__(self)
-        self.listing = listing
-        self.keys = keys
-        
-    def run (self):
-        updateDbusHandler.UpdateStarted()
-        for key in self.keys:
-            print "Start update: %s" % key
-            updatingFeeds.append(key)
-            (use_proxy, proxy) = config.getProxy()
-            try:
-                if use_proxy:
-                        self.listing.updateFeed(key, proxy=proxy, imageCache=config.getImageCache() )
-                else:
-                        self.listing.updateFeed(key, imageCache=config.getImageCache() )
-            except:
-                print "Error updating feed: %s" %key
-            updatingFeeds.remove(key)
-            print "End update: %s" % key
-        updateDbusHandler.UpdateFinished()
-
 class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
     def updateAll(self):
-        feeds = []
         for cat in listing.getListOfCategories():
             for feed in listing.getSortedListOfKeys("Manual", category=cat):
-                feeds.append(feed)
-        download = Download(listing, feeds)
-        download.start()
+                listing.updateFeed(feed)
     
     def openTaskSwitch(self):
         import subprocess
@@ -168,7 +148,6 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
         if markAllAsRead=="True":
             feed.markAllAsRead()
             listing.updateUnread(key)
-            updateDbusHandler.ArticleCountUpdated()
         xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml>"
         if onlyUnread == "False":
             onlyUnread = False
@@ -233,7 +212,6 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
             feed = listing.getFeed(key)
             feed.setEntryRead(article)
             listing.updateUnread(key)
-            updateDbusHandler.ArticleCountUpdated()
             self.send_response(200)
             self.send_header("Content-type", "text/html")
             self.end_headers()
@@ -268,13 +246,11 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
             xml = "<xml>OK</xml>"
         elif request[1] == "updateFeed":
             key = request[2]
-            download = Download(listing, [key,])
-            download.start()
+            listing.updateFeed(key)
             xml = "<xml>OK</xml>"
         elif request[1]=="updateAll":
             #app.automaticUpdate()
             self.updateAll()
-            updateDbusHandler.ArticleCountUpdated()
             xml = "<xml>OK</xml>"
         elif request[1] == "addCat":
             catName = request[2]
@@ -294,7 +270,7 @@ if not isdir(CONFIGDIR):
     try:
         mkdir(CONFIGDIR)
     except:
-        print "Error: Can't create configuration directory"
+        logger.error("Error: Can't create configuration directory")
         from sys import exit
         exit(1)
 
@@ -305,22 +281,24 @@ import thread
 
 
 
-# Start the HTTP server in a new thread
-thread.start_new_thread(start_server, ())
-
 # Initialize the glib mainloop, for dbus purposes
 from feedingitdbus import ServerObject
-from updatedbus import UpdateServerObject, get_lock
+from updatedbus import UpdateServerObject
 
 import gobject
 gobject.threads_init()
 import dbus.mainloop.glib
 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+import mainthread
+mainthread.init()
+from jobmanager import JobManager
+JobManager(True)
 
-global updateDbusHandler, dbusHandler
 app = App()
 dbusHandler = ServerObject(app)
-updateDbusHandler = UpdateServerObject(app)
+
+# Start the HTTP server in a new thread
+thread.start_new_thread(start_server, ())
 
 mainloop = gobject.MainLoop()
 mainloop.run()