1.1 --- a/MoinShare.py Tue May 14 01:37:22 2013 +0200
1.2 +++ b/MoinShare.py Tue May 14 17:16:56 2013 +0200
1.3 @@ -189,4 +189,48 @@
1.4
1.5 return updates
1.6
1.7 +# Source management.
1.8 +
1.9 +def getUpdateSources(pagename, request):
1.10 +
1.11 + "Return the update sources from the given 'pagename' using the 'request'."
1.12 +
1.13 + sources = {}
1.14 +
1.15 + source_definitions = getWikiDict(pagename, request)
1.16 +
1.17 + if source_definitions:
1.18 + for name, value in source_definitions.items():
1.19 + sources[name] = getSourceParameters(value)
1.20 +
1.21 + return sources
1.22 +
1.23 +def getSourceParameters(source_definition):
1.24 +
1.25 + "Return the parameters from the given 'source_definition' string."
1.26 +
1.27 + parameters = {}
1.28 + unqualified = ("type", "location")
1.29 +
1.30 + for arg in source_definition.split():
1.31 + try:
1.32 + argname, argvalue = arg.split("=", 1)
1.33 +
1.34 + # Detect unlikely parameter names.
1.35 +
1.36 + if not argname.isalpha():
1.37 + raise ValueError
1.38 +
1.39 + parameters[argname] = argvalue
1.40 +
1.41 + # Unqualified parameters are assumed to be one of a recognised set.
1.42 +
1.43 + except ValueError:
1.44 + for argname in unqualified:
1.45 + if not parameters.has_key(argname):
1.46 + parameters[argname] = arg
1.47 + break
1.48 +
1.49 + return parameters
1.50 +
1.51 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/macros/SharedContent.py Tue May 14 01:37:22 2013 +0200
2.2 +++ b/macros/SharedContent.py Tue May 14 17:16:56 2013 +0200
2.3 @@ -10,7 +10,7 @@
2.4 from MoinMoin.Page import Page
2.5 from MoinRemoteSupport import *
2.6 from MoinSupport import parseMacroArguments
2.7 -from MoinShare import getUpdatesFromPage, Update
2.8 +from MoinShare import getUpdateSources, getUpdatesFromPage, Update
2.9 from email.utils import parsedate
2.10 import xml.dom.pulldom
2.11
2.12 @@ -197,16 +197,13 @@
2.13 fmt = macro.formatter
2.14 _ = request.getText
2.15
2.16 - feed_urls = []
2.17 - pagenames = []
2.18 + source_pages = []
2.19 show_content = None
2.20 max_entries = None
2.21
2.22 for arg, value in parseMacroArguments(args):
2.23 - if arg == "url":
2.24 - feed_urls.append(value)
2.25 - elif arg == "page":
2.26 - pagenames.append(value)
2.27 + if arg == "sources":
2.28 + source_pages.append(value)
2.29 elif arg == "show":
2.30 show_content = value.lower()
2.31 elif arg == "limit":
2.32 @@ -215,44 +212,67 @@
2.33 except ValueError:
2.34 return fmt.text(_("SharedContent: limit must be set to the maximum number of entries to be shown"))
2.35
2.36 - if not feed_urls and not pagenames:
2.37 - return fmt.text(_("SharedContent: at least one feed URL or page must be specified"))
2.38 + if not source_pages:
2.39 + return fmt.text(_("SharedContent: at least one sources page must be specified"))
2.40 +
2.41 + sources = {}
2.42 +
2.43 + for source_page in source_pages:
2.44 + sources.update(getUpdateSources(source_page, request))
2.45 +
2.46 + if not sources:
2.47 + return fmt.text(_("SharedContent: at least one update source must be specified"))
2.48
2.49 show_content = show_content or False
2.50 max_entries = max_entries or MAX_ENTRIES
2.51
2.52 - # Retrieve updates from feeds, classifying them as missing or bad and
2.53 - # excluding them if appropriate.
2.54 + # Retrieve updates, classifying them as missing or bad and excluding them if
2.55 + # appropriate.
2.56
2.57 updates = []
2.58 feeds = []
2.59 + unspecified = []
2.60 missing = []
2.61 bad_content = []
2.62
2.63 - for feed_url in feed_urls:
2.64 + for source_name, source_parameters in sources.items():
2.65 + location = source_parameters.get("location")
2.66 + if not location:
2.67 + unspecified.append(source_name)
2.68 + continue
2.69 +
2.70 + show_feed_content = source_parameters.get("show", show_content)
2.71 try:
2.72 - feed_info, feed_updates = getUpdates(request, feed_url, max_entries, show_content)
2.73 - updates += feed_updates
2.74 - feeds.append((feed_url, feed_info))
2.75 - except FeedMissingError:
2.76 - missing.append(feed_url)
2.77 - except FeedContentTypeError:
2.78 - bad_content.append(feed_url)
2.79 + max_entries_for_feed = int(source_parameters["limit"])
2.80 + except (KeyError, ValueError):
2.81 + max_entries_for_feed = None
2.82
2.83 - # Retrieve updates from pages.
2.84 + # Retrieve updates from feeds.
2.85
2.86 - for pagename in pagenames:
2.87 - page = Page(request, pagename)
2.88 - updates += getUpdatesFromPage(page, request)
2.89 + if source_parameters.get("type") == "url":
2.90 + try:
2.91 + feed_info, feed_updates = getUpdates(request, location, max_entries_for_feed, show_feed_content)
2.92 + updates += feed_updates
2.93 + feeds.append((location, feed_info))
2.94 + except FeedMissingError:
2.95 + missing.append(location)
2.96 + except FeedContentTypeError:
2.97 + bad_content.append(location)
2.98
2.99 - # Build feed-equivalent information for the update source.
2.100 + # Retrieve updates from pages.
2.101
2.102 - feeds.append((
2.103 - page.url(request), (
2.104 - "internal", _("Updates from page %s") % pagename,
2.105 - page.url(request, {"action" : "SharedUpdates", "doit" : "1"})
2.106 - )
2.107 - ))
2.108 + elif source_parameters.get("type") == "page":
2.109 + page = Page(request, location)
2.110 + updates += getUpdatesFromPage(page, request)
2.111 +
2.112 + # Build feed-equivalent information for the update source.
2.113 +
2.114 + feeds.append((
2.115 + page.url(request, {"action" : "SharedUpdates", "doit" : "1"}), (
2.116 + "internal", _("Updates from page %s") % location,
2.117 + page.url(request)
2.118 + )
2.119 + ))
2.120
2.121 # Prepare the output.
2.122