summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2022-01-12 20:03:09 +0000
committerCalum Lind <calumlind+deluge@gmail.com>2022-01-12 20:12:02 +0000
commitc3cd7f5e5cd133d6488f01899dbc39910fc63c6f (patch)
tree0a4ab8d61bc9360d7ad44a32ce98c7eaa18d9223
parent2351d658449e94c409c2a71ade714a6ca19d793a (diff)
downloaddeluge-c3cd7f5e5cd133d6488f01899dbc39910fc63c6f.tar.gz
deluge-c3cd7f5e5cd133d6488f01899dbc39910fc63c6f.tar.bz2
deluge-c3cd7f5e5cd133d6488f01899dbc39910fc63c6f.zip
[Plugins] Fix missing description with metadata 2.1
Changes to the metadata specs in v2.1 meant that Description field might appear in the body of the message instead of as a header key. Replaced custom parser with email parser (as outlined in the document using compat32 policy) to simplify extracting the message header and body. Ref: https://dev.deluge-torrent.org/ticket/3476 Ref: https://packaging.python.org/en/latest/specifications/core-metadata/#description
-rw-r--r--deluge/pluginmanagerbase.py25
-rw-r--r--deluge/tests/test_plugin_metadata.py22
2 files changed, 28 insertions, 19 deletions
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)