Changeset 1421 for trunk/packages/invirt-base/python/invirt
- Timestamp:
- Oct 29, 2008, 12:44:44 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/invirt-base/python/invirt/config.py
r1420 r1421 6 6 from os.path import getmtime 7 7 from contextlib import closing 8 import yaml 9 10 try: loader = yaml.CSafeLoader 11 except: loader = yaml.SafeLoader 8 12 9 13 src_path = '/etc/invirt/master.yaml' 10 14 cache_path = '/var/lib/invirt/cache.json' 11 15 lock_path = '/var/lib/invirt/cache.lock' 16 17 def load_master(): 18 with closing(file(src_path)) as f: 19 return yaml.load(f, loader) 20 21 def get_src_mtime(): 22 return getmtime(src_path) 12 23 13 24 def load(force_refresh = False): … … 26 37 do_refresh = True 27 38 else: 28 src_mtime = get mtime(src_path)39 src_mtime = get_src_mtime() 29 40 try: cache_mtime = getmtime(cache_path) 30 41 except OSError: do_refresh = True … … 67 78 # transactionally isolated from the above cache read. If we fail to 68 79 # acquire the lock, just try to load the master configuration. 69 import yaml70 try: loader = yaml.CSafeLoader71 except: loader = yaml.SafeLoader72 80 try: 73 81 with lock_file(lock_path): 74 with closing(file(src_path)) as f: 75 ns.cfg = yaml.load(f, loader) 82 ns.cfg = load_master() 76 83 try: 77 84 with closing(file(cache_path + '.tmp', 'w')) as f: … … 80 87 else: rename(cache_path + '.tmp', cache_path) 81 88 except IOError: 82 with closing(file(src_path)) as f: 83 ns.cfg = yaml.load(f, loader) 89 ns.cfg = load_master() 84 90 return ns.cfg 85 91
Note: See TracChangeset
for help on using the changeset viewer.