Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rawdog
Original file line number Diff line number Diff line change
@@ -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 <ats@offog.org>
#
Expand Down
56 changes: 54 additions & 2 deletions rawdoglib/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions rawdoglib/rawdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import getopt
import hashlib
import locale
import operator
import os
import re
import socket
Expand All @@ -40,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
Expand Down Expand Up @@ -461,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,
Expand Down Expand Up @@ -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:
Expand Down