2009-01-21 01:11:01 +01:00
|
|
|
# -*- python -*-
|
|
|
|
# -*- coding: utf8 -*-
|
2009-01-21 16:11:39 +01:00
|
|
|
#
|
|
|
|
# DDPortfolio service url builder
|
|
|
|
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info>
|
|
|
|
#
|
|
|
|
# This file is part of DDPortfolio service.
|
|
|
|
#
|
|
|
|
# DDPortfolio service is free software: you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Affero General Public License
|
|
|
|
# as published by the Free Software Foundation, either version 3 of
|
|
|
|
# the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# DDPortfolio service is distributed in the hope that it will be
|
|
|
|
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public
|
|
|
|
# License along with this program. If not, see
|
|
|
|
# <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
"""
|
|
|
|
This module provides the function build_urls to build personalized
|
|
|
|
URLs using the given information and the URL patterns defined in
|
|
|
|
ddportfolio.ini.
|
|
|
|
"""
|
2009-01-21 01:11:01 +01:00
|
|
|
|
2009-01-22 21:06:23 +01:00
|
|
|
from ConfigParser import ConfigParser, InterpolationMissingOptionError
|
2009-01-21 01:11:01 +01:00
|
|
|
import pkg_resources
|
2009-01-21 21:16:54 +01:00
|
|
|
from ddportfolioservice.model import keyfinder
|
2009-01-21 01:11:01 +01:00
|
|
|
from urllib import quote_plus
|
2009-01-22 21:06:23 +01:00
|
|
|
from pylons.i18n.translation import _, N_
|
2009-01-21 01:11:01 +01:00
|
|
|
|
2009-01-22 17:34:46 +01:00
|
|
|
|
2009-01-22 21:06:23 +01:00
|
|
|
my_config = ConfigParser()
|
2009-01-21 01:11:01 +01:00
|
|
|
my_config.readfp(pkg_resources.resource_stream(__name__, 'ddportfolio.ini'))
|
|
|
|
|
2009-01-22 21:06:23 +01:00
|
|
|
_FIELDNAMES_MAP = {
|
2009-01-22 21:45:04 +01:00
|
|
|
'email' : N_('Email address'),
|
2009-01-22 21:06:23 +01:00
|
|
|
'name' : N_('Name'),
|
|
|
|
'gpgfp' : N_('GPG fingerprint'),
|
|
|
|
'username' : N_('Debian user name'),
|
2009-01-22 21:45:04 +01:00
|
|
|
'nonddemail' : N_('Non DD email address'),
|
2009-01-22 21:06:23 +01:00
|
|
|
'aliothusername' : N_('Alioth user name'),
|
|
|
|
}
|
|
|
|
|
2009-01-21 01:11:01 +01:00
|
|
|
|
|
|
|
def build_urls(fields):
|
|
|
|
"""Build personalized URLs using the developer information in
|
|
|
|
fields."""
|
2009-01-22 17:34:46 +01:00
|
|
|
data = []
|
2009-01-21 21:54:15 +01:00
|
|
|
qfields = dict([(key, quote_plus(fields[key].encode('utf8'))) \
|
2009-01-22 21:06:23 +01:00
|
|
|
for key in fields if fields[key] is not None])
|
|
|
|
if 'gpgfp' not in qfields:
|
|
|
|
fpr = keyfinder.getFingerprintByEmail(fields['email'].encode('utf8'))
|
|
|
|
if fpr:
|
|
|
|
qfields['gpgfp'] = fpr[0]
|
2009-01-22 17:34:46 +01:00
|
|
|
for section in [section.strip() for section in \
|
|
|
|
my_config.get('DEFAULT',
|
|
|
|
'urlbuilder.sections').split(',')]:
|
|
|
|
data.append(['section', section])
|
2009-01-21 01:11:01 +01:00
|
|
|
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:
|
2009-01-22 17:34:46 +01:00
|
|
|
data.append(
|
|
|
|
['url', section, url,
|
|
|
|
my_config.get(section, url + '.pattern',
|
|
|
|
False, qfields)])
|
2009-01-22 21:06:23 +01:00
|
|
|
except InterpolationMissingOptionError, e:
|
|
|
|
data.append(['error', section, url,
|
2009-01-22 21:45:04 +01:00
|
|
|
_('Missing input: %s') % \
|
2009-01-22 21:06:23 +01:00
|
|
|
_(_FIELDNAMES_MAP[e.reference])])
|
2009-01-22 17:34:46 +01:00
|
|
|
return data
|