Changeset 781 for trunk/packages/sipb-xen-base/files/usr/share/python-support/sipb-xen-base/invirt/config.py
- Timestamp:
- Jul 29, 2008, 10:35:08 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-base/files/usr/share/python-support/sipb-xen-base/invirt/config.py
r778 r781 1 1 import json, yaml 2 2 from invirt.common import * 3 from os import error, makedirs 4 from os.path import dirname, getmtime 3 from os.path import getmtime 5 4 6 5 default_src_path = '/etc/invirt/master.yaml' 7 default_cache_path = '/var/lib/invirt/ invirt.json'6 default_cache_path = '/var/lib/invirt/cache.json' 8 7 9 8 try: default_loader = yaml.CSafeLoader … … 29 28 if not do_refresh: 30 29 # try reading from the cache first 31 try: cfg = w rap(file(cache_path),lambda f: json.read(f.read()))30 try: cfg = with_closing(file(cache_path))(lambda f: json.read(f.read())) 32 31 except: do_refresh = True 33 32 34 33 if do_refresh: 35 # reload the source and regenerate the cache 36 cfg = wrap(file(src_path), lambda f: yaml.load(f, default_loader)) 37 try: wrap(file(cache_path, 'w'), lambda f: f.write(json.write(cfg))) 38 except: pass # silent failure 34 # Atomically reload the source and regenerate the cache. The read and 35 # write must be a single transaction, or a stale version may be 36 # written. 37 @with_lock_file('/var/lib/invirt/cache.lock') 38 def cfg(): 39 cfg = with_closing(file(src_path))(lambda f: yaml.load(f, default_loader)) 40 try: with_closing(file(cache_path, 'w'))(lambda f: f.write(json.write(cfg))) 41 except: pass # silent failure 42 return cfg 39 43 return cfg 40 44
Note: See TracChangeset
for help on using the changeset viewer.