diff --git a/deluge/common.py b/deluge/common.py index 7320ab6c5..163e8ba03 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -253,27 +253,16 @@ def get_pixmap(fname): def resource_filename(module, path): - """A workaround for pkg_resources.resource_filename finding wrong package when developing - - When developing and there is a second deluge package (installed globally) and - another in develop mode elsewhere. While pkg_resources.require('Deluge') - returns the proper deluge instance, resource_filename does not, it returns - the first found on the python path, which is not what is wanted. - - Also ensures the filename path is decoded from bytes. - - Args: - module (str): The module name in dotted notation. - path (str): The relative path to resource. - - Returns: - str: The absolute resource path. - + """While developing, if there's a second deluge package, installed globally + and another in develop mode somewhere else, while pkg_resources.require('Deluge') + returns the proper deluge instance, pkg_resources.resource_filename does + not, it returns the first found on the python path, which is not good + enough. + This is a work-around that. """ - filename = pkg_resources.require('Deluge>=%s' % get_version())[0].get_resource_filename( - pkg_resources._manager, os.path.join(*(module.split('.') + [path]))) - - return decode_bytes(filename) + return pkg_resources.require('Deluge>=%s' % get_version())[0].get_resource_filename( + pkg_resources._manager, os.path.join(*(module.split('.') + [path])) + ) def open_file(path, timestamp=None): diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/common.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/common.py index 511692922..b47f85d0b 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/common.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/common.py @@ -14,10 +14,10 @@ from __future__ import unicode_literals -from os.path import join +import os.path -from deluge.common import resource_filename +from pkg_resources import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.autoadd', join('data', filename)) + return resource_filename('deluge.plugins.autoadd', os.path.join('data', filename)) diff --git a/deluge/plugins/Blocklist/deluge/plugins/blocklist/common.py b/deluge/plugins/Blocklist/deluge/plugins/blocklist/common.py index c797a65c3..e2e7a86ec 100644 --- a/deluge/plugins/Blocklist/deluge/plugins/blocklist/common.py +++ b/deluge/plugins/Blocklist/deluge/plugins/blocklist/common.py @@ -14,15 +14,15 @@ from __future__ import unicode_literals +import os.path from functools import wraps -from os.path import join from sys import exc_info -from deluge.common import resource_filename +from pkg_resources import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.blocklist', join('data', filename)) + return resource_filename('deluge.plugins.blocklist', os.path.join('data', filename)) def raises_errors_as(error): diff --git a/deluge/plugins/Execute/deluge/plugins/execute/common.py b/deluge/plugins/Execute/deluge/plugins/execute/common.py index 0bb8c343d..de0479129 100644 --- a/deluge/plugins/Execute/deluge/plugins/execute/common.py +++ b/deluge/plugins/Execute/deluge/plugins/execute/common.py @@ -14,10 +14,10 @@ from __future__ import unicode_literals -from os.path import join +import os.path -from deluge.common import resource_filename +from pkg_resources import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.execute', join('data', filename)) + return resource_filename('deluge.plugins.execute', os.path.join('data', filename)) diff --git a/deluge/plugins/Extractor/deluge/plugins/extractor/common.py b/deluge/plugins/Extractor/deluge/plugins/extractor/common.py index b52c3d92f..5d6ab1511 100644 --- a/deluge/plugins/Extractor/deluge/plugins/extractor/common.py +++ b/deluge/plugins/Extractor/deluge/plugins/extractor/common.py @@ -14,10 +14,10 @@ from __future__ import unicode_literals -from os.path import join +import os.path -from deluge.common import resource_filename +from pkg_resources import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.extractor', join('data', filename)) + return resource_filename('deluge.plugins.extractor', os.path.join('data', filename)) diff --git a/deluge/plugins/Label/deluge/plugins/label/common.py b/deluge/plugins/Label/deluge/plugins/label/common.py index 2aebe6f80..16e7d8aa3 100644 --- a/deluge/plugins/Label/deluge/plugins/label/common.py +++ b/deluge/plugins/Label/deluge/plugins/label/common.py @@ -14,10 +14,10 @@ from __future__ import unicode_literals -from os.path import join +import os.path -from deluge.common import resource_filename +from pkg_resources import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.label', join('data', filename)) + return resource_filename('deluge.plugins.label', os.path.join('data', filename)) diff --git a/deluge/plugins/Notifications/deluge/plugins/notifications/common.py b/deluge/plugins/Notifications/deluge/plugins/notifications/common.py index 64e3be290..8b4d68e9d 100644 --- a/deluge/plugins/Notifications/deluge/plugins/notifications/common.py +++ b/deluge/plugins/Notifications/deluge/plugins/notifications/common.py @@ -15,19 +15,19 @@ from __future__ import unicode_literals import logging -from os.path import join +import os.path +from pkg_resources import resource_filename from twisted.internet import defer from deluge import component -from deluge.common import resource_filename from deluge.event import known_events log = logging.getLogger(__name__) def get_resource(filename): - return resource_filename('deluge.plugins.notifications', join('data', filename)) + return resource_filename('deluge.plugins.notifications', os.path.join('data', filename)) class CustomNotifications(object): diff --git a/deluge/plugins/Scheduler/deluge/plugins/scheduler/common.py b/deluge/plugins/Scheduler/deluge/plugins/scheduler/common.py index eb752f92e..27cd79af7 100644 --- a/deluge/plugins/Scheduler/deluge/plugins/scheduler/common.py +++ b/deluge/plugins/Scheduler/deluge/plugins/scheduler/common.py @@ -14,10 +14,10 @@ from __future__ import unicode_literals -from os.path import join +import os.path -from deluge.common import resource_filename +from pkg_resources import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.scheduler', join('data', filename)) + return resource_filename('deluge.plugins.scheduler', os.path.join('data', filename)) diff --git a/deluge/plugins/Stats/deluge/plugins/stats/common.py b/deluge/plugins/Stats/deluge/plugins/stats/common.py index d3d26d5dc..f70d711d6 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/common.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/common.py @@ -14,10 +14,10 @@ from __future__ import unicode_literals -from os.path import join +import os.path -from deluge.common import resource_filename +from pkg_resources import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.stats', join('data', filename)) + return resource_filename('deluge.plugins.stats', os.path.join('data', filename)) diff --git a/deluge/plugins/Toggle/deluge/plugins/toggle/common.py b/deluge/plugins/Toggle/deluge/plugins/toggle/common.py index 8177a101e..60f6ac149 100644 --- a/deluge/plugins/Toggle/deluge/plugins/toggle/common.py +++ b/deluge/plugins/Toggle/deluge/plugins/toggle/common.py @@ -14,10 +14,10 @@ from __future__ import unicode_literals -from os.path import join +import os.path -from deluge.common import resource_filename +from pkg_resources import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.toggle', join('data', filename)) + return resource_filename('deluge.plugins.toggle', os.path.join('data', filename)) diff --git a/deluge/plugins/WebUi/deluge/plugins/webui/common.py b/deluge/plugins/WebUi/deluge/plugins/webui/common.py index 1e05ed1fc..0a9d6574f 100644 --- a/deluge/plugins/WebUi/deluge/plugins/webui/common.py +++ b/deluge/plugins/WebUi/deluge/plugins/webui/common.py @@ -14,10 +14,10 @@ from __future__ import unicode_literals -from os.path import join +import os.path -from deluge.common import resource_filename +from pkg_resources import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.webui', join('data', filename)) + return resource_filename('deluge.plugins.webui', os.path.join('data', filename)) diff --git a/deluge/scripts/create_plugin.py b/deluge/scripts/create_plugin.py index 83582ade8..a1dd356d2 100644 --- a/deluge/scripts/create_plugin.py +++ b/deluge/scripts/create_plugin.py @@ -213,12 +213,13 @@ setup( COMMON = """ from __future__ import unicode_literals -from os.path import join +import os.path + +from pkg_resources import resource_filename -from deluge.common import resource_filename def get_resource(filename): - return resource_filename('deluge.plugins.%(safe_name)s', join('data', filename)) + return resource_filename('deluge.plugins.%(safe_name)s', os.path.join('data', filename)) """ GTKUI = """