Author: andar
Revision: 5095
Log:
Add event logging
Diff:
Modified: trunk/deluge/ui/console/colors.py
===================================================================
--- trunk/deluge/ui/console/colors.py 2009-04-19 19:55:40 UTC (rev 5094)
+++ trunk/deluge/ui/console/colors.py 2009-04-19 19:57:06 UTC (rev 5095)
@@ -46,7 +46,8 @@
"status": ("yellow", "blue", "bold"),
"info": ("white", "black", "bold"),
"error": ("red", "black", "bold"),
- "success": ("green", "black", "bold")
+ "success": ("green", "black", "bold"),
+ "event": ("magenta", "black", "bold")
}
Added: trunk/deluge/ui/console/eventlog.py
===================================================================
--- trunk/deluge/ui/console/eventlog.py (rev 0)
+++ trunk/deluge/ui/console/eventlog.py 2009-04-19 19:57:06 UTC (rev 5095)
@@ -0,0 +1,95 @@
+#
+# eventlog.py
+#
+# Copyright (C) 2009 Andrew Resch <[email protected]>
+#
+# Deluge is free software.
+#
+# You may redistribute it and/or modify it under the terms of the
+# GNU General Public License, as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option)
+# any later version.
+#
+# deluge is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with deluge. If not, write to:
+# The Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor
+# Boston, MA 02110-1301, USA.
+#
+
+
+import deluge.component as component
+import deluge.common
+from deluge.ui.client import client
+
+from deluge.log import LOG as log
+
+class EventLog(component.Component):
+ """
+ Prints out certain events as they are received from the core.
+ """
+ def __init__(self):
+ component.Component.__init__(self, "EventLog")
+ self.console = component.get("ConsoleUI")
+
+ client.register_event_handler("TorrentAddedEvent",
self.on_torrent_added_event)
+ client.register_event_handler("PreTorrentRemovedEvent",
self.on_torrent_removed_event)
+ client.register_event_handler("TorrentStateChangedEvent",
self.on_torrent_state_changed_event)
+ client.register_event_handler("TorrentFinishedEvent",
self.on_torrent_finished_event)
+ client.register_event_handler("NewVersionAvailableEvent",
self.on_new_version_available_event)
+ client.register_event_handler("SessionPausedEvent",
self.on_session_paused_event)
+ client.register_event_handler("SessionResumedEvent",
self.on_session_resumed_event)
+ client.register_event_handler("ConfigValueChangedEvent",
self.on_config_value_changed_event)
+
+ def on_torrent_added_event(self, torrent_id):
+ def on_torrent_status(status):
+ self.console.write("{{event}}* TorrentAdded: {{info}}%s (%s)" %
(status["name"], torrent_id))
+ client.core.get_torrent_status(torrent_id,
["name"]).addCallback(on_torrent_status)
+
+ def on_torrent_removed_event(self, torrent_id):
+ self.console.write("{{event}}* TorrentRemovedEvent: {{info}}%s (%s)" %
+ (self.console.get_torrent_name(torrent_id), torrent_id))
+
+ def on_torrent_state_changed_event(self, torrent_id, state):
+ log.debug("on_torrent_state_changed_event!")
+ # Modify the state string color
+ state_color = {
+ "Seeding": "{{blue,black,bold}}",
+ "Downloading": "{{green,black,bold}}",
+ "Paused": "{{white,black}}",
+ "Checking": "{{green,black}}",
+ "Queued": "{{yellow,black}}",
+ "Error": "{{red,black,bold}}"
+ }
+ if state in state_color:
+ state = state_color[state] + state
+
+ self.console.write("{{event}}* TorrentStateChanged: %s {{info}}%s
(%s)" %
+ (state, self.console.get_torrent_name(torrent_id), torrent_id))
+
+ def on_torrent_paused_event(self, torrent_id):
+ self.console.write("{{event}}* TorrentPaused: {{info}}%s (%s)" %
+ (self.console.get_torrent_name(torrent_id), torrent_id))
+
+ def on_torrent_finished_event(self, torrent_id):
+ self.console.write("{{event}}* TorrentFinished: {{info}}%s (%s)" %
+ (self.console.get_torrent_name(torrent_id), torrent_id))
+
+ def on_new_version_available_event(self, version):
+ self.console.write("{{event}}* NewVersionAvailable: {{info}}%s" %
+ (version))
+
+ def on_session_paused_event(self):
+ self.console.write("{{event}}* SessionPaused")
+
+ def on_session_resumed_event(self):
+ self.console.write("{{event}}* SessionResumed")
+
+ def on_config_value_changed_event(self, key, value):
+ self.console.write("{{event}}* ConfigValueChanged: %s: %s" %
+ (key, value))
Modified: trunk/deluge/ui/console/main.py
===================================================================
--- trunk/deluge/ui/console/main.py 2009-04-19 19:55:40 UTC (rev 5094)
+++ trunk/deluge/ui/console/main.py 2009-04-19 19:57:06 UTC (rev 5095)
@@ -26,12 +26,12 @@
import os, sys
import optparse
from deluge.ui.console import UI_PATH
-#from deluge.ui.console.colors import Template, make_style, templates,
default_style as style
import deluge.component as component
from deluge.ui.client import client
import deluge.common
from deluge.ui.coreconfig import CoreConfig
from deluge.ui.console.statusbars import StatusBars
+from deluge.ui.console.eventlog import EventLog
from twisted.internet import defer, reactor
import shlex
@@ -163,6 +163,7 @@
colors.init_colors()
self.screen = screen.Screen(stdscr, self.do_command,
self.tab_completer)
self.statusbars = StatusBars()
+ self.eventlog = EventLog()
self.screen.topbar = "{{status}}Deluge " + deluge.common.get_version()
+ " Console"
self.screen.bottombar = "{{status}}"
@@ -314,6 +315,21 @@
self.write(cmd)
return (line, cursor)
+ def get_torrent_name(self, torrent_id):
+ """
+ Gets a torrent name from the torrents list.
+
+ :param torrent_id: str, the torrent_id
+
+ :returns: the name of the torrent or None
+ """
+
+ for tid, name in self.torrents:
+ if torrent_id == tid:
+ return name
+
+ return None
+
def on_torrent_added_event(self, torrent_id):
def on_torrent_status(status):
self.torrents.append(torrent_id, status["name"])
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---