Changeset 116
- Timestamp:
- Thu Sep 8 18:18:16 2005
- Files:
-
- trunk/tests/doctests/utils/config.py (modified) (diff)
- trunk/setup.py (modified) (diff)
- trunk/xix/utils/linux.py (modified) (diff)
- trunk/xix/utils/interfaces.py (modified) (diff)
- trunk/xix/utils/config.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/tests/doctests/utils/config.py
r112 r116 11 11 # pydoc unit tests 12 12 13 class ds: pass 14 d = ds() 13 class File: 14 def __init__(self, data): 15 self.data = data 16 def read(self): 17 return self.data 15 18 16 19 class ConfigLoaderTest: … … 19 22 Duplicate entries are strictly not allowed: 20 23 21 >>> d.data ="""24 >>> fd = File(""" 21 24 ... foo.bar=123 22 25 ... foo.bar="foobar" 23 ... """ 24 >>> ConfigLoader.load(d) 26 ... """) 27 >>> ConfigLoader.load(fd) 25 28 Traceback (most recent call last): 26 29 ... … … 32 35 Cannot extent terminal nodes: 33 36 34 >>> d.data ="""37 >>> fd = File(""" 34 37 ... foo=123 35 38 ... foo.bar="foobar" 36 ... """ 37 >>> ConfigLoader.load(d) 39 ... """) 40 >>> ConfigLoader.load(fd) 38 41 Traceback (most recent call last): 39 42 ... … … 45 48 Configuration files must be well formed: 46 49 47 >>> d.data = "crap here" 48 >>> ConfigLoader.load(d) 50 >>> fd = File("crap here") 51 >>> ConfigLoader.load(fd) 49 52 Traceback (most recent call last): 50 53 ... … … 55 58 Configuration nodes must be valid python names: 56 59 57 >>> d.data = "this.123='hello'" 58 >>> ConfigLoader.load(d) 60 >>> fd = File("this.123='hello'") 61 >>> ConfigLoader.load(fd) 59 62 Traceback (most recent call last): 60 63 ... … … 65 68 Type values are implicit by given python syntax: 66 69 67 >>> d.data = "foo.bar=[1,2,3]" 68 >>> cfg = ConfigLoader.load(d) 70 >>> fd = File("foo.bar=[1,2,3]") 71 >>> cfg = ConfigLoader.load(fd) 69 72 >>> type(cfg.foo.bar) 70 73 <type 'list'> … … 74 77 Strings MUST be indicated with quotes (single or double): 75 78 76 >>> d.data = "foo.bar=not good dude" 77 >>> ConfigLoader.load(d) 79 >>> fd = File("foo.bar=not good dude") 80 >>> ConfigLoader.load(fd) 78 81 Traceback (most recent call last): 79 82 ... … … 84 87 Not all types are supported: 85 88 86 >>> d.data = "foo.bar=type" 87 >>> ConfigLoader.load(d) 89 >>> fd = File("foo.bar=type") 90 >>> ConfigLoader.load(fd) 88 91 Traceback (most recent call last): 89 92 ... … … 94 97 We can also get a module wrapper ... 95 98 96 >>> d.data = "foo.bar=xix.utils.string" 97 >>> cfg = ConfigLoader.load(d) 99 >>> fd = File("foo.bar=xix.utils.string") 100 >>> cfg = ConfigLoader.load(fd) 98 101 >>> from xix.utils.interfaces import IModuleWrapper 99 102 >>> IModuleWrapper.providedBy(cfg.foo.bar) -
trunk/setup.py
r85 r116 12 12 from distutil.core import setup 13 13 14 15 def _packageUtilsStandalone(): 16 # TODO complete this for building a standalone xix.utils package ... 17 pass 18 14 19 setup( 15 20 author='Drew Smathers', … … 19 24 description='Web Application Prototyping Kit', 20 25 url='http://www.cc.gatech.edu/ugrads/d/dpaces/', 21 packages=['xix', 'xix.rend', 'xix.services', 'xix.tests','xix.kitchensink', 'xix.taps'], 22 package_data = {'xix' : ['plugins.tml', 'kitchensink/README']}, 26 packages=['xix', 'xix.rend', 'xix.services', 'xix.tests','xix.utils', 'xix.taps'], 27 package_data = {'xix' : ['plugins.tml', 'utils/README']}, 23 28 scripts=['xix/scripts/xxrclient', 'xix/scripts/runxix'] 24 29 ) -
trunk/xix/utils/linux.py
r112 r116 38 38 streams.ERR : (console.FGRED, console.BOLD, console.BGBLACK), 39 39 streams.WARN : (console.FGMAGENTA, console.BGBLACK), 40 streams.DEBUG : (console.FG WHITE, console.HALF_BRIGHT),40 streams.DEBUG : (console.FGCYAN,), 40 40 streams.VERBOSE : (console.FGCYAN, console.BGBLACK), 41 41 streams.SILLY : (console.FGGREEN, console.BGBLACK), -
trunk/xix/utils/interfaces.py
r115 r116 40 40 @raises TypeError: if arguments supplied incorrectly 41 41 ''' 42 def lo okupPath(path):42 def load(path): 42 42 '''Lookup node given path. path argumented may also be interpretted 43 43 as a key for lookup. … … 81 81 '''Configuration Factory for loading application configuration containers 82 82 ''' 83 def getConfig(name =None):83 def getConfig(name): 83 83 '''Return configuration with name name or default configuration 84 84 85 @param name: name of configuration (optional)85 @param name: name of configuration 85 85 @type name: string 86 86 ''' 87 def addResource(name, url): 88 '''Add a resource used by loader with name and url. 89 90 @param name: symbolic name of resource 91 @type name: string 92 @param url: url of the resource 93 @type url: string 94 ''' 87 95 88 96 class IModuleWrapper(Interface): -
trunk/xix/utils/config.py
r114 r116 98 98 99 99 @staticmethod 100 def load( src):100 def load(fd): 100 100 ''' 101 101 Example usage: 102 102 103 >>> class ds: pass 104 ... 105 >>> d = ds() 106 >>> d.data = """ 103 >>> class File: 104 ... def read(self): 105 ... return """ 107 106 ... foo.bar=123 108 107 ... foo.baz='hello world' 109 108 ... foo.foo.nested.pi=3.14 110 109 ... """ 111 >>> cfg = ConfigLoader.load(d) 110 ... 111 >>> fd = File() 112 >>> cfg = ConfigLoader.load(fd) 112 113 >>> print cfg.foo.bar, cfg.foo.baz, cfg.foo.foo.nested.pi 113 114 123 hello world 3.14 114 115 ''' 115 116 cfg = Config() 116 for line in ( src.data.split('\n')):117 for line in (fd.read().split('\n')): 116 117 try: 117 118 if line[0] == "#": continue … … 190 191 if _modulename(s): 191 192 return _ModuleWrapperCaster() 193 # TODO support for loading components 192 194 raise ConfigLoaderException("Cannot resolve type : %s." % s) 193 195 raise ConfigLoaderException('Unsupported type: %s.' % type(tipe)) 194 196 197 class ConfigFactory: 198 '''Factory for managing multiple named configurations. 199 ''' 200 201 implements(IConfigFactory) 202 203 def __init__(self, loader=None): 204 self.loader = loader or ConfigLoader 205 self.resources = {} 206 self.cache = {} 207 208 def getConfig(self, name): 209 if name in self.cache: 210 return self.cache[name] 211 self.cache[name] = self.loader.load(open(self.resources[name])) 212 return self.cache[name] 213 214 def addResource(self, name, url): 215 if name in self.resources: 216 raise ConfigLoaderException, 'Resource with name %s already registered' % name 217 self.resources[name] = url 218 219 220 configFactory = ConfigFactory() 195 221 196 222 class ModuleWrapper:
