1 #!/usr/bin/env python2.5
4 # Copyright (c) 2007-2008 INdT.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # ============================================================================
20 # Name : update_feeds.py
21 # Author : Yves Marcoz
23 # Description : Simple RSS Reader
24 # ============================================================================
26 from rss_sqlite import Listing
27 from config import Config
33 CONFIGDIR="/home/user/.feedingit/"
34 #DESKTOP_FILE = "/usr/share/applications/hildon-status-menu/feedingit_status.desktop"
37 from socket import setdefaulttimeout
39 setdefaulttimeout(timeout)
42 from updatedbus import UpdateServerObject, get_lock
44 class Download(threading.Thread):
45 def __init__(self, config, dbusHandler):
47 threading.Thread.__init__(self)
50 self.dbusHandler = dbusHandler
52 self.dbug = open(CONFIGDIR+"dbug.log", "w")
57 self.dbug.write("Starting updates\n")
59 self.dbusHandler.UpdateStarted()
60 (use_proxy, proxy) = self.config.getProxy()
61 listing = Listing(CONFIGDIR)
62 for key in listing.getListOfFeeds():
64 self.dbug.write("updating %s\n" %key)
67 from urllib2 import install_opener, build_opener
68 install_opener(build_opener(proxy))
69 listing.updateFeed(key, self.config.getExpiry(), proxy=proxy, imageCache=self.config.getImageCache() )
71 listing.updateFeed(key, self.config.getExpiry(), imageCache=self.config.getImageCache() )
74 file = open("/home/user/.feedingit/feedingit_update.log", "a")
75 traceback.print_exc(file=file)
79 self.dbug.write("received stopUpdate after %s\n" %key)
81 self.dbusHandler.UpdateFinished()
82 self.dbusHandler.ArticleCountUpdated()
84 self.dbug.write("Dbus ArticleCountUpdated signal sent\n")
87 file = open("/home/user/.feedingit/feedingit_update.log", "a")
88 traceback.print_exc(file=file)
92 self.dbug.write("About to main_quit\n")
95 self.dbug.write("After main_quit\n")
100 self.config = Config(self, CONFIGDIR+"config.ini")
101 self.dbusHandler = UpdateServerObject(self)
102 self.updateThread = False
104 def automaticUpdate(self):
105 #self.listing.updateFeeds()
106 if self.updateThread == False:
107 self.updateThread = Download(self.config, self.dbusHandler)
108 self.updateThread.start()
110 def stopUpdate(self):
112 self.updateThread.running = False
116 import dbus.mainloop.glib
117 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
119 gobject.threads_init()
120 mainloop = gobject.MainLoop()
122 app_lock = get_lock("app_lock")
131 file = open("/home/user/.feedingit/feedingit_update.log", "w")
132 traceback.print_exc(file=file)
135 file = open("/home/user/.feedingit/feedingit_update.log", "a")
136 file.write("Update in progress")