Changeset 1422 for trunk/packages/invirt-base/python
- Timestamp:
- Oct 29, 2008, 12:44:45 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.