Cleaned up core.handle_events(self).

This commit is contained in:
Alex Dedul 2007-07-14 08:04:52 +00:00
parent 8ba55e4dfa
commit 76c8792ce4

View File

@ -510,45 +510,40 @@ class Manager:
# Handle them for the backend's purposes, but still send them up in case the client # Handle them for the backend's purposes, but still send them up in case the client
# wants to do something - show messages, for example # wants to do something - show messages, for example
def pop_event(): def pop_event():
try:
return deluge_core.pop_event()
except:
pass
else:
return deluge_core.pop_event()
ret = []
try: try:
event = deluge_core.pop_event() event = deluge_core.pop_event()
except: except:
pass return None
else: else:
while event is not None: return event
ret = []
while True:
event = pop_event()
if event is None:
break
print "EVENT: ", event print "EVENT: ", event
ret.append(event) ret.append(event)
try:
if event['unique_ID'] not in self.unique_IDs: if 'unique_ID' in event and \
event = pop_event() event['unique_ID'] not in self.unique_IDs:
continue
except KeyError:
event = pop_event()
continue continue
# Call event callbacks # Call plugins events callbacks
if event['event_type'] in self.event_callbacks: if event['event_type'] in self.event_callbacks:
for plugin_instance in self.event_callbacks[event['event_type']]: for plugin_instance in self.event_callbacks[event['event_type']]:
plugin_instance.handle_event(event) plugin_instance.handle_event(event)
if event['event_type'] is self.constants['EVENT_STORAGE_MOVED']: if event['event_type'] is self.constants['EVENT_STORAGE_MOVED']:
if event['message'] == "move_failed": if event['message'] == "move_failed":
raise StorageMoveFailed(_("You cannot move torrent to a different partition. Please fix your preferences")) raise StorageMoveFailed(_("You cannot move torrent to a different partition. Please fix your preferences"))
elif event['message'] == "move_success": elif event['message'] == "move_success":
self.unique_IDs[event['unique_ID']].save_dir = self.get_pref('default_finished_path') self.unique_IDs[event['unique_ID']].save_dir = self.get_pref('default_finished_path')
elif event['event_type'] is self.constants['EVENT_FINISHED']:
if event['event_type'] is self.constants['EVENT_FINISHED']:
# Queue seeding torrent to bottom if needed # Queue seeding torrent to bottom if needed
if(self.get_pref('enable_move_completed')): if self.get_pref('enable_move_completed'):
deluge_core.move_storage(event['unique_ID'], self.get_pref('default_finished_path')) deluge_core.move_storage(event['unique_ID'], self.get_pref('default_finished_path'))
if self.get_pref('queue_seeds_to_bottom'): if self.get_pref('queue_seeds_to_bottom'):
self.queue_bottom(event['unique_ID']) self.queue_bottom(event['unique_ID'])
@ -563,8 +558,7 @@ class Manager:
message = event['message'] message = event['message']
tracker = message[message.find('"')+1:message.rfind('"')] tracker = message[message.find('"')+1:message.rfind('"')]
self.set_supp_torrent_state_val(unique_ID, self.set_supp_torrent_state_val(unique_ID, "tracker_status",
"tracker_status",
(tracker, status)) (tracker, status))
old_state = self.get_supp_torrent_state(unique_ID) old_state = self.get_supp_torrent_state(unique_ID)
@ -575,12 +569,9 @@ class Manager:
new[tracker] = message new[tracker] = message
self.set_supp_torrent_state_val(unique_ID, self.set_supp_torrent_state_val(unique_ID, "tracker_messages",
"tracker_messages",
new) new)
event = pop_event()
return ret return ret
# Filtering functions # Filtering functions