Changeset 1197 for trunk/packages/sipb-xen-base/files/usr/share/python-support/sipb-xen-base/invirt/config.py
- Timestamp:
- Oct 24, 2008, 3:35:21 AM (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
r816 r1197 1 from __future__ import with_statement 2 1 3 import json 2 4 from invirt.common import * 3 5 from os import rename 4 6 from os.path import getmtime 7 from contextlib import closing 5 8 6 9 default_src_path = '/etc/invirt/master.yaml' 7 10 default_cache_path = '/var/lib/invirt/cache.json' 8 lock_ file= '/var/lib/invirt/cache.lock'11 lock_path = '/var/lib/invirt/cache.lock' 9 12 10 13 def load(src_path = default_src_path, … … 54 57 # lock with other concurrent reads). This isolation is accomplished 55 58 # using an atomic filesystem rename in the refreshing stage. 56 try: ns.cfg = with_closing(file(cache_path)) ( 57 lambda f: json.read(f.read())) 59 try: 60 with closing(file(cache_path)) as f: 61 ns.cfg = json.read(f.read()) 58 62 except: do_refresh = True 59 63 … … 69 73 except: loader = yaml.SafeLoader 70 74 try: 71 @with_lock_file(lock_file)72 def refresh_cache():73 ns.cfg = with_closing(file(src_path)) (74 lambda f: yaml.load(f, loader))75 try: with_closing(file(cache_path + '.tmp', 'w')) (76 lambda f: f.write(json.write(ns.cfg)))75 with lock_file(lock_path): 76 with closing(file(src_path)) as f: 77 ns.cfg = yaml.load(f, loader) 78 try: 79 with closing(file(cache_path + '.tmp', 'w')) as f: 80 f.write(json.write(ns.cfg)) 77 81 except: pass # silent failure 78 82 else: rename(cache_path + '.tmp', cache_path) 79 83 except IOError: 80 ns.cfg = with_closing(file(src_path)) (81 lambda f: yaml.load(f, loader))84 with closing(file(src_path)) as f: 85 ns.cfg = yaml.load(f, loader) 82 86 return ns.cfg 83 87
Note: See TracChangeset
for help on using the changeset viewer.