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
, JobHandler
30 class FeedUpdateJobHandler(JobHandler
):
31 job_id
= "feed-update"
34 "update-started" : (gobject
.SIGNAL_RUN_LAST
, gobject
.TYPE_NONE
, (gobject
.TYPE_PYOBJECT
,)),
35 "update-done" : (gobject
.SIGNAL_RUN_LAST
, gobject
.TYPE_NONE
, (gobject
.TYPE_PYOBJECT
,))
38 def __init__(self
, id, job
):
39 JobHandler
.__init
__(self
, id, job
)
41 def _on_fetch_started(self
, handler
, task
):
42 self
._notify
("update-started", task
.user_data
)
44 def _on_url_fetched(self
, handler
, fetch_result
):
45 feed
= fetch_result
.task
.user_data
48 if fetch_result
.result
.error
:
49 update_result
= FeedUpdateResult("fetch-error", feed
, fetch_result
= fetch_result
.result
)
52 feed
= SummaryParser
.parse(fetch_result
.result
.content
, feed
)
53 update_result
= FeedUpdateResult(None, feed
, fetch_result
= fetch_result
.result
)
55 update_result
= FeedUpdateResult("parse-error", feed
,
56 fetch_result
= fetch_result
.result
, parse_error
= e
)
58 self
._notify
("update-done", update_result
)
60 def _on_fetch_done(self
, handler
, data
):
66 for feed
in self
.job
.tasks
:
69 if feed
.pdict
.has_key("username"):
70 credentials
= feed
.pdict
["username"], feed
.pdict
["password"], ""
72 task
= Fetcher
.create_task(url
= feed
.location
, credentials
= credentials
, user_data
= feed
)
74 self
.fetch_tasks
.append(task
)
76 self
.observers
= [{ "task-done": [ self
._on
_url
_fetched
],
77 "task-start": [ self
._on
_fetch
_started
],
78 "job-done": [ self
._on
_fetch
_done
]}]
81 self
.fetcher_id
= Fetcher
.fetch(self
.fetch_tasks
, observers
= self
.observers
, wait
= True)
83 class FeedUpdateResult(object):
84 def __init__(self
, error
, feed
, fetch_result
= None, parse_error
= None):
87 self
.fetch_result
= fetch_result
89 JobManager
.register_handler(FeedUpdateJobHandler
)
91 def update(feeds
, observers
):
92 update
= Job("feed-update")
94 update
.observers
= observers
95 return JobManager
.start(update
)