- # XXX no reason to do this on the fly; cache it on server startup
- update_config = defaultdict(dict) # source_name => config
- key_rx = re.compile(
- '(?x) ^ spline-frontpage [.] sources [.] (\w+) (?: [.] (\w+) )? $')
- for key, val in config.iteritems():
- match = key_rx.match(key)
- if not match:
- continue
-
- source_name, subkey = match.groups()
- if not subkey:
- # This is the type declaration; use a special key
- subkey = '__type__'
-
- if subkey in ('limit', 'max_age'):
- val = int(val)
- update_config[source_name][subkey] = val
-
- global_limit = int(config.get('spline-frontpage.limit', 10))
- now = datetime.datetime.now()
- try:
- global_max_age = now - datetime.timedelta(
- seconds=int(config['spline-frontpage.max_age']))
- except KeyError:
- global_max_age = None
-
- # Ask plugins to deal with this stuff for us!
- updates = []
- for source, source_config in update_config.iteritems():
- hook_name = 'frontpage_updates_' + source_config['__type__']
-
- # Merge with the global config
- merged_config = source_config.copy()
- del merged_config['__type__']
-
- merged_config['limit'] = min(
- merged_config.get('limit', global_limit),
- global_limit,
- )