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 Fetcher
import FetchTask
21 from JobManager
import Job
, TaskResult
, TaskThread
, JobHandler
31 class FeedUpdateJobHandler(JobHandler
):
32 job_id
= "feed-update"
35 "update-started" : (gobject
.SIGNAL_RUN_LAST
, gobject
.TYPE_NONE
, (gobject
.TYPE_PYOBJECT
,)),
36 "update-done" : (gobject
.SIGNAL_RUN_LAST
, gobject
.TYPE_NONE
, (gobject
.TYPE_PYOBJECT
,))
39 def __init__(self
, id, job
):
40 JobHandler
.__init
__(self
, id, job
)
42 def _on_fetch_started(self
, handler
, task
):
43 self
._notify
("update-started", task
.user_data
)
45 def _on_url_fetched(self
, handler
, fetch_result
):
46 feed
= fetch_result
.task
.user_data
49 if fetch_result
.result
.error
:
50 update_result
= FeedUpdateResult("fetch-error", feed
, fetch_result
.result
)
52 update_result
= FeedUpdateResult(None, feed
, fetch_result
.result
)
53 feed
= SummaryParser
.parse(fetch_result
.result
.content
, feed
)
55 self
._notify
("update-done", update_result
)
57 def _on_fetch_done(self
, handler
, data
):
61 self
.fetch_tasks
= [Fetcher
.create_task(url
= feed
.location
, user_data
= feed
) for feed
in self
.job
.tasks
]
63 self
.observers
= [{ "task-done": [ self
._on
_url
_fetched
],
64 "task-start": [ self
._on
_fetch
_started
],
65 "job-done": [ self
._on
_fetch
_done
]}]
68 print "starting fetch..."
69 self
.fetcher_id
= Fetcher
.fetch(self
.fetch_tasks
, observers
= self
.observers
, wait
= True)
70 print "fetch finished!"
72 class FeedUpdateResult(object):
73 def __init__(self
, error
, feed
, fetch_result
):
76 self
.fetch_result
= fetch_result
78 JobManager
.register_handler(FeedUpdateJobHandler
)
80 def update(feeds
, observers
):
81 update
= Job("feed-update")
83 update
.observers
= observers
84 return JobManager
.start(update
)