31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
|
# -*- python -*-
|
||
|
# -*- coding: utf8 -*-
|
||
|
|
||
|
import ConfigParser
|
||
|
import pkg_resources
|
||
|
from urllib import quote_plus
|
||
|
|
||
|
my_config = ConfigParser.ConfigParser()
|
||
|
my_config.readfp(pkg_resources.resource_stream(__name__, 'ddportfolio.ini'))
|
||
|
|
||
|
|
||
|
def build_urls(fields):
|
||
|
"""Build personalized URLs using the developer information in
|
||
|
fields."""
|
||
|
data = {}
|
||
|
errors = {}
|
||
|
qfields = dict([(key, quote_plus(fields[key])) for key in fields])
|
||
|
for section in my_config.sections():
|
||
|
if my_config.has_option(section, 'urls'):
|
||
|
for url in my_config.get(section, 'urls').split(','):
|
||
|
if my_config.has_option(section, url + '.pattern'):
|
||
|
try:
|
||
|
data[section + '.' + url] = \
|
||
|
my_config.get(section, url + '.pattern',
|
||
|
False, qfields)
|
||
|
except Exception, e:
|
||
|
errors['%s.%s.pattern' % (section, url)] = \
|
||
|
[my_config.get(section, '%s.pattern' % url,
|
||
|
True), str(e)]
|
||
|
return {'data' : data, 'errors' : errors}
|