deluge/plugins/EventLogging/tab_log.py

196 lines
12 KiB
Python
Raw Normal View History

import gtk
2007-08-01 21:47:05 +00:00
import xdg.BaseDirectory
import os
import time
CONFIG_DIR = xdg.BaseDirectory.save_config_path('deluge')
class LogTabManager(object):
def __init__(self, viewport, manager):
2007-08-01 21:47:05 +00:00
self.log_files = False
self.viewport = viewport
self.vbox = None
self.manager = manager
2007-08-01 21:47:05 +00:00
self.logdir = os.path.join(CONFIG_DIR, 'logs')
if not os.path.isdir(self.logdir):
os.mkdir(self.logdir)
2007-08-04 08:35:31 +00:00
self.labels = []
def clear_log_store(self):
if not self.vbox is None:
self.vbox.destroy()
self.vbox = None
def build_log_view(self):
self.vbox = gtk.VBox()
self.viewport.add(self.vbox)
self.vbox.show_all()
2007-08-01 21:47:05 +00:00
def enable_log_files(self):
self.log_files = True
def disable_log_files(self):
self.log_files = False
def handle_event(self, event):
event_message = None
if event['event_type'] is self.manager.constants['EVENT_FINISHED']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Torrent finished") + " {"+ _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + "}"
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_PEER_ERROR']:
event_message = _("Peer message") + " {" + _("event message: ") + event['message'] + ", " + _("ip address: ")\
+ event['ip'] + ", " + _("client: ") + event['client_ID'] + "}"
2007-08-01 21:47:05 +00:00
if self.log_files:
log = os.path.join(self.logdir, 'peer_messages.log')
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_INVALID_REQUEST']:
event_message = _("Invalid request") + " {" + _("event message: ") + event['message'] + ", " + _("client: ")\
+ event['client_ID'] + "}"
2007-08-01 21:47:05 +00:00
if self.log_files:
log = os.path.join(self.logdir, 'invalid_requests.log')
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_FILE_ERROR']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("File error") + " {" + _("event message: ") + event['message'] + ", " + _("torrent: ")\
2007-08-01 21:47:05 +00:00
+ torrent + "}"
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_HASH_FAILED_ERROR']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Hash failed error") + " {" + _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + ", "\
+ _("piece index: ") + str(event['piece_index']) + "}"
2007-08-01 21:47:05 +00:00
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_PEER_BAN_ERROR']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Peer ban error") + " {" + _("event message: ") + event['message'] + ", " + _("ip address: ")\
2007-08-01 21:47:05 +00:00
+ event['ip'] + ", " + _("torrent: ") + torrent + "}"
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_FASTRESUME_REJECTED_ERROR']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Fastresume rejected error") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + "}"
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_TRACKER_ANNOUNCE']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Tracker announce") + " {" + _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + "}"
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_TRACKER_REPLY']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Tracker reply") + " {" + _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + "}"
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_TRACKER_ALERT']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Tracker alert") + " {" + _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + ", "\
+ _("status code: ") + str(event['status_code']) + ", " + _("Times in a row: ")\
+ str(event['times_in_row']) + "}"
2007-08-01 21:47:05 +00:00
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_TRACKER_WARNING']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Tracker warning") + " {" + _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + "}"
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_STORAGE_MOVED']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Storage moved") + " {" + _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + "}"
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_PIECE_FINISHED']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Piece finished") + " {" + _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + ", "\
+ _("piece index: ") + str(event['piece_index']) + "}"
2007-08-01 21:47:05 +00:00
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_BLOCK_DOWNLOADING']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Block downloading") + " {" + _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + ", "\
+ _("piece index: ") + str(event['piece_index']) + ", " + _("block index: ")\
+ str(event['block_index']) + ", " + _("peer speed: ") + event['peer_speed'] + "}"
2007-08-01 21:47:05 +00:00
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_BLOCK_FINISHED']:
2007-08-01 21:47:05 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '')
event_message = _("Block finished") + " {" + _("event message: ") + event['message'] + ", "\
2007-08-01 21:47:05 +00:00
+ _("torrent: ") + torrent + ", "\
+ _("piece index: ") + str(event['piece_index']) + ", " + _("block index: ")\
+ str(event['block_index']) + "}"
2007-08-01 21:47:05 +00:00
if self.log_files:
log = os.path.join(self.logdir, torrent.replace('.torrent', '.log'))
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if event['event_type'] is self.manager.constants['EVENT_OTHER']:
event_message = _("Other") + " {" + _("event message: ") + event['message'] + "}"
2007-08-01 21:47:05 +00:00
if self.log_files:
log = os.path.join(self.logdir, 'other.log')
logfile = open(log, "a")
logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n')
logfile.close()
if not event_message is None:
label = gtk.Label()
2007-08-04 08:35:31 +00:00
self.labels.append(label)
label.set_text(event_message)
label.set_alignment(0,0)
label.set_selectable(True)
2007-08-04 08:35:31 +00:00
self.vbox.pack_end(label, expand=False)
if len(self.labels)>100:
remove_label = self.labels.pop(0)
remove_label.destroy()
label.show()