summaryrefslogtreecommitdiffstats
path: root/deluge/pluginmanagerbase.py
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/pluginmanagerbase.py')
-rw-r--r--deluge/pluginmanagerbase.py59
1 files changed, 28 insertions, 31 deletions
diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py
index f838cd3..835dbb2 100644
--- a/deluge/pluginmanagerbase.py
+++ b/deluge/pluginmanagerbase.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
#
@@ -9,8 +8,7 @@
"""PluginManagerBase"""
-from __future__ import unicode_literals
-
+import email
import logging
import os.path
@@ -37,7 +35,7 @@ METADATA_KEYS = [
]
DEPRECATION_WARNING = """
-The plugin %s is not using the "deluge.plugins" namespace.
+The plugin %s is not using the "deluge_" namespace.
In order to avoid package name clashes between regular python packages and
deluge plugins, the way deluge plugins should be created has changed.
If you're seeing this message and you're not the developer of the plugin which
@@ -47,7 +45,7 @@ git repository to have an idea of what needs to be changed.
"""
-class PluginManagerBase(object):
+class PluginManagerBase:
"""PluginManagerBase is a base class for PluginManagers to inherit"""
def __init__(self, config_file, entry_name):
@@ -105,7 +103,9 @@ class PluginManagerBase(object):
for dirname in plugin_dirs:
pkg_resources.working_set.add_entry(dirname)
- self.pkg_env = pkg_resources.Environment(plugin_dirs, None)
+ self.pkg_env = pkg_resources.Environment(
+ plugin_dirs, platform=None, python=None
+ )
self.available_plugins = []
for name in self.pkg_env:
@@ -129,7 +129,7 @@ class PluginManagerBase(object):
"""
if plugin_name not in self.available_plugins:
- log.warning('Cannot enable non-existant plugin %s', plugin_name)
+ log.warning('Cannot enable non-existent plugin %s', plugin_name)
return defer.succeed(False)
if plugin_name in self.plugins:
@@ -162,7 +162,7 @@ class PluginManagerBase(object):
log.exception(ex)
return_d = defer.fail(False)
- if not instance.__module__.startswith('deluge.plugins.'):
+ if not instance.__module__.startswith('deluge_'):
import warnings
warnings.warn_explicit(
@@ -243,7 +243,7 @@ class PluginManagerBase(object):
del self.plugins[name]
self.config['enabled_plugins'].remove(name)
except Exception as ex:
- log.warning('Problems occured disabling plugin: %s', name)
+ log.warning('Problems occurred disabling plugin: %s', name)
log.debug(ex)
ret = False
else:
@@ -255,28 +255,25 @@ class PluginManagerBase(object):
def get_plugin_info(self, name):
"""Returns a dictionary of plugin info from the metadata"""
- info = {}.fromkeys(METADATA_KEYS)
- last_header = ''
- cont_lines = []
- # Missing plugin info
+
if not self.pkg_env[name]:
- log.warning('Failed to retrive info for plugin: %s', name)
- for k in info:
- info[k] = 'not available'
+ log.warning('Failed to retrieve info for plugin: %s', name)
+ info = {}.fromkeys(METADATA_KEYS, '')
+ info['Name'] = info['Version'] = 'not available'
return info
- for line in self.pkg_env[name][0].get_metadata('PKG-INFO').splitlines():
- if not line:
- continue
- if line[0] in ' \t' and (
- len(line.split(':', 1)) == 1 or line.split(':', 1)[0] not in info
- ):
- # This is a continuation
- cont_lines.append(line.strip())
- else:
- if cont_lines:
- info[last_header] = '\n'.join(cont_lines).strip()
- cont_lines = []
- if line.split(':', 1)[0] in info:
- last_header = line.split(':', 1)[0]
- info[last_header] = line.split(':', 1)[1].strip()
+
+ pkg_info = self.pkg_env[name][0].get_metadata('PKG-INFO')
+ return self.parse_pkg_info(pkg_info)
+
+ @staticmethod
+ def parse_pkg_info(pkg_info):
+ metadata_msg = email.message_from_string(pkg_info)
+ metadata_ver = metadata_msg.get('Metadata-Version')
+
+ info = {key: metadata_msg.get(key, '') for key in METADATA_KEYS}
+
+ # Optional Description field in body (Metadata spec >=2.1)
+ if not info['Description'] and metadata_ver.startswith('2'):
+ info['Description'] = metadata_msg.get_payload().strip()
+
return info