Revert "[#2341] Use common.resource_filename in plugins"

Using common.resource_filename broke plugins so need to find a better solution for non-ascii dirs.

This reverts commit bdb3b509adf5915efa938be3871e65ee8a817093.
This commit is contained in:
Calum Lind 2017-06-16 14:07:46 +01:00
parent 3893d3e214
commit fb4307f748
12 changed files with 43 additions and 53 deletions

View File

@ -253,27 +253,16 @@ def get_pixmap(fname):
def resource_filename(module, path): def resource_filename(module, path):
"""A workaround for pkg_resources.resource_filename finding wrong package when developing """While developing, if there's a second deluge package, installed globally
and another in develop mode somewhere else, while pkg_resources.require('Deluge')
When developing and there is a second deluge package (installed globally) and returns the proper deluge instance, pkg_resources.resource_filename does
another in develop mode elsewhere. While pkg_resources.require('Deluge') not, it returns the first found on the python path, which is not good
returns the proper deluge instance, resource_filename does not, it returns enough.
the first found on the python path, which is not what is wanted. This is a work-around that.
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.
""" """
filename = 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]))
)
return decode_bytes(filename)
def open_file(path, timestamp=None): def open_file(path, timestamp=None):

View File

@ -14,10 +14,10 @@
from __future__ import unicode_literals 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): def get_resource(filename):
return resource_filename('deluge.plugins.autoadd', join('data', filename)) return resource_filename('deluge.plugins.autoadd', os.path.join('data', filename))

View File

@ -14,15 +14,15 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import os.path
from functools import wraps from functools import wraps
from os.path import join
from sys import exc_info from sys import exc_info
from deluge.common import resource_filename from pkg_resources import resource_filename
def get_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): def raises_errors_as(error):

View File

@ -14,10 +14,10 @@
from __future__ import unicode_literals 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): def get_resource(filename):
return resource_filename('deluge.plugins.execute', join('data', filename)) return resource_filename('deluge.plugins.execute', os.path.join('data', filename))

View File

@ -14,10 +14,10 @@
from __future__ import unicode_literals 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): def get_resource(filename):
return resource_filename('deluge.plugins.extractor', join('data', filename)) return resource_filename('deluge.plugins.extractor', os.path.join('data', filename))

View File

@ -14,10 +14,10 @@
from __future__ import unicode_literals 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): def get_resource(filename):
return resource_filename('deluge.plugins.label', join('data', filename)) return resource_filename('deluge.plugins.label', os.path.join('data', filename))

View File

@ -15,19 +15,19 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import logging import logging
from os.path import join import os.path
from pkg_resources import resource_filename
from twisted.internet import defer from twisted.internet import defer
from deluge import component from deluge import component
from deluge.common import resource_filename
from deluge.event import known_events from deluge.event import known_events
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def get_resource(filename): 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): class CustomNotifications(object):

View File

@ -14,10 +14,10 @@
from __future__ import unicode_literals 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): def get_resource(filename):
return resource_filename('deluge.plugins.scheduler', join('data', filename)) return resource_filename('deluge.plugins.scheduler', os.path.join('data', filename))

View File

@ -14,10 +14,10 @@
from __future__ import unicode_literals 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): def get_resource(filename):
return resource_filename('deluge.plugins.stats', join('data', filename)) return resource_filename('deluge.plugins.stats', os.path.join('data', filename))

View File

@ -14,10 +14,10 @@
from __future__ import unicode_literals 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): def get_resource(filename):
return resource_filename('deluge.plugins.toggle', join('data', filename)) return resource_filename('deluge.plugins.toggle', os.path.join('data', filename))

View File

@ -14,10 +14,10 @@
from __future__ import unicode_literals 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): def get_resource(filename):
return resource_filename('deluge.plugins.webui', join('data', filename)) return resource_filename('deluge.plugins.webui', os.path.join('data', filename))

View File

@ -213,12 +213,13 @@ setup(
COMMON = """ COMMON = """
from __future__ import unicode_literals 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): 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 = """ GTKUI = """