From f85287771d74f7821a2513e5aca9eabf941bd574 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 11 Nov 2019 19:42:34 +0100 Subject: [PATCH] RSS: Register feed config in config.py instead of plugin.py. So they are not dropped if plugin.py fails to load before feedparser is not installed. Closes GH-1387. --- plugins/RSS/config.py | 23 +++++++++++++++++++++++ plugins/RSS/plugin.py | 30 ++++-------------------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/plugins/RSS/config.py b/plugins/RSS/config.py index 0dda277c9..194ae83aa 100644 --- a/plugins/RSS/config.py +++ b/plugins/RSS/config.py @@ -115,4 +115,27 @@ conf.registerChannelValue(RSS, 'keywordBlacklist', in this blacklist."""))) +def register_feed_config(name, url=''): + RSS.feeds().add(name) + conf.registerGlobalValue(RSS.feeds, name, + registry.String(url, _("""The URL for the feed %s. Note that because + announced lines are cached, you may need to reload this plugin after + changing this option.""" % name))) + feed_group = conf.registerGroup(RSS.feeds, name) + conf.registerChannelValue(feed_group, 'format', + registry.String('', _("""Feed-specific format. Defaults to + supybot.plugins.RSS.format if empty."""))) + conf.registerChannelValue(feed_group, 'announceFormat', + registry.String('', _("""Feed-specific announce format. + Defaults to supybot.plugins.RSS.announceFormat if empty."""))) + conf.registerGlobalValue(feed_group, 'waitPeriod', + registry.NonNegativeInteger(0, _("""If set to a non-zero + value, overrides supybot.plugins.RSS.waitPeriod for this + particular feed."""))) + +for name in RSS.feeds(): + register_feed_config(name) + + + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index ba0ba4ff0..5310f590b 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -62,6 +62,8 @@ if minisix.PY2: else: from urllib.request import ProxyHandler +from .config import register_feed_config + def get_feedName(irc, msg, args, state): if irc.isChannel(args[0]): state.errorInvalid('feed name', args[0], 'must not be channel names.') @@ -194,8 +196,6 @@ class RSS(callbacks.Plugin): else: announced = {} for name in self.registryValue('feeds'): - self.assert_feed_does_not_exist(name) - self.register_feed_config(name) try: url = self.registryValue(registry.join(['feeds', name])) except registry.NonExistentRegistryEntry: @@ -235,28 +235,6 @@ class RSS(callbacks.Plugin): feed.name) raise callbacks.Error(s) - def register_feed_config(self, name, url=''): - self.registryValue('feeds').add(name) - group = self.registryValue('feeds', value=False) - conf.registerGlobalValue(group, name, - registry.String(url, """The URL for the feed - %s. Note that because - announced lines are cached, - you may need to reload this - plugin after changing this - option.""" % name)) - feed_group = conf.registerGroup(group, name) - conf.registerChannelValue(feed_group, 'format', - registry.String('', _("""Feed-specific format. Defaults to - supybot.plugins.RSS.format if empty."""))) - conf.registerChannelValue(feed_group, 'announceFormat', - registry.String('', _("""Feed-specific announce format. - Defaults to supybot.plugins.RSS.announceFormat if empty."""))) - conf.registerGlobalValue(feed_group, 'waitPeriod', - registry.NonNegativeInteger(0, _("""If set to a non-zero - value, overrides supybot.plugins.RSS.waitPeriod for this - particular feed."""))) - def register_feed(self, name, url, initial, plugin_is_loading, announced=None): self.feed_names[name] = url @@ -468,7 +446,7 @@ class RSS(callbacks.Plugin): given URL. """ self.assert_feed_does_not_exist(name, url) - self.register_feed_config(name, url) + register_feed_config(name, url) self.register_feed(name, url, True, False) irc.replySuccess() add = wrap(add, ['feedName', 'url']) @@ -525,7 +503,7 @@ class RSS(callbacks.Plugin): for name in feeds: feed = plugin.get_feed(name) if not feed: - plugin.register_feed_config(name, name) + register_feed_config(name, name) plugin.register_feed(name, name, True, False) feed = plugin.get_feed(name) plugin.announce_feed(feed, True)