5 __copyright__
= "Copyright (c) 2002-2005 Free Software Foundation, Inc."
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
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
25 class FeedDiscoveryJobHandler(ThreadPoolJobHandler
):
26 job_id
= "feed-discovery"
28 def __init__(self
, job
):
29 ThreadPoolJobHandler
.__init
__(self
, job
)
32 self
.result_class
= FeedDiscoveryTaskResult
33 self
.task_class
= FeedDiscoveryTaskThread
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
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
]
61 JobManager
.register_handler(FeedDiscoveryJobHandler
)
63 def discover(url
, observers
):
64 update
= Job("feed-discovery")
66 update
.observers
= observers
67 JobManager
.start_job(update
)