Flake8 core and common files

* Added N802 to flake8 ignore as certain inherited funcs cannot be changed
   to lowercase and this unresolved warning hides other errors/warnings.
 * Include new header
This commit is contained in:
Calum Lind 2014-09-03 22:28:28 +01:00
parent 5d88504c34
commit 5167e93d12
44 changed files with 636 additions and 1277 deletions

View File

@ -1,3 +1,12 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#
from new import classobj from new import classobj
from deluge.core.core import Core from deluge.core.core import Core
@ -7,6 +16,7 @@ from deluge.core.daemon import Daemon
class RpcApi: class RpcApi:
pass pass
def scan_for_methods(obj): def scan_for_methods(obj):
methods = { methods = {
'__doc__': 'Methods available in %s' % obj.__name__.lower() '__doc__': 'Methods available in %s' % obj.__name__.lower()

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# _libtorrent.py
# #
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #
""" """
@ -47,6 +21,7 @@ supports.
REQUIRED_VERSION = "0.16.7.0" REQUIRED_VERSION = "0.16.7.0"
def check_version(lt): def check_version(lt):
from deluge.common import VersionSplit from deluge.common import VersionSplit
if VersionSplit(lt.version) < VersionSplit(REQUIRED_VERSION): if VersionSplit(lt.version) < VersionSplit(REQUIRED_VERSION):

View File

@ -183,7 +183,7 @@ def resource_filename(module, path):
# enough. # enough.
# This is a work-around that. # This is a work-around that.
return pkg_resources.require("Deluge>=%s" % get_version())[0].get_resource_filename( return pkg_resources.require("Deluge>=%s" % get_version())[0].get_resource_filename(
pkg_resources._manager, os.path.join(*(module.split('.')+[path])) pkg_resources._manager, os.path.join(*(module.split(".") + [path]))
) )

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# component.py
# #
# Copyright (C) 2007-2010 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007-2010 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 logging import logging
@ -41,9 +15,11 @@ from twisted.internet.task import LoopingCall
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class ComponentAlreadyRegistered(Exception): class ComponentAlreadyRegistered(Exception):
pass pass
class Component(object): class Component(object):
""" """
Component objects are singletons managed by the :class:`ComponentRegistry`. Component objects are singletons managed by the :class:`ComponentRegistry`.
@ -219,6 +195,7 @@ class Component(object):
def shutdown(self): def shutdown(self):
pass pass
class ComponentRegistry(object): class ComponentRegistry(object):
""" """
The ComponentRegistry holds a list of currently registered The ComponentRegistry holds a list of currently registered
@ -264,6 +241,7 @@ class ComponentRegistry(object):
if obj in self.components.values(): if obj in self.components.values():
log.debug("Deregistering Component: %s", obj._component_name) log.debug("Deregistering Component: %s", obj._component_name)
d = self.stop([obj._component_name]) d = self.stop([obj._component_name])
def on_stop(result, name): def on_stop(result, name):
del self.components[name] del self.components[name]
return d.addCallback(on_stop, obj._component_name) return d.addCallback(on_stop, obj._component_name)
@ -430,6 +408,7 @@ resume = _ComponentRegistry.resume
update = _ComponentRegistry.update update = _ComponentRegistry.update
shutdown = _ComponentRegistry.shutdown shutdown = _ComponentRegistry.shutdown
def get(name): def get(name):
""" """
Return a reference to a component. Return a reference to a component.

View File

@ -1,38 +1,11 @@
# # -*- coding: utf-8 -*-
# config.py
# #
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
# #
# 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.
#
# 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.
#
#
""" """
Deluge Config Module Deluge Config Module
@ -208,7 +181,7 @@ what is currently in the config and it could not convert the value
# Do not allow the type to change unless it is None # Do not allow the type to change unless it is None
oldtype, newtype = type(self.__config[key]), type(value) oldtype, newtype = type(self.__config[key]), type(value)
if value is not None and oldtype != type(None) and oldtype != newtype: if value is not None and not isinstance(oldtype, type(None)) and not isinstance(oldtype, newtype):
try: try:
if oldtype == unicode: if oldtype == unicode:
value = oldtype(value, "utf8") value = oldtype(value, "utf8")
@ -542,7 +515,7 @@ what is currently in the config and it could not convert the value
log.exception(ex) log.exception(ex)
log.error("There was an exception try to convert config file %s %s to %s", log.error("There was an exception try to convert config file %s %s to %s",
self.__config_file, self.__version["file"], output_version) self.__config_file, self.__version["file"], output_version)
raise e raise ex
else: else:
self.__version["file"] = output_version self.__version["file"] = output_version
self.save() self.save()

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# configmanager.py
# #
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 logging import logging
@ -42,6 +16,7 @@ from deluge.config import Config
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class _ConfigManager: class _ConfigManager:
def __init__(self): def __init__(self):
log.debug("ConfigManager started..") log.debug("ConfigManager started..")
@ -121,18 +96,22 @@ class _ConfigManager:
# Singleton functions # Singleton functions
_configmanager = _ConfigManager() _configmanager = _ConfigManager()
def ConfigManager(config, defaults=None): def ConfigManager(config, defaults=None):
return _configmanager.get_config(config, defaults) return _configmanager.get_config(config, defaults)
def set_config_dir(directory): def set_config_dir(directory):
"""Sets the config directory, else just uses default""" """Sets the config directory, else just uses default"""
return _configmanager.set_config_dir(directory) return _configmanager.set_config_dir(directory)
def get_config_dir(filename=None): def get_config_dir(filename=None):
if filename != None: if filename is not None:
return os.path.join(_configmanager.get_config_dir(), filename) return os.path.join(_configmanager.get_config_dir(), filename)
else: else:
return _configmanager.get_config_dir() return _configmanager.get_config_dir()
def close(config): def close(config):
return _configmanager.close(config) return _configmanager.close(config)

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# decorators.py
# #
# Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com> # Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #
from functools import wraps from functools import wraps

View File

@ -1,37 +1,11 @@
# # -*- coding: utf-8 -*-
# error.py
# #
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me> # Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# event.py
# #
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #
""" """
@ -48,10 +22,10 @@ class DelugeEventMetaClass(type):
""" """
This metaclass simply keeps a list of all events classes created. This metaclass simply keeps a list of all events classes created.
""" """
def __init__(cls, name, bases, dct): def __init__(self, name, bases, dct):
super(DelugeEventMetaClass, cls).__init__(name, bases, dct) super(DelugeEventMetaClass, self).__init__(name, bases, dct)
if name != "DelugeEvent": if name != "DelugeEvent":
known_events[name] = cls known_events[name] = self
class DelugeEvent(object): class DelugeEvent(object):

View File

@ -1,35 +1,10 @@
# # -*- coding: utf-8 -*-
# httpdownloader.py
# #
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 logging import logging
@ -45,6 +20,7 @@ from common import get_version
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class HTTPDownloader(client.HTTPDownloader): class HTTPDownloader(client.HTTPDownloader):
""" """
Factory class for downloading files and keeping track of progress. Factory class for downloading files and keeping track of progress.
@ -132,6 +108,7 @@ class HTTPDownloader(client.HTTPDownloader):
return client.HTTPDownloader.pageEnd(self) return client.HTTPDownloader.pageEnd(self)
def sanitise_filename(filename): def sanitise_filename(filename):
""" """
Sanitises a filename to use as a download destination file. Sanitises a filename to use as a download destination file.
@ -159,8 +136,8 @@ def sanitise_filename(filename):
return filename return filename
def download_file(url, filename, callback=None, headers=None,
force_filename=False, allow_compression=True): def download_file(url, filename, callback=None, headers=None, force_filename=False, allow_compression=True):
""" """
Downloads a file from a specific URL and returns a Deferred. You can also Downloads a file from a specific URL and returns a Deferred. You can also
specify a callback function to be called as parts are received. specify a callback function to be called as parts are received.
@ -207,7 +184,6 @@ def download_file(url, filename, callback=None, headers=None,
scheme = uri.scheme scheme = uri.scheme
host = uri.host host = uri.host
port = uri.port port = uri.port
path = uri.path
factory = HTTPDownloader(url, filename, callback, headers, force_filename, allow_compression) factory = HTTPDownloader(url, filename, callback, headers, force_filename, allow_compression)
if scheme == "https": if scheme == "https":

View File

@ -1,37 +1,11 @@
# # -*- coding: utf-8 -*-
# log.py
# #
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2010 Pedro Algarvio <pedro@algarvio.me> # Copyright (C) 2010 Pedro Algarvio <pedro@algarvio.me>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #
"""Logging functions""" """Logging functions"""
@ -49,12 +23,13 @@ __all__ = ["setupLogger", "setLoggerLevel", "getPluginLogger", "LOG"]
LoggingLoggerClass = logging.getLoggerClass() LoggingLoggerClass = logging.getLoggerClass()
if 'dev' in common.get_version(): if "dev" in common.get_version():
DEFAULT_LOGGING_FORMAT = "%%(asctime)s.%%(msecs)03.0f [%%(levelname)-8s][%%(name)-%ds:%%(lineno)-4d] %%(message)s" DEFAULT_LOGGING_FORMAT = "%%(asctime)s.%%(msecs)03.0f [%%(levelname)-8s][%%(name)-%ds:%%(lineno)-4d] %%(message)s"
else: else:
DEFAULT_LOGGING_FORMAT = "%%(asctime)s [%%(levelname)-8s][%%(name)-%ds] %%(message)s" DEFAULT_LOGGING_FORMAT = "%%(asctime)s [%%(levelname)-8s][%%(name)-%ds] %%(message)s"
MAX_LOGGER_NAME_LENGTH = 10 MAX_LOGGER_NAME_LENGTH = 10
class Logging(LoggingLoggerClass): class Logging(LoggingLoggerClass):
def __init__(self, logger_name): def __init__(self, logger_name):
LoggingLoggerClass.__init__(self, logger_name) LoggingLoggerClass.__init__(self, logger_name)
@ -110,8 +85,8 @@ class Logging(LoggingLoggerClass):
while hasattr(f, "f_code"): while hasattr(f, "f_code"):
co = f.f_code co = f.f_code
filename = os.path.normcase(co.co_filename) filename = os.path.normcase(co.co_filename)
if filename in (__file__.replace('.pyc', '.py'), if filename in (__file__.replace(".pyc", ".py"),
defer.__file__.replace('.pyc', '.py')): defer.__file__.replace(".pyc", ".py")):
f = f.f_back f = f.f_back
continue continue
rv = (filename, f.f_lineno, co.co_name) rv = (filename, f.f_lineno, co.co_name)
@ -143,27 +118,27 @@ def setupLogger(level="error", filename=None, filemode="w"):
if logging.getLoggerClass() is not Logging: if logging.getLoggerClass() is not Logging:
logging.setLoggerClass(Logging) logging.setLoggerClass(Logging)
logging.addLevelName(5, 'TRACE') logging.addLevelName(5, "TRACE")
logging.addLevelName(1, 'GARBAGE') logging.addLevelName(1, "GARBAGE")
level = levels.get(level, logging.ERROR) level = levels.get(level, logging.ERROR)
rootLogger = logging.getLogger() root_logger = logging.getLogger()
if filename and filemode=='a': if filename and filemode == "a":
import logging.handlers import logging.handlers
handler = logging.handlers.RotatingFileHandler( handler = logging.handlers.RotatingFileHandler(
filename, filemode, filename, filemode,
maxBytes=50 * 1024 * 1024, # 50 Mb maxBytes=50 * 1024 * 1024, # 50 Mb
backupCount=3, backupCount=3,
encoding='utf-8', encoding="utf-8",
delay=0 delay=0
) )
elif filename and filemode=='w': elif filename and filemode == "w":
import logging.handlers import logging.handlers
handler = getattr( handler = getattr(
logging.handlers, 'WatchedFileHandler', logging.FileHandler)( logging.handlers, "WatchedFileHandler", logging.FileHandler)(
filename, filemode, 'utf-8', delay=0 filename, filemode, "utf-8", delay=0
) )
else: else:
handler = logging.StreamHandler() handler = logging.StreamHandler()
@ -176,13 +151,14 @@ def setupLogger(level="error", filename=None, filemode="w"):
) )
handler.setFormatter(formatter) handler.setFormatter(formatter)
rootLogger.addHandler(handler) root_logger.addHandler(handler)
rootLogger.setLevel(level) root_logger.setLevel(level)
twisted_logging = PythonLoggingObserver('twisted') twisted_logging = PythonLoggingObserver("twisted")
twisted_logging.start() twisted_logging.start()
logging.getLogger("twisted").setLevel(level) logging.getLogger("twisted").setLevel(level)
def tweak_logging_levels(): def tweak_logging_levels():
"""This function allows tweaking the logging levels for all or some loggers. """This function allows tweaking the logging levels for all or some loggers.
This is mostly usefull for developing purposes hence the contents of the This is mostly usefull for developing purposes hence the contents of the
@ -202,17 +178,16 @@ def tweak_logging_levels():
the command line. the command line.
""" """
from deluge import configmanager from deluge import configmanager
logging_config_file = os.path.join(configmanager.get_config_dir(), logging_config_file = os.path.join(configmanager.get_config_dir(), "logging.conf")
'logging.conf')
if not os.path.isfile(logging_config_file): if not os.path.isfile(logging_config_file):
return return
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.warn("logging.conf found! tweaking logging levels from %s", log.warn("logging.conf found! tweaking logging levels from %s",
logging_config_file) logging_config_file)
for line in open(logging_config_file, 'r').readlines(): for line in open(logging_config_file, "r").readlines():
if line.strip().startswith("#"): if line.strip().startswith("#"):
continue continue
name, level = line.strip().split(':') name, level = line.strip().split(":")
if level not in levels: if level not in levels:
continue continue
@ -240,12 +215,12 @@ def getPluginLogger(logger_name):
module_stack = stack.pop(0) # The module that called the log function module_stack = stack.pop(0) # The module that called the log function
caller_module = inspect.getmodule(module_stack[0]) caller_module = inspect.getmodule(module_stack[0])
# In some weird cases caller_module might be None, try to continue # In some weird cases caller_module might be None, try to continue
caller_module_name = getattr(caller_module, '__name__', '') caller_module_name = getattr(caller_module, "__name__", "")
warnings.warn_explicit(DEPRECATION_WARNING, DeprecationWarning, warnings.warn_explicit(DEPRECATION_WARNING, DeprecationWarning,
module_stack[1], module_stack[2], module_stack[1], module_stack[2],
caller_module_name) caller_module_name)
if 'deluge.plugins.' in logger_name: if "deluge.plugins." in logger_name:
return logging.getLogger(logger_name) return logging.getLogger(logger_name)
return logging.getLogger("deluge.plugin.%s" % logger_name) return logging.getLogger("deluge.plugin.%s" % logger_name)
@ -272,16 +247,17 @@ The above will result in, regarding the "Label" plugin for example a log message
Triggering code:""" Triggering code:"""
class __BackwardsCompatibleLOG(object):
class _BackwardsCompatibleLOG(object):
def __getattribute__(self, name): def __getattribute__(self, name):
import warnings import warnings
logger_name = 'deluge' logger_name = "deluge"
stack = inspect.stack() stack = inspect.stack()
stack.pop(0) # The logging call from this module stack.pop(0) # The logging call from this module
module_stack = stack.pop(0) # The module that called the log function module_stack = stack.pop(0) # The module that called the log function
caller_module = inspect.getmodule(module_stack[0]) caller_module = inspect.getmodule(module_stack[0])
# In some weird cases caller_module might be None, try to continue # In some weird cases caller_module might be None, try to continue
caller_module_name = getattr(caller_module, '__name__', '') caller_module_name = getattr(caller_module, "__name__", "")
warnings.warn_explicit(DEPRECATION_WARNING, DeprecationWarning, warnings.warn_explicit(DEPRECATION_WARNING, DeprecationWarning,
module_stack[1], module_stack[2], module_stack[1], module_stack[2],
caller_module_name) caller_module_name)
@ -290,9 +266,9 @@ class __BackwardsCompatibleLOG(object):
module = inspect.getmodule(member[0]) module = inspect.getmodule(member[0])
if not module: if not module:
continue continue
if module.__name__ in ('deluge.plugins.pluginbase', if module.__name__ in ("deluge.plugins.pluginbase",
'deluge.plugins.init'): "deluge.plugins.init"):
logger_name += '.plugin.%s' % caller_module_name logger_name += ".plugin.%s" % caller_module_name
# Monkey Patch The Plugin Module # Monkey Patch The Plugin Module
caller_module.log = logging.getLogger(logger_name) caller_module.log = logging.getLogger(logger_name)
break break
@ -303,4 +279,4 @@ class __BackwardsCompatibleLOG(object):
) )
return getattr(logging.getLogger(logger_name), name) return getattr(logging.getLogger(logger_name), name)
LOG = __BackwardsCompatibleLOG() LOG = _BackwardsCompatibleLOG()

