Changeset 778 for trunk/packages/sipb-xen-base/files/usr/share
- Timestamp:
- Jul 29, 2008, 1:35:57 AM (16 years ago)
- Location:
- trunk/packages/sipb-xen-base/files/usr/share/python-support/sipb-xen-base/invirt
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-base/files/usr/share/python-support/sipb-xen-base/invirt/config.py
r771 r778 1 1 import json, yaml 2 from invirt.common import * 2 3 from os import error, makedirs 3 4 from os.path import dirname, getmtime … … 8 9 try: default_loader = yaml.CSafeLoader 9 10 except: default_loader = yaml.SafeLoader 10 11 def wrap(rsrc, func):12 "Utility to that emulates with Python 2.5's `with closing(rsrc)`."13 try: return func(rsrc)14 finally: rsrc.close()15 11 16 12 def load(src_path = default_src_path, … … 31 27 else: do_refresh = src_mtime > cache_mtime 32 28 29 if not do_refresh: 30 # try reading from the cache first 31 try: cfg = wrap(file(cache_path), lambda f: json.read(f.read())) 32 except: do_refresh = True 33 33 34 if do_refresh: 34 35 # reload the source and regenerate the cache 35 36 cfg = wrap(file(src_path), lambda f: yaml.load(f, default_loader)) 36 wrap(file(cache_path, 'w'), lambda f: f.write(json.write(cfg))) 37 else: 38 cfg = wrap(file(cache_path), lambda f: json.read(f.read())) 37 try: wrap(file(cache_path, 'w'), lambda f: f.write(json.write(cfg))) 38 except: pass # silent failure 39 39 return cfg 40 40 41 dicts = load() 42 structs = dicts2struct(dicts) 43 41 44 # vim:et:sw=4:ts=4
Note: See TracChangeset
for help on using the changeset viewer.