diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index da9590d48..cea08ccb9 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -8,6 +8,7 @@ """PluginManagerBase""" +import email import logging import os.path @@ -266,25 +267,13 @@ class PluginManagerBase: @staticmethod def parse_pkg_info(pkg_info): - last_header = '' - cont_lines = [] - info = {}.fromkeys(METADATA_KEYS, '') + metadata_msg = email.message_from_string(pkg_info) + metadata_ver = metadata_msg.get('Metadata-Version') - for line in pkg_info.splitlines(): - if not line: - continue + info = {key: metadata_msg.get(key, '') for key in METADATA_KEYS} - 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()) - continue + # 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() - 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() return info diff --git a/deluge/tests/test_plugin_metadata.py b/deluge/tests/test_plugin_metadata.py index d86b245d8..58e410ad5 100644 --- a/deluge/tests/test_plugin_metadata.py +++ b/deluge/tests/test_plugin_metadata.py @@ -20,10 +20,30 @@ class PluginManagerBaseTestCase(BaseTestCase): pm = PluginManagerBase('core.conf', 'deluge.plugin.core') for p in pm.get_available_plugins(): for key, value in pm.get_plugin_info(p).items(): - self.assertTrue(isinstance(f'{key}: {value}', str)) + self.assertIsInstance(key, str) + self.assertIsInstance(value, str) def test_get_plugin_info_invalid_name(self): pm = PluginManagerBase('core.conf', 'deluge.plugin.core') for key, value in pm.get_plugin_info('random').items(): result = 'not available' if key in ('Name', 'Version') else '' self.assertEqual(value, result) + + def test_parse_pkg_info_metadata_2_1(self): + pkg_info = """Metadata-Version: 2.1 +Name: AutoAdd +Version: 1.8 +Summary: Monitors folders for .torrent files. +Home-page: http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd +Author: Chase Sterling, Pedro Algarvio +Author-email: chase.sterling@gmail.com, pedro@algarvio.me +License: GPLv3 +Platform: UNKNOWN + +Monitors folders for .torrent files. + """ + plugin_info = PluginManagerBase.parse_pkg_info(pkg_info) + for value in plugin_info.values(): + self.assertNotEqual(value, '') + result = 'Monitors folders for .torrent files.' + self.assertEqual(plugin_info['Description'], result)