Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1373

Show
Ignore:
Timestamp:
09/22/06 20:26:45
Author:
fumanchu
Message:

New _cpconfig.check_compatibility function.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpconfig.py

    r1369 r1373  
    7878 
    7979import ConfigParser 
     80from warnings import warn 
     81 
    8082import cherrypy 
    8183 
     
    101103    } 
    102104 
     105def as_dict(config): 
     106    """Return a dict from 'config' whether it is a dict, file, or filename.""" 
     107    if isinstance(config, basestring): 
     108        config = _Parser().dict_from_file(config) 
     109    elif hasattr(config, 'read'): 
     110        config = _Parser().dict_from_file(config) 
     111    return config 
     112 
    103113def merge(base, other): 
    104     """Merge one app config (from a dict, file, or filename) into another.""" 
     114    """Merge one app config (from a dict, file, or filename) into another. 
     115     
     116    If the given config is a filename, it will be appended to 
     117    cherrypy.engine.reload_files and monitored for changes. 
     118    """ 
    105119    if isinstance(other, basestring): 
    106120        if other not in cherrypy.engine.reload_files: 
    107121            cherrypy.engine.reload_files.append(other) 
    108         other = _Parser().dict_from_file(other) 
    109     elif hasattr(other, 'read'): 
    110         other = _Parser().dict_from_file(other) 
    111122     
    112123    # Load other into base 
    113     for section, value_map in other.iteritems(): 
     124    for section, value_map in as_dict(other).iteritems(): 
    114125        base.setdefault(section, {}).update(value_map) 
    115126 
     
    174185        if namespace in self.namespaces: 
    175186            self.namespaces[namespace](atoms[1], v) 
     187 
     188 
     189obsolete = { 
     190    'server.default_content_type': 'tools.response_headers.headers', 
     191    'log_access_file': 'log.access_file', 
     192    'log_config_options': None, 
     193    'log_file': 'log.error_file', 
     194    'log_file_not_found': None, 
     195    'log_request_headers': 'tools.log_headers.on', 
     196    'log_to_screen': 'log.screen', 
     197    'show_tracebacks': 'request.show_tracebacks', 
     198    'throw_errors': 'request.throw_errors', 
     199    'profiler.on': 'cherrypy.tree.mount(profiler.make_app(cherrypy.Application(Root())))', 
     200    } 
     201 
     202deprecated = {} 
     203 
     204def check_compatibility(config): 
     205    """Process config and warn on each obsolete or deprecated entry.""" 
     206    for section, map in as_dict(config).iteritems(): 
     207        if isinstance(map, dict): 
     208            for k, v in map.iteritems(): 
     209                if k in obsolete: 
     210                    warn("%r is obsolete. Use %r instead." % (k, v)) 
     211                elif k in deprecated: 
     212                    warn("%r is deprecated. Use %r instead." % (k, v)) 
     213        else: 
     214            if section in obsolete: 
     215                warn("%r is obsolete. Use %r instead." % (section, map)) 
     216            elif section in deprecated: 
     217                warn("%r is deprecated. Use %r instead." % (section, map)) 
    176218 
    177219 

Hosted by WebFaction

Log in as guest/cpguest to create tickets