Work on feed discovery dialog.
[straw/fork.git] / straw / FeedDiscovery.py
blob92a95c5df5c069b38bc7bbf96993cff4475d4473
1 """
3 """
5 __copyright__ = "Copyright (c) 2002-2005 Free Software Foundation, Inc."
6 __license__ = """
7 Straw is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 2 of the License, or (at your option) any later
10 version.
12 Straw is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 Place - Suite 330, Boston, MA 02111-1307, USA. """
20 from JobManager import Job, TaskResult, TaskThread, TaskInfo, ThreadPoolJobHandler
21 import JobManager
22 import SummaryParser
23 import feedfinder
25 class FeedDiscoveryJobHandler(ThreadPoolJobHandler):
26 job_id = "feed-discovery"
28 def __init__(self, job):
29 ThreadPoolJobHandler.__init__(self, job)
31 self.pool_size = 1
32 self.result_class = FeedDiscoveryTaskResult
33 self.task_class = FeedDiscoveryTaskThread
35 def _split(self):
36 ti = TaskInfo(1, { "url" : self.job.data })
37 self.task_queue.put(ti)
39 def _prepare_result(self):
40 task_result = self.result_queue.get()
41 return task_result.result
43 class FeedDiscoveryTaskResult(TaskResult):
44 def __init__(self, task_info, result):
45 self.task_info = task_info
46 self.result = result
48 def get(self):
49 raise NotImplementedError
51 class FeedDiscoveryTaskThread(TaskThread):
52 def __init__(self, handler, task_queue, result_queue):
53 TaskThread.__init__(self, handler, task_queue, result_queue)
55 def _process(self, task):
56 url = task.data["url"]
57 data = feedfinder.feeds(url, True)
58 feeds = [SummaryParser.parse(content, location = url) for url, content in data]
59 return feeds
61 JobManager.register_handler(FeedDiscoveryJobHandler)
63 def discover(url, observers):
64 update = Job("feed-discovery")
65 update.data = url
66 update.observers = observers
67 JobManager.start_job(update)