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