Make list of publishable feeds configurable, per:

http://lists.planetplanet.org/archives/devel/2010-June/002149.html

Also change use of stderr to log, and provide a main program entry point
which can be used to initiate publishing.
This commit is contained in:
Sam Ruby 2010-06-15 21:11:21 -04:00
parent e51f58a2c4
commit 399b0f052a
4 changed files with 38 additions and 6 deletions

View File

@ -126,6 +126,9 @@ hub when feeds are published, speeding delivery of updates to
subscribers. See
the <a href="http://code.google.com/p/pubsubhubbub/"> PubSubHubbub
home page</a> for more information.</dd>
<dt><ins>pubsubhubbub_feeds</ins></dt>
<dd>List of feeds to publish. Defaults to <code>atom.xml rss10.xml
rss20.xml</code>.</dd>
</dl>
<p>Additional options can be found in
<a href="normalization.html#overrides">normalization level overrides</a>.</p>

View File

@ -106,6 +106,7 @@ def __init__():
define_planet('output_dir', 'output')
define_planet('spider_threads', 0)
define_planet('pubsubhubbub_hub', '')
define_planet_list('pubsubhubbub_feeds', 'atom.xml rss10.xml rss20.xml')
define_planet_int('new_feed_items', 0)
define_planet_int('feed_timeout', 20)

View File

@ -1,15 +1,26 @@
import os, sys
import urlparse
import planet
import pubsubhubbub_publisher as PuSH
def publish(config):
log = planet.logger
hub = config.pubsubhubbub_hub()
link = config.link()
# identify feeds
feeds = []
if hub and link:
for root, dirs, files in os.walk(config.output_dir()):
xmlfiles = [urlparse.urljoin(link, f) for f in files if f in ['atom.xml', 'rss10.xml', 'rss20.xml']]
for file in files:
if file in config.pubsubhubbub_feeds():
feeds.append(urlparse.urljoin(link, file))
# publish feeds
if feeds:
try:
PuSH.publish(hub, xmlfiles)
PuSH.publish(hub, feeds)
for feed in feeds:
log.info("Published %s to %s\n" % (feed, hub))
except PuSH.PublishError, e:
sys.stderr.write("PubSubHubbub publishing error: %s\n" % e)
break
log.error("PubSubHubbub publishing error: %s\n" % e)

17
publish.py Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env python
"""
Main program to run just the splice portion of planet
"""
import os.path
import sys
from planet import publish, config
if __name__ == '__main__':
if len(sys.argv) == 2 and os.path.isfile(sys.argv[1]):
config.load(sys.argv[1])
publish.publish(config)
else:
print "Usage:"
print " python %s config.ini" % sys.argv[0]