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 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, listing, config, dbusHandler):
47 threading.Thread.__init__(self)
49 self.listing = listing
51 self.dbusHandler = dbusHandler
53 self.dbug = open(CONFIGDIR+"dbug.log", "w")
58 self.dbug.write("Starting updates\n")
60 self.dbusHandler.UpdateStarted()
61 (use_proxy, proxy) = self.config.getProxy()
62 for key in self.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 self.listing.updateFeed(key, self.config.getExpiry(), proxy=proxy, imageCache=self.config.getImageCache() )
71 self.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 self.listing.saveConfig()
89 self.dbug.write("About to main_quit\n")
92 self.dbug.write("After main_quit\n")
97 self.listing = Listing(CONFIGDIR)
98 self.config = Config(self, CONFIGDIR+"config.ini")
99 self.dbusHandler = UpdateServerObject(self)
100 self.updateThread = False
102 def automaticUpdate(self):
103 #self.listing.updateFeeds()
104 if self.updateThread == False:
105 self.updateThread = Download(self.listing, self.config, self.dbusHandler)
106 self.updateThread.start()
108 def stopUpdate(self):
110 self.updateThread.running = False
114 import dbus.mainloop.glib
115 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
117 gobject.threads_init()
118 mainloop = gobject.MainLoop()
120 app_lock = get_lock("app_lock")
129 file = open("/home/user/.feedingit/feedingit_update.log", "w")
130 traceback.print_exc(file=file)
133 file = open("/home/user/.feedingit/feedingit_update.log", "a")
134 file.write("Update in progress")