Changeset 5
- Timestamp:
- 07/24/06 15:04:54 (2 years ago)
- Files:
-
- trunk/bin (added)
- trunk/bin/domainmodel-admin (added)
- trunk/bin/domainmodel-sdist-maker (added)
- trunk/bin/domainmodel-test (added)
- trunk/src/dm/builder.py (modified) (1 diff)
- trunk/src/dm/config.py (moved) (moved from trunk/src/dm/system.py) (1 diff)
- trunk/src/dm/configtest.py (added)
- trunk/src/dm/dictionary.py (added)
- trunk/src/dm/dictionarytest.py (added)
- trunk/src/dm/django (added)
- trunk/src/dm/django/__init__.py (added)
- trunk/src/dm/django/settings (added)
- trunk/src/dm/django/settings/__init__.py (added)
- trunk/src/dm/django/settings/main.py (added)
- trunk/src/dm/log.py (modified) (7 diffs)
- trunk/src/dm/test (added)
- trunk/src/dm/test/__init__.py (moved) (moved from trunk/src/dm/test.py)
- trunk/src/dm/unittest.py (moved) (moved from trunk/src/dm/testunit.py)
- trunk/src/dm/view/basetest.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/dm/builder.py
r2 r5 20 20 21 21 def findSystemDictionary(self): 22 import dm. system23 return dm. system.SystemDictionary('kforge')22 import dm.dictionary 23 return dm.dictionary.SystemDictionary() 24 24 25 25 def findDebug(self): trunk/src/dm/config.py
r2 r5 1 import os2 import re3 1 import ConfigParser 4 2 5 class DictionaryConfigParser(ConfigParser.SafeConfigParser): 6 """ConfigParser object with alternative dictionary-like interface. 7 """ 3 class ConfigFileReader(ConfigParser.SafeConfigParser): 4 "Presents config files as a dictionary of name-value pairs." 8 5 9 6 def __init__(self): 10 # new style super doesn't work...11 # super(SystemDictionary, self).__init__()12 7 ConfigParser.SafeConfigParser.__init__(self) 13 8 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: 17 29 sectionName = 'DEFAULT' 18 30 optionName = key 19 31 else: 20 sectionName = key[: tindex]21 optionName = key[ tindex+1:]32 sectionName = key[:index] 33 optionName = key[index+1:] 22 34 return (sectionName, optionName) 23 35 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'] 39 38 40 39 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 48 50 49 # todo: change from `isa' to `hasa' DictionaryConfigParser50 # todo: fix up the methods to new style super()51 # (rgrp) No: this is a bad idea and is what he had before52 # ConfigParser is the python provided object for doing what we want and53 # we should use it. We are simply providing a minimal interface layer on54 # top of it and there is no reason we should replicate much of the ConfigParser55 # interface again in our object56 # (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 and58 # is-not-a parser" so it should aggregate a parser and use it, rather than59 # inheriting from it, which is stupid. There is no need to replicate much of60 # 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 = applicationName71 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.systemRootPath81 self['application'] = self.applicationName82 self['etcdir'] = self.etcPath83 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.applicationName106 )107 if not os.path.isdir(path):108 raise EnvironmentError, 'System root dir not found: ' + path109 return path110 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.applicationName118 path = os.path.join(119 self.etcPath,120 fileName121 )122 return path123 124 def makeEtcPath(self):125 path = os.path.join(126 self.systemRootPath,127 'etc'128 )129 return path130 trunk/src/dm/log.py
r2 r5 1 1 """ 2 KForge logger. 2 Logger. 3 3 4 """ 4 5 … … 6 7 import logging.handlers 7 8 import os 9 from dm.ioc import RequiredFeature 8 10 9 DICTWORD_LOG _PATH= 'logging.log_file'10 DICTWORD_LOG _LEVEL= 'logging.level'11 DICTWORD_ APPLICATION = 'application'11 DICTWORD_LOGGING_PATH = 'logging.log_file' 12 DICTWORD_LOGGING_LEVEL = 'logging.level' 13 DICTWORD_SYSTEM_NAME = 'system_name' 12 14 13 from dm.ioc import *14 15 15 16 def getLogger(): … … 19 20 """ 20 21 dictionary = RequiredFeature('SystemDictionary') 21 applicationName = dictionary[DICTWORD_APPLICATION]22 return logging.getLogger( applicationName)22 systemName = dictionary[DICTWORD_SYSTEM_NAME] 23 return logging.getLogger(systemName) 23 24 24 25 def initLogging(): … … 32 33 """ 33 34 dictionary = RequiredFeature('SystemDictionary') 34 logPath = dictionary[DICTWORD_LOG _PATH]35 logPath = dictionary[DICTWORD_LOGGING_PATH] 35 36 logLevel = logging.INFO 36 37 logLevels = { … … 41 42 'CRITICAL' : logging.CRITICAL 42 43 } 43 logLevelName = dictionary[DICTWORD_LOG _LEVEL]44 logLevelName = dictionary[DICTWORD_LOGGING_LEVEL] 44 45 if logLevelName in logLevels: 45 46 logLevel = logLevels[logLevelName] … … 67 68 68 69 rootLogger = logging.getLogger('') 69 applicationName = dictionary[DICTWORD_APPLICATION]70 applicationLogger = logging.getLogger(applicationName)70 systemName = dictionary[DICTWORD_SYSTEM_NAME] 71 systemLogger = logging.getLogger(systemName) 71 72 rootLogger.addHandler(consoleHandler) 72 applicationLogger.addHandler(fileHandler)73 systemLogger.addHandler(fileHandler) 73 74 # setting this level seems to have no effect 74 75 # i.e. debug events from the application logger still get processed … … 76 77 # rootLogger.setLevel(logging.ERROR) 77 78 # still need to set this or we don't get anything below warning 78 applicationLogger.setLevel(logLevel)79 systemLogger.setLevel(logLevel) 79 80 80 81 initLogging() trunk/src/dm/view/basetest.py
r4 r5 80 80 # self.failIf(self.view.authoriseActionObject('Update', object)) 81 81 # 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)) 87 87 # object = self.registry.getDomainClass('Member') 88 88 # self.failIf(self.view.authoriseActionObject('Create', object)) … … 96 96 # object = self.registry.getDomainClass('Project') 97 97 # 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)) 100 100 # object = self.registry.getDomainClass('Member') 101 101 # self.failUnless(self.view.canRead(object)) … … 108 108 # object = self.registry.getDomainClass('Project') 109 109 # 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)) 112 112 # object = self.registry.getDomainClass('Member') 113 113 # self.failIf(self.view.canCreate(object)) … … 118 118 # object = self.registry.getDomainClass('Project') 119 119 # 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') 123 121 # self.failIf(self.view.canUpdate(object)) 122 # object = self.registry.getDomainClass('Member') 123 # self.failIf(self.view.canUpdate(object)) 124 124 125 125 def test_canDelete(self): … … 128 128 # object = self.registry.getDomainClass('Project') 129 129 # 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') 133 131 # self.failIf(self.view.canDelete(object)) 132 # object = self.registry.getDomainClass('Member') 133 # self.failIf(self.view.canDelete(object)) 134 134 135 135
