deluge/plugins/EventLogging/tab_log.py

235 lines
14 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
#
# tab_log.py
#
# Copyright (C) Marcos Pinto 2007 <markybob@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program 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 this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
import gtk
2007-08-01 21:47:05 +00:00
import os
import time
from deluge import common
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
self.logdir = os.path.join(common.CONFIG_DIR, 'logs')
2007-08-01 21:47:05 +00:00
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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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-09 06:43:26 +00:00
torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(common.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()
2007-08-05 05:09:03 +00:00
if event['event_type'] is self.manager.constants['EVENT_PEER_BLOCKED']:
event_message = _("Peer blocked") + " {" + _("event message: ") + event['message'] + ", "\
+ _("ip address: ") + event['ip'] + "}"
if self.log_files:
log = os.path.join(self.logdir, 'peer_blocked.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()