"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/config.py" between
viewvc-1.1.28.tar.gz and viewvc-1.2.1.tar.gz

About: ViewVC is a browser interface for CVS and Subversion version control repositories.

config.py  (viewvc-1.1.28):config.py  (viewvc-1.2.1)
skipping to change at line 19 skipping to change at line 19
# For more information, visit http://viewvc.org/ # For more information, visit http://viewvc.org/
# #
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# #
# config.py: configuration utilities # config.py: configuration utilities
# #
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
import sys import sys
import os import os
import string
import ConfigParser import ConfigParser
import fnmatch import fnmatch
######################################################################### #########################################################################
# #
# CONFIGURATION # CONFIGURATION
# ------------- # -------------
# #
# There are three forms of configuration: # There are three forms of configuration:
# #
skipping to change at line 56 skipping to change at line 55
# 2. vhost overrides - these options overlay/override the base # 2. vhost overrides - these options overlay/override the base
# configuration on a per-vhost basis. # configuration on a per-vhost basis.
# 3. root overrides - these options overlay/override the base # 3. root overrides - these options overlay/override the base
# configuration and vhost overrides on a per-root basis. # configuration and vhost overrides on a per-root basis.
# #
# Here's a diagram of the valid overlays/overrides: # Here's a diagram of the valid overlays/overrides:
# #
# PER-ROOT PER-VHOST BASE # PER-ROOT PER-VHOST BASE
# #
# ,-----------. ,-----------. # ,-----------. ,-----------.
# | vhost-*/ | | | # | vhost-*| | | |
# | general | --> | general | # | general | --> | general |
# | | | | # | | | |
# `-----------' `-----------' # `-----------' `-----------'
# ,-----------. ,-----------. ,-----------. # ,-----------. ,-----------. ,-----------.
# | root-*/ | | vhost-*/ | | | # | root-*| | | vhost-*| | | |
# | options | --> | options | --> | options | # | options | --> | options | --> | options |
# | | | | | | # | | | | | |
# `-----------' `-----------' `-----------' # `-----------' `-----------' `-----------'
# ,-----------. ,-----------. ,-----------. # ,-----------. ,-----------. ,-----------.
# | root-*/ | | vhost-*/ | | | # | root-*| | | vhost-*| | | |
# | templates | --> | templates | --> | templates | # | templates | --> | templates | --> | templates |
# | | | | | | # | | | | | |
# `-----------' `-----------' `-----------' # `-----------' `-----------' `-----------'
# ,-----------. ,-----------. ,-----------. # ,-----------. ,-----------. ,-----------.
# | root-*/ | | vhost-*/ | | | # | root-*| | | vhost-*| | | |
# | utilities | --> | utilities | --> | utilities | # | utilities | --> | utilities | --> | utilities |
# | | | | | | # | | | | | |
# `-----------' `-----------' `-----------' # `-----------' `-----------' `-----------'
# ,-----------. ,-----------. # ,-----------. ,-----------.
# | vhost-*/ | | | # | vhost-*| | | |
# | cvsdb | --> | cvsdb | # | cvsdb | --> | cvsdb |
# | | | | # | | | |
# `-----------' `-----------' # `-----------' `-----------'
# ,-----------. ,-----------. ,-----------. # ,-----------. ,-----------. ,-----------.
# | root-*/ | | vhost-*/ | | | # | root-*| | | vhost-*| | | |
# | authz-* | --> | authz-* | --> | authz-* | # | authz-* | --> | authz-* | --> | authz-* |
# | | | | | | # | | | | | |
# `-----------' `-----------' `-----------' # `-----------' `-----------' `-----------'
# ,-----------. # ,-----------.
# | | # | |
# | vhosts | # | vhosts |
# | | # | |
# `-----------' # `-----------'
# ,-----------. # ,-----------.
# | | # | |
skipping to change at line 115 skipping to change at line 114
'general', 'general',
'options', 'options',
'query', 'query',
'templates', 'templates',
'utilities', 'utilities',
) )
_force_multi_value = ( _force_multi_value = (
# Configuration values with multiple, comma-separated values. # Configuration values with multiple, comma-separated values.
'allowed_views', 'allowed_views',
'binary_mime_types', 'binary_mime_types',
'dir_ignored_files',
'custom_log_formatting', 'custom_log_formatting',
'cvs_roots', 'cvs_roots',
'kv_files', 'kv_files',
'languages', 'languages',
'mime_types_files', 'mime_types_files',
'root_parents', 'root_parents',
'svn_roots', 'svn_roots',
'renamed_roots', 'renamed_roots',
) )
_allowed_overrides = { _allowed_overrides = {
skipping to change at line 175 skipping to change at line 175
def load_kv_files(self, language): def load_kv_files(self, language):
"""Process the key/value (kv) files specified in the """Process the key/value (kv) files specified in the
configuration, merging their values into the configuration as configuration, merging their values into the configuration as
dotted heirarchical items.""" dotted heirarchical items."""
kv = _sub_config() kv = _sub_config()
for fname in self.general.kv_files: for fname in self.general.kv_files:
if fname[0] == '[': if fname[0] == '[':
idx = string.index(fname, ']') idx = fname.index(']')
parts = string.split(fname[1:idx], '.') parts = fname[1:idx].split('.')
fname = string.strip(fname[idx+1:]) fname = fname[idx+1:].strip()
else: else:
parts = [ ] parts = [ ]
fname = string.replace(fname, '%lang%', language) fname = fname.replace('%lang%', language)
parser = ConfigParser.ConfigParser() parser = ConfigParser.ConfigParser()
parser.optionxform = lambda x: x # don't case-normalize option names. parser.optionxform = lambda x: x # don't case-normalize option names.
parser.read(os.path.join(self.base, fname)) parser.read(os.path.join(self.base, fname))
for section in parser.sections(): for section in parser.sections():
for option in parser.options(section): for option in parser.options(section):
full_name = parts + [section] full_name = parts + [section]
ob = kv ob = kv
for name in full_name: for name in full_name:
try: try:
skipping to change at line 212 skipping to change at line 212
return os.path.join(self.base, path) return os.path.join(self.base, path)
def _process_section(self, parser, section, subcfg_name): def _process_section(self, parser, section, subcfg_name):
if not hasattr(self, subcfg_name): if not hasattr(self, subcfg_name):
setattr(self, subcfg_name, _sub_config()) setattr(self, subcfg_name, _sub_config())
sc = getattr(self, subcfg_name) sc = getattr(self, subcfg_name)
for opt in parser.options(section): for opt in parser.options(section):
value = parser.get(section, opt) value = parser.get(section, opt)
if opt in self._force_multi_value: if opt in self._force_multi_value:
value = map(string.strip, filter(None, string.split(value, ','))) value = map(lambda x: x.strip(), filter(None, value.split(',')))
else: else:
try: try:
value = int(value) value = int(value)
except ValueError: except ValueError:
pass pass
### FIXME: This feels like unnecessary depth of knowledge for a ### FIXME: This feels like unnecessary depth of knowledge for a
### semi-generic configuration object. ### semi-generic configuration object.
if opt == 'cvs_roots' or opt == 'svn_roots' or opt == 'renamed_roots': if opt == 'cvs_roots' or opt == 'svn_roots' or opt == 'renamed_roots':
value = _parse_roots(opt, value) value = _parse_roots(opt, value)
skipping to change at line 247 skipping to change at line 247
return 0 return 0
def _is_allowed_override(self, sectype, secspec, section): def _is_allowed_override(self, sectype, secspec, section):
"""Test if SECTION is an allowed override section for sections of """Test if SECTION is an allowed override section for sections of
type SECTYPE ('vhosts' or 'root', currently) and type-specifier type SECTYPE ('vhosts' or 'root', currently) and type-specifier
SECSPEC (a rootname or vhostname, currently). If it is, return SECSPEC (a rootname or vhostname, currently). If it is, return
the overridden base section name. If it's not an override section the overridden base section name. If it's not an override section
at all, return None. And if it's an override section but not an at all, return None. And if it's an override section but not an
allowed one, raise IllegalOverrideSection.""" allowed one, raise IllegalOverrideSection."""
cv = '%s-%s/' % (sectype, secspec) cv = '%s-%s|' % (sectype, secspec)
lcv = len(cv) lcv = len(cv)
if section[:lcv] != cv: if section[:lcv] != cv:
return None return None
base_section = section[lcv:] base_section = section[lcv:]
if self._is_allowed_section(base_section, if self._is_allowed_section(base_section,
self._allowed_overrides[sectype]): self._allowed_overrides[sectype]):
return base_section return base_section
raise IllegalOverrideSection(sectype, section) raise IllegalOverrideSection(sectype, section)
def _process_vhost(self, parser, vhost): def _process_vhost(self, parser, vhost):
skipping to change at line 270 skipping to change at line 270
if not canon_vhost: if not canon_vhost:
return return
# Overlay any option sections associated with this vhost name. # Overlay any option sections associated with this vhost name.
for section in parser.sections(): for section in parser.sections():
base_section = self._is_allowed_override('vhost', canon_vhost, section) base_section = self._is_allowed_override('vhost', canon_vhost, section)
if base_section: if base_section:
self._process_section(parser, section, base_section) self._process_section(parser, section, base_section)
def _find_canon_vhost(self, parser, vhost): def _find_canon_vhost(self, parser, vhost):
vhost = string.split(string.lower(vhost), ':')[0] # lower-case, no port vhost = vhost.lower().split(':')[0] # lower-case, no port
for canon_vhost in parser.options('vhosts'): for canon_vhost in parser.options('vhosts'):
value = parser.get('vhosts', canon_vhost) value = parser.get('vhosts', canon_vhost)
patterns = map(string.lower, map(string.strip, patterns = map(lambda x: x.lower().strip(),
filter(None, string.split(value, ',')))) filter(None, value.split(',')))
for pat in patterns: for pat in patterns:
if fnmatch.fnmatchcase(vhost, pat): if fnmatch.fnmatchcase(vhost, pat):
return canon_vhost return canon_vhost
return None return None
def overlay_root_options(self, rootname): def overlay_root_options(self, rootname):
"""Overlay per-root options for ROOTNAME atop the existing option """Overlay per-root options for ROOTNAME atop the existing option
set. This is a destructive change to the configuration.""" set. This is a destructive change to the configuration."""
skipping to change at line 337 skipping to change at line 337
# We assume that per-root options have *not* been overlayed. # We assume that per-root options have *not* been overlayed.
assert(self.root_options_overlayed == 0) assert(self.root_options_overlayed == 0)
if not self.conf_path: if not self.conf_path:
return None, {} return None, {}
# Figure out the authorizer by searching first for a per-root # Figure out the authorizer by searching first for a per-root
# override, then falling back to the base/vhost configuration. # override, then falling back to the base/vhost configuration.
authorizer = None authorizer = None
root_options_section = 'root-%s/options' % (rootname) root_options_section = 'root-%s|options' % (rootname)
if self.parser.has_section(root_options_section) \ if self.parser.has_section(root_options_section) \
and self.parser.has_option(root_options_section, 'authorizer'): and self.parser.has_option(root_options_section, 'authorizer'):
authorizer = self.parser.get(root_options_section, 'authorizer') authorizer = self.parser.get(root_options_section, 'authorizer')
if not authorizer: if not authorizer:
authorizer = self.options.authorizer authorizer = self.options.authorizer
# No authorizer? Get outta here. # No authorizer? Get outta here.
if not authorizer: if not authorizer:
return None, {} return None, {}
# Dig up the parameters for the authorizer, starting with the # Dig up the parameters for the authorizer, starting with the
# base/vhost items, then overlaying any root-specific ones we find. # base/vhost items, then overlaying any root-specific ones we find.
params = {} params = {}
authz_section = 'authz-%s' % (authorizer) authz_section = 'authz-%s' % (authorizer)
if hasattr(self, authz_section): if hasattr(self, authz_section):
sub_config = getattr(self, authz_section) sub_config = getattr(self, authz_section)
for attr in dir(sub_config): for attr in dir(sub_config):
params[attr] = getattr(sub_config, attr) params[attr] = getattr(sub_config, attr)
root_authz_section = 'root-%s/authz-%s' % (rootname, authorizer) root_authz_section = 'root-%s|authz-%s' % (rootname, authorizer)
for section in self.parser.sections(): for section in self.parser.sections():
if section == root_authz_section: if section == root_authz_section:
for key, value in self._get_parser_items(self.parser, section): for key, value in self._get_parser_items(self.parser, section):
params[key] = value params[key] = value
return authorizer, params return authorizer, params
def get_authorizer_params(self, authorizer=None): def get_authorizer_params(self, authorizer=None):
"""Return a dictionary of parameter names and values which belong """Return a dictionary of parameter names and values which belong
to the configured authorizer (or AUTHORIZER, if provided).""" to the configured authorizer (or AUTHORIZER, if provided)."""
params = {} params = {}
skipping to change at line 395 skipping to change at line 395
self.general.mime_types_files = ["mimetypes.conf"] self.general.mime_types_files = ["mimetypes.conf"]
self.general.address = '' self.general.address = ''
self.general.kv_files = [ ] self.general.kv_files = [ ]
self.general.languages = ['en-us'] self.general.languages = ['en-us']
self.utilities.rcs_dir = '' self.utilities.rcs_dir = ''
if sys.platform == "win32": if sys.platform == "win32":
self.utilities.cvsnt = 'cvs' self.utilities.cvsnt = 'cvs'
else: else:
self.utilities.cvsnt = None self.utilities.cvsnt = None
self.utilities.svn = ''
self.utilities.diff = '' self.utilities.diff = ''
self.utilities.cvsgraph = '' self.utilities.cvsgraph = ''
self.options.root_as_url_component = 1 self.options.root_as_url_component = 1
self.options.checkout_magic = 0 self.options.checkout_magic = 0
self.options.allowed_views = ['annotate', 'diff', 'markup', 'roots'] self.options.allowed_views = ['annotate', 'diff', 'markup', 'roots']
self.options.authorizer = None self.options.authorizer = None
self.options.mangle_email_addresses = 0 self.options.mangle_email_addresses = 0
self.options.custom_log_formatting = [] self.options.custom_log_formatting = []
self.options.default_file_view = "log" self.options.default_file_view = "log"
self.options.binary_mime_types = [] self.options.binary_mime_types = []
self.options.dir_ignored_files = []
self.options.http_expiration_time = 600 self.options.http_expiration_time = 600
self.options.generate_etags = 1 self.options.generate_etags = 1
self.options.svn_ignore_mimetype = 0 self.options.svn_ignore_mimetype = 0
self.options.svn_config_dir = None self.options.svn_config_dir = None
self.options.max_filesize_kbytes = 512 self.options.max_filesize_kbytes = 512
self.options.use_rcsparse = 0 self.options.use_rcsparse = 0
self.options.sort_by = 'file' self.options.sort_by = 'file'
self.options.sort_group_dirs = 1 self.options.sort_group_dirs = 1
self.options.hide_attic = 1 self.options.hide_attic = 1
self.options.hide_errorful_entries = 0 self.options.hide_errorful_entries = 0
self.options.log_sort = 'date' self.options.log_sort = 'date'
self.options.diff_format = 'h' self.options.diff_format = 'h'
self.options.hide_cvsroot = 1 self.options.hide_cvsroot = 1
self.options.hr_breakable = 1 self.options.hr_breakable = 1
self.options.hr_funout = 1 self.options.hr_funout = 1
self.options.hr_ignore_white = 0 self.options.hr_ignore_white = 0
self.options.hr_ignore_keyword_subst = 1 self.options.hr_ignore_keyword_subst = 1
self.options.hr_intraline = 0 self.options.hr_intraline = 0
self.options.allow_compress = 0 self.options.allow_compress = 0
self.options.template_dir = "templates" self.options.template_dir = "templates/default"
self.options.docroot = None self.options.docroot = None
self.options.show_subdir_lastmod = 0 self.options.show_subdir_lastmod = 0
self.options.show_roots_lastmod = 0 self.options.show_roots_lastmod = 0
self.options.show_logs = 1 self.options.show_logs = 1
self.options.show_log_in_markup = 1 self.options.show_log_in_markup = 1
self.options.cross_copies = 1 self.options.cross_copies = 1
self.options.use_localtime = 0 self.options.use_localtime = 0
self.options.iso8601_timestamps = 0 self.options.iso8601_timestamps = 0
self.options.short_log_len = 80 self.options.short_log_len = 80
self.options.enable_syntax_coloration = 1 self.options.enable_syntax_coloration = 1
self.options.tabsize = 8 self.options.tabsize = 8
self.options.detect_encoding = 0 self.options.detect_encoding = 0
self.options.use_cvsgraph = 0 self.options.use_cvsgraph = 0
self.options.cvsgraph_conf = "cvsgraph.conf" self.options.cvsgraph_conf = "cvsgraph.conf"
self.options.allowed_cvsgraph_useropts = []
self.options.use_re_search = 0 self.options.use_re_search = 0
self.options.dir_pagesize = 0 self.options.dir_pagesize = 0
self.options.log_pagesize = 0 self.options.log_pagesize = 0
self.options.log_pagesextra = 3 self.options.log_pagesextra = 3
self.options.limit_changes = 100 self.options.limit_changes = 100
self.options.stacktraces = 0 self.options.stacktraces = 0
self.templates.diff = None self.templates.diff = None
self.templates.directory = None self.templates.directory = None
self.templates.error = None self.templates.error = None
self.templates.file = None self.templates.file = None
self.templates.graph = None self.templates.graph = None
self.templates.log = None self.templates.log = None
self.templates.query = None
self.templates.query_form = None self.templates.query_form = None
self.templates.query_results = None self.templates.query_results = None
self.templates.roots = None self.templates.roots = None
self.cvsdb.enabled = 0 self.cvsdb.enabled = 0
self.cvsdb.host = '' self.cvsdb.host = ''
self.cvsdb.port = 3306 self.cvsdb.port = 3306
self.cvsdb.database_name = '' self.cvsdb.database_name = ''
self.cvsdb.user = '' self.cvsdb.user = ''
self.cvsdb.passwd = '' self.cvsdb.passwd = ''
self.cvsdb.readonly_user = '' self.cvsdb.readonly_user = ''
self.cvsdb.readonly_passwd = '' self.cvsdb.readonly_passwd = ''
self.cvsdb.row_limit = 1000 self.cvsdb.row_limit = 1000
self.cvsdb.rss_row_limit = 100 self.cvsdb.rss_row_limit = 100
self.cvsdb.check_database_for_root = 0 self.cvsdb.check_database_for_root = 0
self.query.viewvc_base_url = None
def _startswith(somestr, substr): def _startswith(somestr, substr):
return somestr[:len(substr)] == substr return somestr[:len(substr)] == substr
def _parse_roots(config_name, config_value): def _parse_roots(config_name, config_value):
roots = { } roots = { }
for root in config_value: for root in config_value:
pos = string.find(root, ':') try:
if pos < 0: name, path = root.split(':', 1)
except:
raise MalformedRoot(config_name, root) raise MalformedRoot(config_name, root)
name, path = map(string.strip, (root[:pos], root[pos+1:])) roots[name.strip()] = path.strip()
roots[name] = path
return roots return roots
class ViewVCConfigurationError(Exception): class ViewVCConfigurationError(Exception):
pass pass
class IllegalOverrideSection(ViewVCConfigurationError): class IllegalOverrideSection(ViewVCConfigurationError):
def __init__(self, override_type, section_name): def __init__(self, override_type, section_name):
self.section_name = section_name self.section_name = section_name
self.override_type = override_type self.override_type = override_type
def __str__(self): def __str__(self):
skipping to change at line 508 skipping to change at line 506
def __init__(self, config_name, value_given): def __init__(self, config_name, value_given):
Exception.__init__(self, config_name, value_given) Exception.__init__(self, config_name, value_given)
self.config_name = config_name self.config_name = config_name
self.value_given = value_given self.value_given = value_given
def __str__(self): def __str__(self):
return "malformed configuration: '%s' uses invalid syntax: %s" \ return "malformed configuration: '%s' uses invalid syntax: %s" \
% (self.config_name, self.value_given) % (self.config_name, self.value_given)
class _sub_config: class _sub_config:
pass pass
if not hasattr(sys, 'hexversion'):
# Python 1.5 or 1.5.1. fix the syntax for ConfigParser options.
import regex
ConfigParser.option_cre = regex.compile('^\([-A-Za-z0-9._]+\)\(:\|['
+ string.whitespace
+ ']*=\)\(.*\)$')
 End of changes. 25 change blocks. 
27 lines changed or deleted 25 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)