View File

@ -1,37 +1,11 @@
# # -*- coding: utf-8 -*-
# main.py
# #
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2010 Pedro Algarvio <pedro@algarvio.me> # Copyright (C) 2010 Pedro Algarvio <pedro@algarvio.me>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #
@ -73,19 +47,19 @@ def start_ui():
help="""The UI that you wish to launch. The UI choices are:\n help="""The UI that you wish to launch. The UI choices are:\n
\t gtk -- A GTK-based graphical user interface (default)\n \t gtk -- A GTK-based graphical user interface (default)\n
\t web -- A web-based interface (http://localhost:8112)\n \t web -- A web-based interface (http://localhost:8112)\n
\t console -- A console or command-line interface""", action="store", type="str") \t console -- A console or command-line interface""")
parser.add_option("-s", "--set-default-ui", dest="default_ui", parser.add_option("-s", "--set-default-ui", dest="default_ui",
help="Sets the default UI to be run when no UI is specified", action="store", type="str") help="Sets the default UI to be run when no UI is specified")
parser.add_option("-a", "--args", dest="args", parser.add_option("-a", "--args", dest="args",
help="Arguments to pass to UI, -a '--option args'", action="store", type="str") help="Arguments to pass to UI, -a '--option args'")
parser.add_option("-c", "--config", dest="config", parser.add_option("-c", "--config", dest="config",
help="Set the config folder location", action="store", type="str") help="Set the config folder location")
parser.add_option("-l", "--logfile", dest="logfile", parser.add_option("-l", "--logfile", dest="logfile",
help="Output to designated logfile instead of stdout", action="store", type="str") help="Output to designated logfile instead of stdout")
parser.add_option("-L", "--loglevel", dest="loglevel", parser.add_option("-L", "--loglevel", dest="loglevel",
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str") help="Set the log level: none, info, warning, error, critical, debug")
parser.add_option("-q", "--quiet", dest="quiet", parser.add_option("-q", "--quiet", dest="quiet", action="store_true", default=False,
help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False) help="Sets the log level to 'none', this is the same as `-L none`")
parser.add_option("-r", "--rotate-logs", parser.add_option("-r", "--rotate-logs",
help="Rotate logfiles.", action="store_true", default=False) help="Rotate logfiles.", action="store_true", default=False)
@ -152,36 +126,27 @@ def start_daemon():
parser.add_option("-v", "--version", action="callback", callback=version_callback, parser.add_option("-v", "--version", action="callback", callback=version_callback,
help="Show program's version number and exit") help="Show program's version number and exit")
parser.add_option("-p", "--port", dest="port", parser.add_option("-p", "--port", dest="port",
help="Port daemon will listen on", action="store", type="int") help="Port daemon will listen on", type="int")
parser.add_option("-i", "--interface", dest="listen_interface", parser.add_option("-i", "--interface", dest="listen_interface",
help="Interface daemon will listen for bittorrent connections on, \ help="Interface daemon will listen for bittorrent connections on,"
this should be an IP address", metavar="IFACE", "this should be an IP address", metavar="IFACE")
action="store", type="str") parser.add_option("-u", "--ui-interface", dest="ui_interface", metavar="IFACE",
parser.add_option("-u", "--ui-interface", dest="ui_interface", help="Interface daemon will listen for UI connections on, this should be an IP address")
help="Interface daemon will listen for UI connections on, this should be\
an IP address", metavar="IFACE", action="store", type="str")
if not (deluge.common.windows_check() or deluge.common.osx_check()): if not (deluge.common.windows_check() or deluge.common.osx_check()):
parser.add_option("-d", "--do-not-daemonize", dest="donot", parser.add_option("-d", "--do-not-daemonize", dest="donot",
help="Do not daemonize", action="store_true", default=False) help="Do not daemonize", action="store_true", default=False)
parser.add_option("-c", "--config", dest="config", parser.add_option("-c", "--config", dest="config", help="Set the config location")
help="Set the config location", action="store", type="str") parser.add_option("-P", "--pidfile", dest="pidfile", help="Use pidfile to store process id")
parser.add_option("-P", "--pidfile", dest="pidfile",
help="Use pidfile to store process id", action="store", type="str")
if not deluge.common.windows_check(): if not deluge.common.windows_check():
parser.add_option("-U", "--user", dest="user", parser.add_option("-U", "--user", dest="user", help="User to switch to. Only use it when starting as root")
help="User to switch to. Only use it when starting as root", action="store", type="str") parser.add_option("-g", "--group", dest="group", help="Group to switch to. Only use it when starting as root")
parser.add_option("-g", "--group", dest="group", parser.add_option("-l", "--logfile", dest="logfile", help="Set the logfile location")
help="Group to switch to. Only use it when starting as root", action="store", type="str")
parser.add_option("-l", "--logfile", dest="logfile",
help="Set the logfile location", action="store", type="str")
parser.add_option("-L", "--loglevel", dest="loglevel", parser.add_option("-L", "--loglevel", dest="loglevel",
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str") help="Set the log level: none, info, warning, error, critical, debug")
parser.add_option("-q", "--quiet", dest="quiet", parser.add_option("-q", "--quiet", dest="quiet", action="store_true", default=False,
help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False) help="Sets the log level to 'none', this is the same as `-L none`")
parser.add_option("-r", "--rotate-logs", parser.add_option("-r", "--rotate-logs", help="Rotate logfiles.", action="store_true", default=False)
help="Rotate logfiles.", action="store_true", default=False) parser.add_option("--profile", dest="profile", action="store_true", default=False, help="Profiles the daemon")
parser.add_option("--profile", dest="profile", action="store_true", default=False,
help="Profiles the daemon")
# Get the options and args from the OptionParser # Get the options and args from the OptionParser
(options, args) = parser.parse_args() (options, args) = parser.parse_args()

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# maketorrent.py
# #
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 os import os
@ -47,6 +21,7 @@ class InvalidPath(Exception):
""" """
pass pass
class InvalidPieceSize(Exception): class InvalidPieceSize(Exception):
""" """
Raised when an invalid piece size is set. Piece sizes must be multiples of Raised when an invalid piece size is set. Piece sizes must be multiples of
@ -54,6 +29,7 @@ class InvalidPieceSize(Exception):
""" """
pass pass
class TorrentMetadata(object): class TorrentMetadata(object):
""" """
This class is used to create .torrent files. This class is used to create .torrent files.
@ -125,7 +101,7 @@ class TorrentMetadata(object):
datasize = get_path_size(self.data_path) datasize = get_path_size(self.data_path)
if self.piece_size: if self.piece_size:
piece_size = piece_size * 1024 piece_size = self.piece_size * 1024
else: else:
# We need to calculate a piece size # We need to calculate a piece size
piece_size = 16384 piece_size = 16384

View File

@ -38,15 +38,18 @@ for i in xrange(0xFDD0, 0xFDF0):
for i in (0xFFFE, 0xFFFF): for i in (0xFFFE, 0xFFFF):
noncharacter_translate[i] = ord('-') noncharacter_translate[i] = ord('-')
def gmtime(): def gmtime():
return time.mktime(time.gmtime()) return time.mktime(time.gmtime())
def get_filesystem_encoding(): def get_filesystem_encoding():
return sys.getfilesystemencoding() return sys.getfilesystemencoding()
def decode_from_filesystem(path): def decode_from_filesystem(path):
encoding = get_filesystem_encoding() encoding = get_filesystem_encoding()
if encoding == None: if encoding is None:
assert isinstance(path, unicode), "Path should be unicode not %s" % type(path) assert isinstance(path, unicode), "Path should be unicode not %s" % type(path)
decoded_path = path decoded_path = path
else: else:
@ -55,9 +58,11 @@ def decode_from_filesystem(path):
return decoded_path return decoded_path
def dummy(*v): def dummy(*v):
pass pass
class RemoteFileProgress(object): class RemoteFileProgress(object):
def __init__(self, session_id): def __init__(self, session_id):
self.session_id = session_id self.session_id = session_id
@ -67,6 +72,7 @@ class RemoteFileProgress(object):
self.session_id, CreateTorrentProgressEvent(piece_count, num_pieces) self.session_id, CreateTorrentProgressEvent(piece_count, num_pieces)
) )
def make_meta_file(path, url, piece_length, progress=None, title=None, comment=None, def make_meta_file(path, url, piece_length, progress=None, title=None, comment=None,
safe=None, content_type=None, target=None, webseeds=None, name=None, safe=None, content_type=None, target=None, webseeds=None, name=None,
private=False, created_by=None, trackers=None): private=False, created_by=None, trackers=None):
@ -127,15 +133,16 @@ def make_meta_file(path, url, piece_length, progress=None, title=None, comment=N
h.write(bencode(data)) h.write(bencode(data))
h.close() h.close()
def calcsize(path): def calcsize(path):
total = 0 total = 0
for s in subfiles(os.path.abspath(path)): for s in subfiles(os.path.abspath(path)):
total += os.path.getsize(s[1]) total += os.path.getsize(s[1])
return total return total
def makeinfo(path, piece_length, progress, name = None,
content_type = None, private=False): # HEREDAVE. If path is directory, def makeinfo(path, piece_length, progress, name=None, content_type=None, private=False):
# how do we assign content type? # HEREDAVE. If path is directory, how do we assign content type?
def to_utf8(name): def to_utf8(name):
if isinstance(name, unicode): if isinstance(name, unicode):
u = name u = name
@ -208,7 +215,8 @@ def makeinfo(path, piece_length, progress, name = None,
name = to_utf8(os.path.split(path)[1]) name = to_utf8(os.path.split(path)[1])
return {'pieces': ''.join(pieces), return {'pieces': ''.join(pieces),
'piece length': piece_length, 'files': fs, 'piece length': piece_length,
'files': fs,
'name': name, 'name': name,
'private': private} 'private': private}
else: else:
@ -241,6 +249,7 @@ def makeinfo(path, piece_length, progress, name = None,
'name': to_utf8(os.path.split(path)[1]), 'name': to_utf8(os.path.split(path)[1]),
'private': private} 'private': private}
def subfiles(d): def subfiles(d):
r = [] r = []
stack = [([], d)] stack = [([], d)]

View File

@ -1,37 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# path_chooser_common.py
#
# Copyright (C) 2013 Bro <bro.development@gmail.com> # Copyright (C) 2013 Bro <bro.development@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 os import os
@ -41,9 +15,11 @@ def get_resource(filename):
import deluge import deluge
return deluge.common.resource_filename("deluge.ui.gtkui", os.path.join("glade", filename)) return deluge.common.resource_filename("deluge.ui.gtkui", os.path.join("glade", filename))
def is_hidden(filepath): def is_hidden(filepath):
def has_hidden_attribute(filepath): def has_hidden_attribute(filepath):
import win32api, win32con import win32api
import win32con
try: try:
attribute = win32api.GetFileAttributes(filepath) attribute = win32api.GetFileAttributes(filepath)
return attribute & (win32con.FILE_ATTRIBUTE_HIDDEN | win32con.FILE_ATTRIBUTE_SYSTEM) return attribute & (win32con.FILE_ATTRIBUTE_HIDDEN | win32con.FILE_ATTRIBUTE_SYSTEM)
@ -56,6 +32,7 @@ def is_hidden(filepath):
return has_hidden_attribute(filepath) return has_hidden_attribute(filepath)
return name.startswith('.') return name.startswith('.')
def get_completion_paths(args): def get_completion_paths(args):
""" """
Takes a path value and returns the available completions. Takes a path value and returns the available completions.

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# pluginmanagerbase.py
# #
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #
@ -69,6 +43,7 @@ If you're the developer, please take a look at the plugins hosted on deluge's
git repository to have an idea of what needs to be changed. git repository to have an idea of what needs to be changed.
""" """
class PluginManagerBase: class PluginManagerBase:
"""PluginManagerBase is a base class for PluginManagers to inherit""" """PluginManagerBase is a base class for PluginManagers to inherit"""
@ -170,8 +145,7 @@ class PluginManagerBase:
plugin_name = plugin_name.replace("-", " ") plugin_name = plugin_name.replace("-", " ")
self.plugins[plugin_name] = instance self.plugins[plugin_name] = instance
if plugin_name not in self.config["enabled_plugins"]: if plugin_name not in self.config["enabled_plugins"]:
log.debug("Adding %s to enabled_plugins list in config", log.debug("Adding %s to enabled_plugins list in config", plugin_name)
plugin_name)
self.config["enabled_plugins"].append(plugin_name) self.config["enabled_plugins"].append(plugin_name)
log.info("Plugin %s enabled..", plugin_name) log.info("Plugin %s enabled..", plugin_name)

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# init.py
# #
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #
""" """
@ -40,8 +14,10 @@ import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class PluginInitBase(object): class PluginInitBase(object):
_plugin_cls = None _plugin_cls = None
def __init__(self, plugin_name): def __init__(self, plugin_name):
self.plugin = self._plugin_cls(plugin_name) self.plugin = self._plugin_cls(plugin_name)

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# pluginbase.py
# #
# Copyright (C) 2007-2010 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007-2010 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 logging import logging
@ -39,6 +13,7 @@ import deluge.component as component
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class PluginBase(component.Component): class PluginBase(component.Component):
update_interval = 1 update_interval = 1
@ -52,6 +27,7 @@ class PluginBase(component.Component):
def disable(self): def disable(self):
raise NotImplementedError("Need to define a disable method!") raise NotImplementedError("Need to define a disable method!")
class CorePluginBase(PluginBase): class CorePluginBase(PluginBase):
def __init__(self, plugin_name): def __init__(self, plugin_name):
super(CorePluginBase, self).__init__("CorePlugin." + plugin_name) super(CorePluginBase, self).__init__("CorePlugin." + plugin_name)
@ -62,11 +38,13 @@ class CorePluginBase(PluginBase):
def __del__(self): def __del__(self):
component.get("RPCServer").deregister_object(self) component.get("RPCServer").deregister_object(self)
class GtkPluginBase(PluginBase): class GtkPluginBase(PluginBase):
def __init__(self, plugin_name): def __init__(self, plugin_name):
super(GtkPluginBase, self).__init__("GtkPlugin." + plugin_name) super(GtkPluginBase, self).__init__("GtkPlugin." + plugin_name)
log.debug("GtkPlugin initialized..") log.debug("GtkPlugin initialized..")
class WebPluginBase(PluginBase): class WebPluginBase(PluginBase):
scripts = [] scripts = []

View File

@ -298,7 +298,6 @@ def loads(x, decode_utf8=False):
return r return r
def encode_int(x, r): def encode_int(x, r):
if 0 <= x < INT_POS_FIXED_COUNT: if 0 <= x < INT_POS_FIXED_COUNT:
r.append(chr(INT_POS_FIXED_START + x)) r.append(chr(INT_POS_FIXED_START + x))

View File

@ -367,8 +367,8 @@ new %(name)sPlugin();
""" """
GPL = """# GPL = """#
# %(filename)s # -*- coding: utf-8 -*-#
#
# Copyright (C) %(current_year)d %(author_name)s <%(author_email)s> # Copyright (C) %(current_year)d %(author_name)s <%(author_email)s>
# #
# Basic plugin template created by: # Basic plugin template created by:
@ -377,33 +377,9 @@ GPL = """#
# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com> # Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
# Copyright (C) 2010 Pedro Algarvio <pedro@algarvio.me> # Copyright (C) 2010 Pedro Algarvio <pedro@algarvio.me>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
# #
""" """
@ -415,7 +391,8 @@ pkg_resources.declare_namespace(__name__)
CREATE_DEV_LINK = """#!/bin/bash CREATE_DEV_LINK = """#!/bin/bash
BASEDIR=$(cd `dirname $0` && pwd) BASEDIR=$(cd `dirname $0` && pwd)
CONFIG_DIR=$( test -z $1 && echo "%(configdir)s" || echo "$1") CONFIG_DIR=$( test -z $1 && echo "%(configdir)s" || echo "$1")
[ -d "$CONFIG_DIR/plugins" ] || echo "Config dir \"$CONFIG_DIR\" is either not a directory or is not a proper deluge config directory. Exiting" [ -d "$CONFIG_DIR/plugins" ] || echo "Config dir \"$CONFIG_DIR\" is either not a directory \
or is not a proper deluge config directory. Exiting"
[ -d "$CONFIG_DIR/plugins" ] || exit 1 [ -d "$CONFIG_DIR/plugins" ] || exit 1
cd $BASEDIR cd $BASEDIR
test -d $BASEDIR/temp || mkdir $BASEDIR/temp test -d $BASEDIR/temp || mkdir $BASEDIR/temp

View File

@ -3,32 +3,9 @@
# #
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com> # Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
# #
# This program is free software; you can redistribute it and/or modify # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# it under the terms of the GNU General Public License as published by # the additional special exception to link portions of this program with the OpenSSL library.
# the Free Software Foundation; either version 3, or (at your option) # See LICENSE for more details.
# 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.
#
# #
# #
@ -51,8 +28,8 @@ print("\n\n")
if 0: # aclient non-core if 0: # aclient non-core
methods = sorted([m for m in dir(aclient) if not m.startswith('_') methods = sorted([m for m in dir(aclient) if not m.startswith('_')
if not m in ['add_torrent_file', 'has_callback', 'get_method', if not m in ['add_torrent_file', 'has_callback', 'get_method', 'methodHelp',
'methodHelp', 'methodSignature', 'list_methods', 'add_torrent_file_binary']]) 'methodSignature', 'list_methods', 'add_torrent_file_binary']])
for m in methods: for m in methods:
func = getattr(aclient, m) func = getattr(aclient, m)
@ -69,9 +46,7 @@ if 0: #aclient non-core
if 1: # baseclient/core if 1: # baseclient/core
methods = sorted([m for m in dir(Core) if m.startswith("export")] methods = sorted([m for m in dir(Core) if m.startswith("export")]
+ ['export_add_torrent_file_binary'] #HACK + ['export_add_torrent_file_binary']) # HACK
)
for m in methods: for m in methods:
@ -90,7 +65,6 @@ if 1: #baseclient/core
print("{{{\n%s\n}}}" % pydoc.getdoc(func)) print("{{{\n%s\n}}}" % pydoc.getdoc(func))
if 0: # plugin-manager if 0: # plugin-manager
import WebUi
from WebUi.pluginmanager import PluginManager from WebUi.pluginmanager import PluginManager
for m in methods: for m in methods:
@ -115,7 +89,4 @@ if 0: #keys
print("\n".join(textwrap.wrap(str(sorted(sclient.get_status_keys())), 100))) print("\n".join(textwrap.wrap(str(sorted(sclient.get_status_keys())), 100)))
print("""}}}""") print("""}}}""")
print("\n\n") print("\n\n")

View File

@ -88,6 +88,7 @@ class ClientTestCase(unittest.TestCase):
d = client.connect( d = client.connect(
"localhost", self.listen_port, username="", password="" "localhost", self.listen_port, username="", password=""
) )
def on_connect(result): def on_connect(result):
self.assertEqual(client.get_auth_level(), AUTH_LEVEL_ADMIN) self.assertEqual(client.get_auth_level(), AUTH_LEVEL_ADMIN)
self.addCleanup(client.disconnect) self.addCleanup(client.disconnect)

View File

@ -65,6 +65,7 @@ class TopLevelResource(Resource):
self.putChild("ubuntu-9.04-desktop-i386.iso.torrent", self.putChild("ubuntu-9.04-desktop-i386.iso.torrent",
File(common.rpath("ubuntu-9.04-desktop-i386.iso.torrent"))) File(common.rpath("ubuntu-9.04-desktop-i386.iso.torrent")))
class CoreTestCase(unittest.TestCase): class CoreTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
common.set_tmp_config_dir() common.set_tmp_config_dir()

View File

@ -1,41 +1,12 @@
# # -*- coding: utf-8 -*-
# test_rpcserver.py
# #
# Copyright (C) 2013 Bro <bro.development@gmail.com> # Copyright (C) 2013 Bro <bro.development@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 os
from twisted.python import log
from twisted.trial import unittest from twisted.trial import unittest
import deluge.component as component import deluge.component as component
@ -48,14 +19,15 @@ from deluge.ui.common import get_localhost_auth
setupLogger("none") setupLogger("none")
class DelugeRPCProtocolTester(DelugeRPCProtocol): class DelugeRPCProtocolTester(DelugeRPCProtocol):
messages = [] messages = []
def transfer_message(self, data): def transfer_message(self, data):
import traceback
self.messages.append(data) self.messages.append(data)
class RPCServerTestCase(unittest.TestCase): class RPCServerTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
@ -91,13 +63,7 @@ class RPCServerTestCase(unittest.TestCase):
self.assertEquals(msg[2], data, str(msg)) self.assertEquals(msg[2], data, str(msg))
def test_invalid_client_login(self): def test_invalid_client_login(self):
ret = self.protocol.dispatch(self.request_id, "daemon.login", [1], {}) self.protocol.dispatch(self.request_id, "daemon.login", [1], {})
msg = self.protocol.messages.pop()
self.assertEquals(msg[0], rpcserver.RPC_ERROR)
self.assertEquals(msg[1], self.request_id)
def test_invalid_client_login(self):
ret = self.protocol.dispatch(self.request_id, "daemon.login", [1], {})
msg = self.protocol.messages.pop() msg = self.protocol.messages.pop()
self.assertEquals(msg[0], rpcserver.RPC_ERROR) self.assertEquals(msg[0], rpcserver.RPC_ERROR)
self.assertEquals(msg[1], self.request_id) self.assertEquals(msg[1], self.request_id)
@ -105,7 +71,7 @@ class RPCServerTestCase(unittest.TestCase):
def test_valid_client_login(self): def test_valid_client_login(self):
self.authmanager = AuthManager() self.authmanager = AuthManager()
auth = get_localhost_auth() auth = get_localhost_auth()
ret = self.protocol.dispatch(self.request_id, "daemon.login", auth, {"client_version": "Test"}) self.protocol.dispatch(self.request_id, "daemon.login", auth, {"client_version": "Test"})
msg = self.protocol.messages.pop() msg = self.protocol.messages.pop()
self.assertEquals(msg[0], rpcserver.RPC_RESPONSE, str(msg)) self.assertEquals(msg[0], rpcserver.RPC_RESPONSE, str(msg))
self.assertEquals(msg[1], self.request_id, str(msg)) self.assertEquals(msg[1], self.request_id, str(msg))
@ -124,7 +90,7 @@ class RPCServerTestCase(unittest.TestCase):
self.assertEquals(msg[3][1], "AttributeError") self.assertEquals(msg[3][1], "AttributeError")
def test_daemon_info(self): def test_daemon_info(self):
ret = self.protocol.dispatch(self.request_id, "daemon.info", [], {}) self.protocol.dispatch(self.request_id, "daemon.info", [], {})
msg = self.protocol.messages.pop() msg = self.protocol.messages.pop()
self.assertEquals(msg[0], rpcserver.RPC_RESPONSE, str(msg)) self.assertEquals(msg[0], rpcserver.RPC_RESPONSE, str(msg))
self.assertEquals(msg[1], self.request_id, str(msg)) self.assertEquals(msg[1], self.request_id, str(msg))

View File

@ -1,36 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# test_transfer.py
#
# Copyright (C) 2012 Bro <bro.development@gmail.com> # Copyright (C) 2012 Bro <bro.development@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
# #
from __future__ import print_function from __future__ import print_function
@ -113,7 +87,7 @@ class TransferTestClass(DelugeTransferProtocol):
try: try:
request = rencode.loads(dobj.decompress(data)) request = rencode.loads(dobj.decompress(data))
print("Successfully loaded message", end=' ') print("Successfully loaded message", end=' ')
print(" - Buffer length: %d, data length: %d, unused length: %d" % \ print(" - Buffer length: %d, data length: %d, unused length: %d" %
(len(data), len(data) - len(dobj.unused_data), len(dobj.unused_data))) (len(data), len(data) - len(dobj.unused_data), len(dobj.unused_data)))
print("Packet count:", self.packet_count) print("Packet count:", self.packet_count)
except Exception as ex: except Exception as ex:
@ -286,7 +260,7 @@ class DelugeTransferProtocolTestCase(unittest.TestCase):
expected_msgs_received_count = 0 expected_msgs_received_count = 0
# Verify that the expected number of complete messages has arrived # Verify that the expected number of complete messages has arrived
if expected_msgs_received_count != len(self.transfer.get_messages_in()): if expected_msgs_received_count != len(self.transfer.get_messages_in()):
print("Expected number of messages received is %d, but %d have been received." % \ print("Expected number of messages received is %d, but %d have been received." %
(expected_msgs_received_count, len(self.transfer.get_messages_in()))) (expected_msgs_received_count, len(self.transfer.get_messages_in())))
# Get the data as received by DelugeTransferProtocol # Get the data as received by DelugeTransferProtocol

View File

@ -1,37 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# transfer.py
#
# Copyright (C) 2012 Bro <bro.development@gmail.com> # Copyright (C) 2012 Bro <bro.development@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #
try: try:
@ -49,6 +22,7 @@ log = logging.getLogger(__name__)
MESSAGE_HEADER_SIZE = 5 MESSAGE_HEADER_SIZE = 5
class DelugeTransferProtocol(Protocol): class DelugeTransferProtocol(Protocol):
""" """
Data messages are transfered using very a simple protocol. Data messages are transfered using very a simple protocol.

View File

@ -58,9 +58,7 @@ log = logging.getLogger(__name__)
class Win32IcoFile(object): class Win32IcoFile(object):
""" """Decoder for Microsoft .ico files."""
Decoder for Microsoft .ico files.
"""
def __init__(self, buf): def __init__(self, buf):
""" """
@ -76,53 +74,40 @@ class Win32IcoFile (object):
self.nb_items = header[2] self.nb_items = header[2]
dir_fields = ('width', 'height', 'nb_color', 'reserved', 'planes', 'bpp', dir_fields = ('width', 'height', 'nb_color', 'reserved', 'planes', 'bpp', 'size', 'offset')
'size', 'offset')
for i in xrange(self.nb_items): for i in xrange(self.nb_items):
directory = list(struct.unpack('<4B2H2I', buf.read(16))) directory = list(struct.unpack('<4B2H2I', buf.read(16)))
for j in xrange(3): for j in xrange(3):
if not directory[j]: if not directory[j]:
directory[j] = 256 directory[j] = 256
icon_header = dict(zip(dir_fields, directory)) icon_header = dict(zip(dir_fields, directory))
icon_header['color_depth'] = ( icon_header['color_depth'] = (icon_header['bpp'] or (icon_header['nb_color'] == 16 and 4))
icon_header['bpp'] or
(icon_header['nb_color'] == 16 and 4))
icon_header['dim'] = (icon_header['width'], icon_header['height']) icon_header['dim'] = (icon_header['width'], icon_header['height'])
self.entry.append(icon_header) self.entry.append(icon_header)
#end for (read headers) #end for (read headers)
# order by size and color depth # order by size and color depth
self.entry.sort(lambda x, y: \ self.entry.sort(lambda x, y: cmp(x['width'], y['width'])
cmp(x['width'], y['width']) or cmp(x['color_depth'], y['color_depth'])) or cmp(x['color_depth'], y['color_depth']))
self.entry.reverse() self.entry.reverse()
#end __init__
def sizes(self): def sizes(self):
""" """Get a list of all available icon sizes and color depths."""
Get a list of all available icon sizes and color depths.
"""
return set((h['width'], h['height']) for h in self.entry) return set((h['width'], h['height']) for h in self.entry)
#end sizes
def get_image(self, size, bpp=False): def get_image(self, size, bpp=False):
""" """Get an image from the icon
Get an image from the icon
Args: Args:
size: tuple of (width, height) size: tuple of (width, height)
bpp: color depth bpp: color depth
""" """
idx = 0
for i in range(self.nb_items): for i in range(self.nb_items):
h = self.entry[i] h = self.entry[i]
if size == h['dim'] and (bpp == False or bpp == h['color_depth']): if size == h['dim'] and (bpp is False or bpp == h['color_depth']):
return self.frame(i) return self.frame(i)
return self.frame(0) return self.frame(0)
#end get_image
def frame(self, idx): def frame(self, idx):
""" """
@ -145,8 +130,7 @@ class Win32IcoFile (object):
else: else:
# XOR + AND mask bmp frame # XOR + AND mask bmp frame
im = PIL.BmpImagePlugin.DibImageFile(self.buf) im = PIL.BmpImagePlugin.DibImageFile(self.buf)
log.debug("Loaded image: %s %s %s %s", im.format, im.mode, im.size, log.debug("Loaded image: %s %s %s %s", im.format, im.mode, im.size, im.info)
im.info)
# change tile dimension to only encompass XOR image # change tile dimension to only encompass XOR image
im.size = im.size[0], im.size[1] / 2 im.size = im.size[0], im.size[1] / 2
@ -196,17 +180,16 @@ class Win32IcoFile (object):
w += 32 - (im.size[0] % 32) w += 32 - (im.size[0] % 32)
# the total mask data is padded row size * height / bits per char # the total mask data is padded row size * height / bits per char
total_bytes = long((w * im.size[1]) / 8) total_bytes = long((w * im.size[1]) / 8)
log.debug("tot=%d, off=%d, w=%d, size=%d", log.debug("tot=%d, off=%d, w=%d, size=%d", len(data), and_mask_offset, w, total_bytes)
len(data), and_mask_offset, w, total_bytes)
self.buf.seek(and_mask_offset) self.buf.seek(and_mask_offset)
maskData = self.buf.read(total_bytes) mask_data = self.buf.read(total_bytes)
# convert raw data to image # convert raw data to image
mask = PIL.Image.frombuffer( mask = PIL.Image.frombuffer(
'1', # 1 bpp '1', # 1 bpp
im.size, # (w, h) im.size, # (w, h)
maskData, # source chars mask_data, # source chars
'raw', # raw decoder 'raw', # raw decoder
('1;I', int(w / 8), -1) # 1bpp inverted, padded, reversed ('1;I', int(w / 8), -1) # 1bpp inverted, padded, reversed
) )
@ -222,13 +205,11 @@ class Win32IcoFile (object):
return im return im
#end frame #end frame
def __repr__(self): def __repr__(self):
s = 'Microsoft Icon: %d images (max %dx%d %dbpp)' % ( s = 'Microsoft Icon: %d images (max %dx%d %dbpp)' % (
len(self.entry), self.entry[0]['width'], self.entry[0]['height'], len(self.entry), self.entry[0]['width'], self.entry[0]['height'],
self.entry[0]['bpp']) self.entry[0]['bpp'])
return s return s
#end __repr__
#end Win32IcoFile #end Win32IcoFile
@ -253,7 +234,6 @@ class Win32IconImageFile (PIL.ImageFile.ImageFile):
self.info['sizes'] = self.ico.sizes() self.info['sizes'] = self.ico.sizes()
self.size = self.ico.entry[0]['dim'] self.size = self.ico.entry[0]['dim']
self.load() self.load()
#end _open
def load(self): def load(self):
im = self.ico.get_image(self.size) im = self.ico.get_image(self.size)
@ -262,7 +242,6 @@ class Win32IconImageFile (PIL.ImageFile.ImageFile):
self.im = im.im self.im = im.im
self.mode = im.mode self.mode = im.mode
self.size = im.size self.size = im.size
#end load
#end class Win32IconImageFile #end class Win32IconImageFile

View File

@ -1,37 +1,11 @@
# # -*- coding: utf-8 -*-
# client.py
# #
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me> # Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 logging import logging
@ -43,7 +17,6 @@ from twisted.internet.protocol import ClientFactory
import deluge.common import deluge.common
from deluge import error from deluge import error
from deluge.event import known_events
from deluge.transfer import DelugeTransferProtocol from deluge.transfer import DelugeTransferProtocol
from deluge.ui.common import get_localhost_auth from deluge.ui.common import get_localhost_auth
@ -53,6 +26,7 @@ RPC_EVENT = 3
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def format_kwargs(kwargs): def format_kwargs(kwargs):
return ", ".join([key + "=" + str(value) for key, value in kwargs.items()]) return ", ".join([key + "=" + str(value) for key, value in kwargs.items()])
@ -91,10 +65,8 @@ class DelugeRPCRequest(object):
:returns: a properly formated RPCRequest :returns: a properly formated RPCRequest
""" """
if self.request_id is None or self.method is None or self.args is None \ if self.request_id is None or self.method is None or self.args is None or self.kwargs is None:
or self.kwargs is None: raise TypeError("You must set the properties of this object before calling format_message!")
raise TypeError("You must set the properties of this object "
"before calling format_message!")
return (self.request_id, self.method, self.args, self.kwargs) return (self.request_id, self.method, self.args, self.kwargs)
@ -156,7 +128,7 @@ class DelugeRPCProtocol(DelugeTransferProtocol):
try: try:
exception_cls = getattr(error, request[2]) exception_cls = getattr(error, request[2])
exception = exception_cls(*request[3], **request[4]) exception = exception_cls(*request[3], **request[4])
except TypeError as err: except TypeError:
log.warn("Received invalid RPC_ERROR (Old daemon?): %s", request[2]) log.warn("Received invalid RPC_ERROR (Old daemon?): %s", request[2])
return return
@ -189,7 +161,8 @@ class DelugeRPCProtocol(DelugeTransferProtocol):
log.debug(msg) log.debug(msg)
except: except:
import traceback import traceback
log.error("Failed to handle RPC_ERROR (Old daemon?): %s\nLocal error: %s", request[2], traceback.format_exc()) log.error("Failed to handle RPC_ERROR (Old daemon?): %s\nLocal error: %s",
request[2], traceback.format_exc())
d.errback(exception) d.errback(exception)
del self.__rpc_requests[request_id] del self.__rpc_requests[request_id]
@ -211,6 +184,7 @@ class DelugeRPCProtocol(DelugeTransferProtocol):
except Exception as ex: except Exception as ex:
log.warn("Error occurred when sending message: %s", ex) log.warn("Error occurred when sending message: %s", ex)
class DelugeRPCClientFactory(ClientFactory): class DelugeRPCClientFactory(ClientFactory):
protocol = DelugeRPCProtocol protocol = DelugeRPCProtocol
@ -240,9 +214,11 @@ class DelugeRPCClientFactory(ClientFactory):
if self.daemon.disconnect_callback: if self.daemon.disconnect_callback:
self.daemon.disconnect_callback() self.daemon.disconnect_callback()
class DaemonProxy(object): class DaemonProxy(object):
pass pass
class DaemonSSLProxy(DaemonProxy): class DaemonSSLProxy(DaemonProxy):
def __init__(self, event_handlers=None): def __init__(self, event_handlers=None):
if event_handlers is None: if event_handlers is None:
@ -445,6 +421,7 @@ class DaemonSSLProxy(DaemonProxy):
def get_bytes_sent(self): def get_bytes_sent(self):
return self.protocol.get_bytes_sent() return self.protocol.get_bytes_sent()
class DaemonClassicProxy(DaemonProxy): class DaemonClassicProxy(DaemonProxy):
def __init__(self, event_handlers=None): def __init__(self, event_handlers=None):
if event_handlers is None: if event_handlers is None:
@ -513,6 +490,7 @@ class DaemonClassicProxy(DaemonProxy):
""" """
self.__daemon.core.eventmanager.deregister_event_handler(event, handler) self.__daemon.core.eventmanager.deregister_event_handler(event, handler)
class DottedObject(object): class DottedObject(object):
""" """
This is used for dotted name calls to client This is used for dotted name calls to client
@ -527,6 +505,7 @@ class DottedObject(object):
def __getattr__(self, name): def __getattr__(self, name):
return RemoteMethod(self.daemon, self.base + "." + name) return RemoteMethod(self.daemon, self.base + "." + name)
class RemoteMethod(DottedObject): class RemoteMethod(DottedObject):
""" """
This is used when something like 'client.core.get_something()' is attempted. This is used when something like 'client.core.get_something()' is attempted.
@ -534,6 +513,7 @@ class RemoteMethod(DottedObject):
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
return self.daemon.call(self.base, *args, **kwargs) return self.daemon.call(self.base, *args, **kwargs)
class Client(object): class Client(object):
""" """
This class is used to connect to a daemon process and issue RPC requests. This class is used to connect to a daemon process and issue RPC requests.
@ -650,7 +630,7 @@ class Client(object):
that you forgot to install the deluged package or it's not in your PATH.")) that you forgot to install the deluged package or it's not in your PATH."))
else: else:
log.exception(ex) log.exception(ex)
raise e raise ex
except Exception as ex: except Exception as ex:
log.error("Unable to start daemon!") log.error("Unable to start daemon!")
log.exception(ex) log.exception(ex)
@ -665,8 +645,8 @@ that you forgot to install the deluged package or it's not in your PATH."))
:returns: bool, True if connected to a localhost :returns: bool, True if connected to a localhost
""" """
if self._daemon_proxy and self._daemon_proxy.host in ("127.0.0.1", "localhost") or\ if (self._daemon_proxy and self._daemon_proxy.host in ("127.0.0.1", "localhost") or
isinstance(self._daemon_proxy, DaemonClassicProxy): isinstance(self._daemon_proxy, DaemonClassicProxy)):
return True return True
return False return False

View File

@ -1,41 +1,15 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# deluge/ui/common.py
#
# Copyright (C) Damien Churchill 2008-2009 <damoxc@gmail.com> # Copyright (C) Damien Churchill 2008-2009 <damoxc@gmail.com>
# Copyright (C) Andrew Resch 2009 <andrewresch@gmail.com> # Copyright (C) Andrew Resch 2009 <andrewresch@gmail.com>
# #
# This program is free software; you can redistribute it and/or modify # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# it under the terms of the GNU General Public License as published by # the additional special exception to link portions of this program with the OpenSSL library.
# the Free Software Foundation; either version 3, or (at your option) # See LICENSE for more details.
# 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.
#
# #
""" """
The ui common module contains methods and classes that are deemed useful for The ui common module contains methods and classes that are deemed useful for all the interfaces.
all the interfaces.
""" """
import logging import logging
@ -125,7 +99,8 @@ class TorrentInfo(object):
path = os.path.join(prefix, *f["path.utf-8"]) path = os.path.join(prefix, *f["path.utf-8"])
del f["path.utf-8"] del f["path.utf-8"]
else: else:
path = utf8_encoded(os.path.join(prefix, utf8_encoded(os.path.join(*f["path"]), self.encoding)), self.encoding) path = utf8_encoded(os.path.join(prefix, utf8_encoded(os.path.join(*f["path"]),
self.encoding)), self.encoding)
f["path"] = path f["path"] = path
f["index"] = index f["index"] = index
if "sha1" in f and len(f["sha1"]) == 20: if "sha1" in f and len(f["sha1"]) == 20:
@ -267,6 +242,7 @@ class TorrentInfo(object):
""" """
return self.__m_filedata return self.__m_filedata
class FileTree2(object): class FileTree2(object):
""" """
Converts a list of paths in to a file tree. Converts a list of paths in to a file tree.
@ -328,16 +304,17 @@ class FileTree2(object):
for path in directory["contents"].keys(): for path in directory["contents"].keys():
full_path = path_join(parent_path, path) full_path = path_join(parent_path, path)
if directory["contents"][path]["type"] == "dir": if directory["contents"][path]["type"] == "dir":
directory["contents"][path] = callback(full_path, directory["contents"][path]) or \ directory["contents"][path] = callback(full_path, directory["contents"][path]
directory["contents"][path] ) or directory["contents"][path]
walk(directory["contents"][path], full_path) walk(directory["contents"][path], full_path)
else: else:
directory["contents"][path] = callback(full_path, directory["contents"][path]) or \ directory["contents"][path] = callback(full_path, directory["contents"][path]
directory["contents"][path] ) or directory["contents"][path]
walk(self.tree, "") walk(self.tree, "")
def __str__(self): def __str__(self):
lines = [] lines = []
def write(path, item): def write(path, item):
depth = path.count("/") depth = path.count("/")
path = os.path.basename(path) path = os.path.basename(path)
@ -346,6 +323,7 @@ class FileTree2(object):
self.walk(write) self.walk(write)
return "\n".join(lines) return "\n".join(lines)
class FileTree(object): class FileTree(object):
""" """
Convert a list of paths in a file tree. Convert a list of paths in a file tree.
@ -404,16 +382,15 @@ class FileTree(object):
for path in directory.keys(): for path in directory.keys():
full_path = os.path.join(parent_path, path) full_path = os.path.join(parent_path, path)
if type(directory[path]) is dict: if type(directory[path]) is dict:
directory[path] = callback(full_path, directory[path]) or \ directory[path] = callback(full_path, directory[path]) or directory[path]
directory[path]
walk(directory[path], full_path) walk(directory[path], full_path)
else: else:
directory[path] = callback(full_path, directory[path]) or \ directory[path] = callback(full_path, directory[path]) or directory[path]
directory[path]
walk(self.tree, "") walk(self.tree, "")
def __str__(self): def __str__(self):
lines = [] lines = []
def write(path, item): def write(path, item):
depth = path.count("/") depth = path.count("/")
path = os.path.basename(path) path = os.path.basename(path)
@ -422,6 +399,7 @@ class FileTree(object):
self.walk(write) self.walk(write)
return "\n".join(lines) return "\n".join(lines)
def get_localhost_auth(): def get_localhost_auth():
""" """
Grabs the localclient auth line from the 'auth' file and creates a localhost uri Grabs the localclient auth line from the 'auth' file and creates a localhost uri

View File

@ -1,38 +1,11 @@
# # -*- coding: utf-8 -*-
# coreconfig.py
# #
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
# #
# 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.
#
# 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 logging import logging
@ -41,11 +14,13 @@ from deluge.ui.client import client
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class CoreConfig(component.Component): class CoreConfig(component.Component):
def __init__(self): def __init__(self):
log.debug("CoreConfig init..") log.debug("CoreConfig init..")
component.Component.__init__(self, "CoreConfig") component.Component.__init__(self, "CoreConfig")
self.config = {} self.config = {}
def on_configvaluechanged_event(key, value): def on_configvaluechanged_event(key, value):
self.config[key] = value self.config[key] = value
client.register_event_handler("ConfigValueChangedEvent", on_configvaluechanged_event) client.register_event_handler("ConfigValueChangedEvent", on_configvaluechanged_event)

View File

@ -1,38 +1,13 @@
# # -*- coding: utf-8 -*-
# sessionproxy.py
# #
# Copyright (C) 2010 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2010 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 logging import logging
import time import time
@ -43,6 +18,7 @@ from deluge.ui.client import client
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class SessionProxy(component.Component): class SessionProxy(component.Component):
""" """
The SessionProxy component is used to cache session information client-side The SessionProxy component is used to cache session information client-side
@ -161,6 +137,7 @@ class SessionProxy(component.Component):
) )
else: else:
d = client.core.get_torrent_status(torrent_id, keys_to_get, True) d = client.core.get_torrent_status(torrent_id, keys_to_get, True)
def on_status(result, torrent_id): def on_status(result, torrent_id):
t = time.time() t = time.time()
self.torrents[torrent_id][0] = t self.torrents[torrent_id][0] = t
@ -171,6 +148,7 @@ class SessionProxy(component.Component):
return d.addCallback(on_status, torrent_id) return d.addCallback(on_status, torrent_id)
else: else:
d = client.core.get_torrent_status(torrent_id, keys, True) d = client.core.get_torrent_status(torrent_id, keys, True)
def on_status(result): def on_status(result):
if result: if result:
t = time.time() t = time.time()
@ -247,7 +225,6 @@ class SessionProxy(component.Component):
# Don't need to fetch anything # Don't need to fetch anything
return maybeDeferred(self.create_status_dict, self.torrents.keys(), keys) return maybeDeferred(self.create_status_dict, self.torrents.keys(), keys)
if len(filter_dict) == 1 and "id" in filter_dict: if len(filter_dict) == 1 and "id" in filter_dict:
# At this point we should have a filter with just "id" in it # At this point we should have a filter with just "id" in it
to_fetch = find_torrents_to_fetch(filter_dict["id"]) to_fetch = find_torrents_to_fetch(filter_dict["id"])
@ -271,6 +248,7 @@ class SessionProxy(component.Component):
def on_torrent_added(self, torrent_id, from_state): def on_torrent_added(self, torrent_id, from_state):
self.torrents[torrent_id] = [time.time() - self.cache_time - 1, {}] self.torrents[torrent_id] = [time.time() - self.cache_time - 1, {}]
self.cache_times[torrent_id] = {} self.cache_times[torrent_id] = {}
def on_status(status): def on_status(status):
self.torrents[torrent_id][1].update(status) self.torrents[torrent_id][1].update(status)
t = time.time() t = time.time()

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# tracker_icons.py
# #
# Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com> # Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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 logging import logging
@ -53,11 +27,10 @@ except ImportError:
# twisted 8 # twisted 8
from twisted.web.error import NoResource, ForbiddenResource from twisted.web.error import NoResource, ForbiddenResource
try: try:
import PIL.Image as Image import PIL.Image as Image
import deluge.ui.Win32IconImagePlugin import deluge.ui.Win32IconImagePlugin
assert deluge.ui.Win32IconImagePlugin # silence pyflakes
except ImportError: except ImportError:
PIL_INSTALLED = False PIL_INSTALLED = False
else: else:
@ -65,6 +38,7 @@ else:
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class TrackerIcon(object): class TrackerIcon(object):
""" """
Represents a tracker's icon Represents a tracker's icon
@ -77,7 +51,7 @@ class TrackerIcon(object):
:type filename: string :type filename: string
""" """
self.filename = os.path.abspath(filename) self.filename = os.path.abspath(filename)
self.mimetype = extension_to_mimetype(self.filename.rpartition('.')[2]) self.mimetype = extension_to_mimetype(self.filename.rpartition(".")[2])
self.data = None self.data = None
self.icon_cache = None self.icon_cache = None
@ -90,9 +64,9 @@ class TrackerIcon(object):
:returns: whether or not they're equal :returns: whether or not they're equal
:rtype: boolean :rtype: boolean
""" """
return os.path.samefile(self.filename, other.filename) or \ return (os.path.samefile(self.filename, other.filename) or
self.get_mimetype() == other.get_mimetype() and \ self.get_mimetype() == other.get_mimetype() and
self.get_data() == other.get_data() self.get_data() == other.get_data())
def get_mimetype(self): def get_mimetype(self):
""" """
@ -142,6 +116,7 @@ class TrackerIcon(object):
""" """
return self.icon_cache return self.icon_cache
class TrackerIcons(Component): class TrackerIcons(Component):
""" """
A TrackerIcon factory class A TrackerIcon factory class
@ -175,7 +150,7 @@ class TrackerIcons(Component):
self.icons[None] = TrackerIcon(no_icon) self.icons[None] = TrackerIcon(no_icon)
else: else:
self.icons[None] = None self.icons[None] = None
self.icons[''] = self.icons[None] self.icons[""] = self.icons[None]
self.pending = {} self.pending = {}
self.redirects = {} self.redirects = {}
@ -433,7 +408,7 @@ class TrackerIcons(Component):
if f.check(PageRedirect): if f.check(PageRedirect):
# Handle redirect errors # Handle redirect errors
location = urljoin(self.host_to_url(host), error_msg.split(" to ")[1]) location = urljoin(self.host_to_url(host), error_msg.split(" to ")[1])
d = self.download_icon([(location, extension_to_mimetype(location.rpartition('.')[2]))] + icons, host) d = self.download_icon([(location, extension_to_mimetype(location.rpartition(".")[2]))] + icons, host)
if not icons: if not icons:
d.addCallbacks(self.on_download_icon_complete, self.on_download_icon_fail, d.addCallbacks(self.on_download_icon_complete, self.on_download_icon_fail,
callbackArgs=(host,), errbackArgs=(host,)) callbackArgs=(host,), errbackArgs=(host,))
@ -441,7 +416,8 @@ class TrackerIcons(Component):
d = self.download_icon(icons, host) d = self.download_icon(icons, host)
elif f.check(NoIconsError, HTMLParseError): elif f.check(NoIconsError, HTMLParseError):
# No icons, try favicon.ico as an act of desperation # No icons, try favicon.ico as an act of desperation
d = self.download_icon([(urljoin(self.host_to_url(host), "favicon.ico"), extension_to_mimetype("ico"))], host) d = self.download_icon([(urljoin(self.host_to_url(host), "favicon.ico"),
extension_to_mimetype("ico"))], host)
d.addCallbacks(self.on_download_icon_complete, self.on_download_icon_fail, d.addCallbacks(self.on_download_icon_complete, self.on_download_icon_fail,
callbackArgs=(host,), errbackArgs=(host,)) callbackArgs=(host,), errbackArgs=(host,))
else: else:
@ -465,7 +441,7 @@ class TrackerIcons(Component):
filename = icon.get_filename() filename = icon.get_filename()
img = Image.open(filename) img = Image.open(filename)
if img.size > (16, 16): if img.size > (16, 16):
new_filename = filename.rpartition('.')[0]+".png" new_filename = filename.rpartition(".")[0] + ".png"
img = img.resize((16, 16), Image.ANTIALIAS) img = img.resize((16, 16), Image.ANTIALIAS)
img.save(new_filename) img.save(new_filename)
if new_filename != filename: if new_filename != filename:
@ -506,6 +482,7 @@ class TrackerIcons(Component):
################################ HELPER CLASSES ############################### ################################ HELPER CLASSES ###############################
class FaviconParser(HTMLParser): class FaviconParser(HTMLParser):
""" """
A HTMLParser which extracts favicons from a HTML page A HTMLParser which extracts favicons from a HTML page
@ -526,7 +503,7 @@ class FaviconParser(HTMLParser):
type = value type = value
if href: if href:
try: try:
mimetype = extension_to_mimetype(href.rpartition('.')[2]) mimetype = extension_to_mimetype(href.rpartition(".")[2])
except KeyError: except KeyError:
pass pass
else: else:
@ -561,6 +538,7 @@ def url_to_host(url):
""" """
return urlparse(url).hostname return urlparse(url).hostname
def host_to_icon_name(host, mimetype): def host_to_icon_name(host, mimetype):
""" """
Given a host, returns the appropriate icon name Given a host, returns the appropriate icon name
@ -573,7 +551,8 @@ def host_to_icon_name(host, mimetype):
:rtype: string :rtype: string
""" """
return host+'.'+mimetype_to_extension(mimetype) return host + "." + mimetype_to_extension(mimetype)
def icon_name_to_host(icon): def icon_name_to_host(icon):
""" """
@ -584,7 +563,7 @@ def icon_name_to_host(icon):
:returns: the host name :returns: the host name
:rtype: string :rtype: string
""" """
return icon.rpartition('.')[0] return icon.rpartition(".")[0]
MIME_MAP = { MIME_MAP = {
"image/gif": "gif", "image/gif": "gif",
@ -599,6 +578,7 @@ MIME_MAP = {
"ico": "image/vnd.microsoft.icon", "ico": "image/vnd.microsoft.icon",
} }
def mimetype_to_extension(mimetype): def mimetype_to_extension(mimetype):
""" """
Given a mimetype, returns the appropriate filename extension Given a mimetype, returns the appropriate filename extension
@ -611,6 +591,7 @@ def mimetype_to_extension(mimetype):
""" """
return MIME_MAP[mimetype.lower()] return MIME_MAP[mimetype.lower()]
def extension_to_mimetype(extension): def extension_to_mimetype(extension):
""" """
Given a filename extension, returns the appropriate mimetype Given a filename extension, returns the appropriate mimetype
@ -625,8 +606,10 @@ def extension_to_mimetype(extension):
################################## EXCEPTIONS ################################# ################################## EXCEPTIONS #################################
class NoIconsError(Exception): class NoIconsError(Exception):
pass pass
class InvalidIconError(Exception): class InvalidIconError(Exception):
pass pass

View File

@ -1,36 +1,10 @@
# # -*- coding: utf-8 -*-
# ui.py
# #
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# 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.
#
# 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.
#
# #
from __future__ import print_function from __future__ import print_function
@ -77,16 +51,13 @@ class _UI(object):
self.__parser.add_option("-v", "--version", action="callback", callback=version_callback, self.__parser.add_option("-v", "--version", action="callback", callback=version_callback,
help="Show program's version number and exit") help="Show program's version number and exit")
group = OptionGroup(self.__parser, "Common Options") group = OptionGroup(self.__parser, "Common Options")
group.add_option("-c", "--config", dest="config", group.add_option("-c", "--config", dest="config", help="Set the config folder location")
help="Set the config folder location", action="store", type="str") group.add_option("-l", "--logfile", dest="logfile", help="Output to designated logfile instead of stdout")
group.add_option("-l", "--logfile", dest="logfile",
help="Output to designated logfile instead of stdout", action="store", type="str")
group.add_option("-L", "--loglevel", dest="loglevel", group.add_option("-L", "--loglevel", dest="loglevel",
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str") help="Set the log level: none, info, warning, error, critical, debug")
group.add_option("-q", "--quiet", dest="quiet", group.add_option("-q", "--quiet", dest="quiet", action="store_true", default=False,
help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False) help="Sets the log level to 'none', this is the same as `-L none`")
group.add_option("-r", "--rotate-logs", group.add_option("-r", "--rotate-logs", help="Rotate logfiles.", action="store_true", default=False)
help="Rotate logfiles.", action="store_true", default=False)
self.__parser.add_option_group(group) self.__parser.add_option_group(group)
@property @property
@ -171,15 +142,15 @@ class UI:
if selected_ui == "gtk": if selected_ui == "gtk":
log.info("Starting GtkUI..") log.info("Starting GtkUI..")
from deluge.ui.gtkui.gtkui import GtkUI from deluge.ui.gtkui.gtkui import GtkUI
ui = GtkUI(args) GtkUI(args)
elif selected_ui == "web": elif selected_ui == "web":
log.info("Starting WebUI..") log.info("Starting WebUI..")
from deluge.ui.web.web import WebUI from deluge.ui.web.web import WebUI
ui = WebUI(args) WebUI(args)
elif selected_ui == "console": elif selected_ui == "console":
log.info("Starting ConsoleUI..") log.info("Starting ConsoleUI..")
from deluge.ui.console.main import ConsoleUI from deluge.ui.console.main import ConsoleUI
ui = ConsoleUI(ui_args) ConsoleUI(ui_args)
except ImportError as ex: except ImportError as ex:
import sys import sys
import traceback import traceback

View File

@ -1 +1,2 @@
from web import start from web import start
assert start # silence pyflakes

View File

@ -4,7 +4,6 @@
# #
import os import os
import re import re
import sys
from version import get_version from version import get_version
from subprocess import call from subprocess import call
from datetime import datetime from datetime import datetime

View File

@ -17,3 +17,4 @@ frameworks = CoreFoundation, Foundation, AppKit
[flake8] [flake8]
max-line-length = 120 max-line-length = 120
builtins = _ builtins = _
ignore = N802

View File

@ -23,11 +23,11 @@
# #
try: try:
from setuptools import setup, find_packages, Extension from setuptools import setup, find_packages
except ImportError: except ImportError:
import ez_setup import ez_setup
ez_setup.use_setuptools() ez_setup.use_setuptools()
from setuptools import setup, find_packages, Extension from setuptools import setup, find_packages
import os import os
import sys import sys
@ -37,7 +37,7 @@ import glob
from version import get_version from version import get_version
from distutils import cmd, sysconfig from distutils import cmd
from distutils.command.build import build as _build from distutils.command.build import build as _build
from distutils.command.clean import clean as _clean from distutils.command.clean import clean as _clean
@ -53,6 +53,7 @@ def windows_check():
desktop_data = 'deluge/ui/data/share/applications/deluge.desktop' desktop_data = 'deluge/ui/data/share/applications/deluge.desktop'
class build_trans(cmd.Command): class build_trans(cmd.Command):
description = 'Compile .po files into .mo files & create .desktop file' description = 'Compile .po files into .mo files & create .desktop file'
@ -79,17 +80,17 @@ class build_trans(cmd.Command):
if not windows_check(): if not windows_check():
# creates the translated desktop file # creates the translated desktop file
INTLTOOL_MERGE='intltool-merge' intltool_merge = 'intltool-merge'
INTLTOOL_MERGE_OPTS='--utf8 --quiet --desktop-style' intltool_merge_opts = '--utf8 --quiet --desktop-style'
desktop_in = 'deluge/ui/data/share/applications/deluge.desktop.in' desktop_in = 'deluge/ui/data/share/applications/deluge.desktop.in'
print('Creating desktop file: %s' % desktop_data) print('Creating desktop file: %s' % desktop_data)
os.system('C_ALL=C ' + '%s '*5 % (INTLTOOL_MERGE, INTLTOOL_MERGE_OPTS, \ os.system('C_ALL=C ' + '%s ' * 5 % (intltool_merge, intltool_merge_opts,
po_dir, desktop_in, desktop_data)) po_dir, desktop_in, desktop_data))
print('Compiling po files from %s...' % po_dir), print('Compiling po files from %s...' % po_dir),
for path, names, filenames in os.walk(po_dir): for path, names, filenames in os.walk(po_dir):
for f in filenames: for f in filenames:
uptoDate = False upto_date = False
if f.endswith('.po'): if f.endswith('.po'):
lang = f[:len(f) - 3] lang = f[:len(f) - 3]
src = os.path.join(path, f) src = os.path.join(path, f)
@ -109,9 +110,9 @@ class build_trans(cmd.Command):
sys.stdout.flush() sys.stdout.flush()
msgfmt.make(src, dest) msgfmt.make(src, dest)
else: else:
uptoDate = True upto_date = True
if uptoDate: if upto_date:
sys.stdout.write(' po files already upto date. ') sys.stdout.write(' po files already upto date. ')
sys.stdout.write('\b\b \nFinished compiling translation files. \n') sys.stdout.write('\b\b \nFinished compiling translation files. \n')
@ -134,12 +135,13 @@ class build_plugins(cmd.Command):
def run(self): def run(self):
# Build the plugin eggs # Build the plugin eggs
PLUGIN_PATH = "deluge/plugins/*" plugin_path = "deluge/plugins/*"
for path in glob.glob(PLUGIN_PATH): for path in glob.glob(plugin_path):
if os.path.exists(os.path.join(path, "setup.py")): if os.path.exists(os.path.join(path, "setup.py")):
if self.develop and self.install_dir: if self.develop and self.install_dir:
os.system("cd " + path + "&& " + sys.executable + " setup.py develop --install-dir=%s" % self.install_dir) os.system("cd " + path + "&& " + sys.executable +
" setup.py develop --install-dir=%s" % self.install_dir)
elif self.develop: elif self.develop:
os.system("cd " + path + "&& " + sys.executable + " setup.py develop") os.system("cd " + path + "&& " + sys.executable + " setup.py develop")
else: else:
@ -159,9 +161,9 @@ class egg_info_plugins(cmd.Command):
def run(self): def run(self):
# Build the plugin eggs # Build the plugin eggs
PLUGIN_PATH = "deluge/plugins/*" plugin_path = "deluge/plugins/*"
for path in glob.glob(PLUGIN_PATH): for path in glob.glob(plugin_path):
if os.path.exists(os.path.join(path, "setup.py")): if os.path.exists(os.path.join(path, "setup.py")):
os.system("cd " + path + "&& " + sys.executable + " setup.py egg_info") os.system("cd " + path + "&& " + sys.executable + " setup.py egg_info")
@ -188,6 +190,7 @@ class build_docs(BuildDoc):
return " " return " "
old_import = __builtins__.__import__ old_import = __builtins__.__import__
def new_import(name, globals={}, locals={}, fromlist=[], level=-1): def new_import(name, globals={}, locals={}, fromlist=[], level=-1):
try: try:
return old_import(name, globals, locals, fromlist, level) return old_import(name, globals, locals, fromlist, level)
@ -205,6 +208,7 @@ class build_docs(BuildDoc):
class build(_build): class build(_build):
sub_commands = [('build_trans', None), ('build_plugins', None)] + _build.sub_commands sub_commands = [('build_trans', None), ('build_plugins', None)] + _build.sub_commands
def run(self): def run(self):
# Run all sub-commands (at least those that need to be run) # Run all sub-commands (at least those that need to be run)
_build.run(self) _build.run(self)
@ -231,9 +235,9 @@ class clean_plugins(cmd.Command):
def run(self): def run(self):
print("Cleaning the plugin's folders..") print("Cleaning the plugin's folders..")
PLUGIN_PATH = "deluge/plugins/*" plugin_path = "deluge/plugins/*"
for path in glob.glob(PLUGIN_PATH): for path in glob.glob(plugin_path):
if os.path.exists(os.path.join(path, "setup.py")): if os.path.exists(os.path.join(path, "setup.py")):
c = "cd " + path + "&& " + sys.executable + " setup.py clean" c = "cd " + path + "&& " + sys.executable + " setup.py clean"
if self.all: if self.all:
@ -245,9 +249,9 @@ class clean_plugins(cmd.Command):
print("Deleting %s" % path) print("Deleting %s" % path)
os.remove(path) os.remove(path)
EGG_INFO_DIR_PATH = "deluge/plugins/*/*.egg-info" egg_info_dir_path = "deluge/plugins/*/*.egg-info"
for path in glob.glob(EGG_INFO_DIR_PATH): for path in glob.glob(egg_info_dir_path):
# Delete the .egg-info's directories # Delete the .egg-info's directories
if path[-9:] == ".egg-info": if path[-9:] == ".egg-info":
print("Deleting %s" % path) print("Deleting %s" % path)
@ -255,9 +259,9 @@ class clean_plugins(cmd.Command):
os.remove(os.path.join(path, fpath)) os.remove(os.path.join(path, fpath))
os.removedirs(path) os.removedirs(path)
ROOT_EGG_INFO_DIR_PATH = "deluge*.egg-info" root_egg_info_dir_path = "deluge*.egg-info"
for path in glob.glob(ROOT_EGG_INFO_DIR_PATH): for path in glob.glob(root_egg_info_dir_path):
print("Deleting %s" % path) print("Deleting %s" % path)
for fpath in os.listdir(path): for fpath in os.listdir(path):
os.remove(os.path.join(path, fpath)) os.remove(os.path.join(path, fpath))

View File

@ -35,18 +35,20 @@ __all__ = ("get_version")
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
VERSION_FILE = "RELEASE-VERSION" VERSION_FILE = "RELEASE-VERSION"
def call_git_describe(prefix='', suffix=''):
cmd = 'git describe --tags --match %s[0-9]*' % prefix def call_git_describe(prefix="", suffix=""):
cmd = "git describe --tags --match %s[0-9]*" % prefix
try: try:
version = Popen(cmd.split(), stdout=PIPE).communicate()[0] version = Popen(cmd.split(), stdout=PIPE).communicate()[0]
version = version.strip().replace(prefix, '') version = version.strip().replace(prefix, "")
if '-' in version: if "-" in version:
version = '.dev'.join(version.replace(suffix,'').split('-')[:2]) version = ".dev".join(version.replace(suffix, "").split("-")[:2])
return version return version
except: except:
return None return None
def get_version(prefix='', suffix=''):
def get_version(prefix="", suffix=""):
try: try:
with open(VERSION_FILE, "r") as f: with open(VERSION_FILE, "r") as f:
release_version = f.readline().strip() release_version = f.readline().strip()
@ -67,4 +69,4 @@ def get_version(prefix='', suffix=''):
return version return version
if __name__ == "__main__": if __name__ == "__main__":
print get_version(prefix='deluge-', suffix='.dev0') print get_version(prefix="deluge-", suffix=".dev0")