Changeset 5

Show
Ignore:
Timestamp:
07/24/06 15:04:54 (2 years ago)
Author:
johnbywater
Message:

Renamed kforge.system to kforge.dictionary.
Replaced inheritance with delgation in respect of dictionary configuration.
Added test, admin, and sdist utilities.
Added django settings (needed for views).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/dm/builder.py

    r2 r5  
    2020 
    2121    def findSystemDictionary(self): 
    22         import dm.system 
    23         return dm.system.SystemDictionary('kforge'
     22        import dm.dictionary 
     23        return dm.dictionary.SystemDictionary(
    2424 
    2525    def findDebug(self): 
  • trunk/src/dm/config.py

    r2 r5  
    1 import os 
    2 import re 
    31import ConfigParser 
    42 
    5 class DictionaryConfigParser(ConfigParser.SafeConfigParser): 
    6     """ConfigParser object with alternative dictionary-like interface. 
    7     """ 
     3class ConfigFileReader(ConfigParser.SafeConfigParser): 
     4    "Presents config files as a dictionary of name-value pairs." 
    85 
    96    def __init__(self): 
    10         # new style super doesn't work... 
    11         # super(SystemDictionary, self).__init__() 
    127        ConfigParser.SafeConfigParser.__init__(self) 
    138     
    14     def _convert_key(self, key): 
    15         tindex = key.find('.') 
    16         if tindex == -1: 
     9    def __getitem__(self, key): 
     10        sectionName, valueName = self.convertKey(key) 
     11        return self.get(sectionName, valueName) 
     12 
     13    def __setitem__(self, key, value): 
     14        sectionName, valueName = self.convertKey(key) 
     15        if sectionName not in self.getSectionNames(): 
     16            self.add_section(sectionName) 
     17        self.set(sectionName, valueName, value) 
     18 
     19    def has_key(self, key): 
     20        sectionName, valueName = self.convertKey(key) 
     21        if sectionName in self.getSectionNames(): 
     22            return self.has_option(sectionName, valueName) 
     23        else: 
     24            return False 
     25 
     26    def convertKey(self, key): 
     27        index = key.find('.') 
     28        if index == -1: 
    1729            sectionName = 'DEFAULT' 
    1830            optionName = key 
    1931        else: 
    20             sectionName = key[:tindex] 
    21             optionName = key[tindex+1:] 
     32            sectionName = key[:index] 
     33            optionName = key[index+1:] 
    2234        return (sectionName, optionName) 
    2335 
    24     def __getitem__(self, y): 
    25         section, option = self._convert_key(y) 
    26         return self.get(section, option) 
    27  
    28     def __setitem__(self, i, y): 
    29         section, option = self._convert_key(i) 
    30         if section not in self.sections() + [ 'DEFAULT' ]: 
    31             self.add_section(section) 
    32         self.set(section, option, y) 
    33  
    34     def has_key(self, keyname): 
    35         sect, opt = self._convert_key(keyname) 
    36         if sect in self.sections() + [ 'DEFAULT' ]: 
    37             return self.has_option(sect, opt) 
    38         else: return False 
     36    def getSectionNames(self): 
     37        return self.sections() + ['DEFAULT'] 
    3938 
    4039    def keys(self): 
    41         results = self.defaults().keys() 
    42         for section in self.sections(): 
    43             tres = self.options(section) 
    44             tres = [ section + '.' + xx for xx in tres] 
    45             results += tres 
    46         return results 
    47            
     40        keys = self.defaults().keys() 
     41        for sectionName in self.sections(): 
     42            valueName = self.options(sectionName) 
     43            # todo: resolve query regarding iteration: 
     44            # (johnbywater) i don't understand the need for iteration 
     45            # here -- aren't we iterating over the chars in a string? 
     46            key = [sectionName + '.' + xx for xx in valueName] # why? :-) 
     47            #key = [sectionName + '.' + str(valueName)]        # why not? 
     48            keys += key 
     49        return keys 
    4850 
    49 # todo: change from `isa' to `hasa' DictionaryConfigParser 
    50 # todo: fix up the methods to new style super() 
    51 # (rgrp) No: this is a bad idea and is what he had before 
    52 # ConfigParser is the python provided object for doing what we want and  
    53 # we should use it. We are simply providing a minimal interface layer on 
    54 # top of it and there is no reason we should replicate much of the ConfigParser 
    55 # interface again in our object 
    56 # (which is what would be necessary if we do not inherit) 
    57 # (johnbywater) No: This is an obvious case of "dict at once has-a parser and 
    58 # is-not-a parser" so it should aggregate a parser and use it, rather than 
    59 # inheriting from it, which is stupid. There is no need to replicate much of 
    60 # the parser interface in the dict because the dict is not a parser (as above). 
    61  
    62 class SystemDictionary(DictionaryConfigParser): 
    63     """Dictionary of system attributes. 
    64     """ 
    65  
    66     def __init__(self, applicationName): 
    67         # new style super() doesn't work... 
    68         #super(SystemDictionary).__init__(applicationName) 
    69         DictionaryConfigParser.__init__(self) 
    70         self.applicationName = applicationName 
    71         self.readEnvironment() 
    72         self.setDefaultWords() 
    73         self.readConfigFiles() 
    74  
    75     def readEnvironment(self): 
    76         self.systemRootPath = self.makeSystemRootPath() 
    77         self.etcPath        = self.makeEtcPath() 
    78  
    79     def setDefaultWords(self): 
    80         self['system_root']     = self.systemRootPath 
    81         self['application']     = self.applicationName  
    82         self['etcdir']          = self.etcPath  
    83         self['system_mode']     = 'production' 
    84         self['visitor']         = 'visitor' 
    85         self['visitor_role']    = 'Visitor' 
    86         self['person_role']     = 'Visitor' 
    87         self['pythonpath']      = os.environ.get('PYTHONPATH', '') 
    88         self['vardir']          = os.path.join(self['system_root'], 'var') 
    89         self['plugin_data_dir'] = os.path.join(self['vardir'], 'plugin_data') 
    90         self['plugin_package']  = 'dm.plugin' 
    91         self['captcha.enable']  = '' # False (ConfigParser only supports str)   
    92         self['__version__']     = self.getSystemVersion() 
    93  
    94     def getSystemVersion(self): 
    95         return '' 
    96  
    97     def makeSystemRootPath(self): 
    98         "Returns base application path." 
    99         ENV_SYSTEM_ROOT = self.applicationName.upper() + 'HOME' 
    100         try: 
    101             path = os.environ[ENV_SYSTEM_ROOT] 
    102         except: 
    103             path = os.path.join( 
    104                 os.environ['HOME'], 
    105                 self.applicationName 
    106             ) 
    107         if not os.path.isdir(path): 
    108             raise EnvironmentError, 'System root dir not found: ' + path 
    109         return path 
    110  
    111     def readConfigFiles(self): 
    112         configPath = self.makeConfigPath() 
    113         configPaths = [configPath] 
    114         self.read(configPaths) 
    115  
    116     def makeConfigPath(self): 
    117         fileName = '%s.conf' % self.applicationName 
    118         path = os.path.join( 
    119             self.etcPath, 
    120             fileName 
    121         ) 
    122         return path 
    123  
    124     def makeEtcPath(self): 
    125         path = os.path.join( 
    126             self.systemRootPath, 
    127             'etc' 
    128         ) 
    129         return path 
    130  
  • trunk/src/dm/log.py

    r2 r5  
    11""" 
    2 KForge logger. 
     2Logger. 
     3 
    34""" 
    45 
     
    67import logging.handlers 
    78import os 
     9from dm.ioc import RequiredFeature 
    810 
    9 DICTWORD_LOG_PATH    = 'logging.log_file' 
    10 DICTWORD_LOG_LEVEL  = 'logging.level' 
    11 DICTWORD_APPLICATION = 'application
     11DICTWORD_LOGGING_PATH = 'logging.log_file' 
     12DICTWORD_LOGGING_LEVEL = 'logging.level' 
     13DICTWORD_SYSTEM_NAME = 'system_name
    1214 
    13 from dm.ioc import * 
    1415 
    1516def getLogger(): 
     
    1920    """ 
    2021    dictionary = RequiredFeature('SystemDictionary') 
    21     applicationName = dictionary[DICTWORD_APPLICATION
    22     return logging.getLogger(applicationName) 
     22    systemName = dictionary[DICTWORD_SYSTEM_NAME
     23    return logging.getLogger(systemName) 
    2324  
    2425def initLogging(): 
     
    3233    """ 
    3334    dictionary = RequiredFeature('SystemDictionary') 
    34     logPath = dictionary[DICTWORD_LOG_PATH] 
     35    logPath = dictionary[DICTWORD_LOGGING_PATH] 
    3536    logLevel = logging.INFO 
    3637    logLevels = { 
     
    4142        'CRITICAL' : logging.CRITICAL 
    4243    } 
    43     logLevelName = dictionary[DICTWORD_LOG_LEVEL] 
     44    logLevelName = dictionary[DICTWORD_LOGGING_LEVEL] 
    4445    if logLevelName in logLevels: 
    4546        logLevel = logLevels[logLevelName] 
     
    6768     
    6869    rootLogger = logging.getLogger('') 
    69     applicationName = dictionary[DICTWORD_APPLICATION
    70     applicationLogger = logging.getLogger(applicationName) 
     70    systemName = dictionary[DICTWORD_SYSTEM_NAME
     71    systemLogger = logging.getLogger(systemName) 
    7172    rootLogger.addHandler(consoleHandler) 
    72     applicationLogger.addHandler(fileHandler) 
     73    systemLogger.addHandler(fileHandler) 
    7374    # setting this level seems to have no effect 
    7475    # i.e. debug events from the application logger still get processed 
     
    7677    # rootLogger.setLevel(logging.ERROR) 
    7778    # still need to set this or we don't get anything below warning 
    78     applicationLogger.setLevel(logLevel) 
     79    systemLogger.setLevel(logLevel) 
    7980     
    8081initLogging() 
  • trunk/src/dm/view/basetest.py

    r4 r5  
    8080#        self.failIf(self.view.authoriseActionObject('Update', object)) 
    8181#        self.failIf(self.view.authoriseActionObject('Delete', object)) 
    82         object = self.registry.getDomainClass('Person') 
    83         self.failUnless(self.view.authoriseActionObject('Create', object)) 
    84         self.failUnless(self.view.authoriseActionObject('Read', object)) 
    85         self.failIf(self.view.authoriseActionObject('Update', object)) 
    86         self.failIf(self.view.authoriseActionObject('Delete', object)) 
     82#        object = self.registry.getDomainClass('Person') 
     83#        self.failUnless(self.view.authoriseActionObject('Create', object)) 
     84#        self.failUnless(self.view.authoriseActionObject('Read', object)) 
     85#        self.failIf(self.view.authoriseActionObject('Update', object)) 
     86#        self.failIf(self.view.authoriseActionObject('Delete', object)) 
    8787#        object = self.registry.getDomainClass('Member') 
    8888#        self.failIf(self.view.authoriseActionObject('Create', object)) 
     
    9696#        object = self.registry.getDomainClass('Project') 
    9797#        self.failUnless(self.view.canRead(object)) 
    98         object = self.registry.getDomainClass('Person') 
    99         self.failUnless(self.view.canRead(object)) 
     98#        object = self.registry.getDomainClass('Person') 
     99#        self.failUnless(self.view.canRead(object)) 
    100100#        object = self.registry.getDomainClass('Member') 
    101101#        self.failUnless(self.view.canRead(object)) 
     
    108108#        object = self.registry.getDomainClass('Project') 
    109109#        self.failIf(self.view.canCreate(object)) 
    110         object = self.registry.getDomainClass('Person') 
    111         self.failUnless(self.view.canCreate(object)) 
     110#        object = self.registry.getDomainClass('Person') 
     111#        self.failUnless(self.view.canCreate(object)) 
    112112#        object = self.registry.getDomainClass('Member') 
    113113#        self.failIf(self.view.canCreate(object)) 
     
    118118#        object = self.registry.getDomainClass('Project') 
    119119#        self.failIf(self.view.canUpdate(object)) 
    120         object = self.registry.getDomainClass('Person') 
    121         self.failIf(self.view.canUpdate(object)) 
    122 #        object = self.registry.getDomainClass('Member') 
     120#        object = self.registry.getDomainClass('Person') 
    123121#        self.failIf(self.view.canUpdate(object)) 
     122#        object = self.registry.getDomainClass('Member') 
     123#        self.failIf(self.view.canUpdate(object)) 
    124124 
    125125    def test_canDelete(self): 
     
    128128#        object = self.registry.getDomainClass('Project') 
    129129#        self.failIf(self.view.canDelete(object)) 
    130         object = self.registry.getDomainClass('Person') 
    131         self.failIf(self.view.canDelete(object)) 
    132 #        object = self.registry.getDomainClass('Member') 
     130#        object = self.registry.getDomainClass('Person') 
    133131#        self.failIf(self.view.canDelete(object)) 
     132#        object = self.registry.getDomainClass('Member') 
     133#        self.failIf(self.view.canDelete(object)) 
    134134 
    135135