Changeset 1422 for trunk/packages/invirt-base
- Timestamp:
- Oct 29, 2008, 12:44:45 AM (16 years ago)
- Location:
- trunk/packages/invirt-base
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/invirt-base/debian/changelog
r1420 r1422 2 2 3 3 * eliminate choice of source and cache files for invirt.config.load and 4 invirt-getconf, so we can make it more complex 4 invirt-getconf, so we can do what follows 5 * look in /etc/invirt/conf.d/ as well as /etc/invirt/master.yaml 5 6 6 7 -- Greg Price <price@mit.edu> Tue, 28 Oct 2008 21:16:14 -0400 -
trunk/packages/invirt-base/python/invirt/config.py
r1421 r1422 3 3 import json 4 4 from invirt.common import * 5 import os 5 6 from os import rename 6 7 from os.path import getmtime … … 11 12 except: loader = yaml.SafeLoader 12 13 13 src_path = '/etc/invirt/master.yaml' 14 cache_path = '/var/lib/invirt/cache.json' 15 lock_path = '/var/lib/invirt/cache.lock' 14 src_path = '/etc/invirt/master.yaml' 15 src_dirpath = '/etc/invirt/conf.d' 16 cache_path = '/var/lib/invirt/cache.json' 17 lock_path = '/var/lib/invirt/cache.lock' 18 19 def augment(d1, d2): 20 """Splice dict-tree d2 into d1. Return d1. 21 22 Example: 23 >>> d = {'a': {'b': 1}, 'c': 2} 24 >>> augment(d, {'a': {'d': 3}}) 25 {'a': {'b', 1, 'd': 3}, 'c': 2} 26 >>> d 27 {'a': {'b', 1, 'd': 3}, 'c': 2} 28 """ 29 for k in d2: 30 if k in d1 and isinstance(d1[k], dict): 31 augment(d1[k], d2[k]) 32 else: 33 d1[k] = d2[k] 34 return d1 35 36 def list_files(): 37 yield src_path 38 for name in os.listdir(src_dirpath): 39 yield os.path.join(src_dirpath, name) 16 40 17 41 def load_master(): 18 with closing(file(src_path)) as f: 19 return yaml.load(f, loader) 42 config = dict() 43 for filename in list_files(): 44 with closing(file(filename)) as f: 45 augment(config, yaml.load(f, loader)) 46 return config 20 47 21 48 def get_src_mtime(): 22 return getmtime(src_path) 49 return max(max(getmtime(filename) for filename in list_files()), 50 getmtime(src_dirpath)) 23 51 24 52 def load(force_refresh = False):
Note: See TracChangeset
for help on using the changeset viewer.