From 480cdee2c47d9dda2897e4458f4ecd0674c526ea Mon Sep 17 00:00:00 2001 From: Maarten Aertsen Date: Tue, 18 Feb 2025 20:10:03 +0100 Subject: [PATCH 1/4] change shebang to python3 --- rawdog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rawdog b/rawdog index cdf9794..5d74dac 100755 --- a/rawdog +++ b/rawdog @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # rawdog: RSS aggregator without delusions of grandeur. # Copyright 2003, 2004, 2005, 2006, 2016 Adam Sampson # From 52820920ad9cc660e14d6b2e40013cac23b28aee Mon Sep 17 00:00:00 2001 From: Maarten Aertsen Date: Tue, 18 Feb 2025 20:10:48 +0100 Subject: [PATCH 2/4] sort feeds by their url --- rawdoglib/rawdog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 1633faa..c95e05d 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -18,6 +18,7 @@ import getopt import hashlib import locale +import operator import os import re import socket @@ -1496,7 +1497,7 @@ def write_feedlist(self, f, config): feeds = [(feed.get_html_name(config).lower(), feed) for feed in list(self.feeds.values())] - feeds.sort() + feeds.sort(key=operator.itemgetter(0)) feeditems = StringIO() for key, feed in feeds: From c2301f8c5bfb885d7792dc3db470ee6315b0b28e Mon Sep 17 00:00:00 2001 From: Maarten Aertsen Date: Tue, 18 Feb 2025 20:11:10 +0100 Subject: [PATCH 3/4] handle p.get("rawdog_responses") is None --- rawdoglib/rawdog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index c95e05d..c2742ae 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -462,7 +462,7 @@ def update(self, rawdog, now, config, articles, p) -> bool: # can't assume that p contains any particular field. responses = p.get("rawdog_responses") - if len(responses) > 0: + if responses is not None and len(responses) > 0: last_status = responses[-1]["status"] elif len(p.get("feed", [])) != 0: # Some protocol other than HTTP -- assume it's OK, From dc1d02a91cc863443a4ce84e148b691c333fb41d Mon Sep 17 00:00:00 2001 From: Maarten Aertsen Date: Tue, 18 Feb 2025 20:27:02 +0100 Subject: [PATCH 4/4] add missing load_plugins() --- rawdoglib/plugins.py | 56 ++++++++++++++++++++++++++++++++++++++++++-- rawdoglib/rawdog.py | 2 +- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/rawdoglib/plugins.py b/rawdoglib/plugins.py index f319ec1..8f4eb30 100644 --- a/rawdoglib/plugins.py +++ b/rawdoglib/plugins.py @@ -18,13 +18,65 @@ # Vellum weblog system: # http://www.kryogenix.org/code/vellum/ +import imp +import os + + class Box: """Utility class that holds a mutable value. Useful for passing immutable types by reference.""" + def __init__(self, value=None): self.value = value +plugin_count = 0 + + +def load_plugins(dir, config): + global plugin_count + + try: + files = os.listdir(dir) + except OSError: + # Ignore directories that can't be read. + return + + for file in files: + if file == "" or file[0] == ".": + continue + + desc = None + for d in imp.get_suffixes(): + if file.endswith(d[0]) and d[2] == imp.PY_SOURCE: + desc = d + if desc is None: + continue + + fn = os.path.join(dir, file) + config.log("Loading plugin ", fn) + f = open(fn, "r") + imp.load_module("plugin%d" % (plugin_count,), f, fn, desc) + plugin_count += 1 + f.close() + + +attached = {} + + +def attach_hook(hookname, func): + """Attach a function to a hook. The function should take the + appropriate arguments for the hook, and should return either True or + False to indicate whether further functions should be processed.""" + attached.setdefault(hookname, []).append(func) + + def call_hook(hookname, *args): - # stub, to be removed later - pass + """Call all the functions attached to a hook with the given + arguments, in the order they were added, stopping if a hook function + returns False. Returns True if any hook function returned False (i.e. + returns True if any hook function handled the request).""" + for func in attached.get(hookname, []): + if not func(*args): + return True + return False diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index c2742ae..ac727a6 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -41,7 +41,7 @@ import rawdoglib.feedscanner from rawdoglib.persister import Persistable, Persister -from rawdoglib.plugins import Box, call_hook +from rawdoglib.plugins import Box, call_hook, load_plugins try: import tidylib