Ignore:
Timestamp:
Jul 29, 2008, 1:35:57 AM (16 years ago)
Author:
y_z
Message:
  • moved more generic code into common package
  • silently fail if cache fails
  • load the configuration on module load
  • produce a struct-based representation of the configuration
  • allowing full exception messages for OSErrors (default behavior)
  • added some dependencies specs
Location:
trunk/packages/sipb-xen-base
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-base/debian/control

    r774 r778  
    33Priority: extra
    44Maintainer: SIPB Xen Project <sipb-xen@mit.edu>
    5 Build-Depends: cdbs (>= 0.4.23-1.1), debhelper (>= 4.1.0), python-json (>= 3.4-2), python-yaml (>= 3.05-1andersk1)
     5Build-Depends: cdbs (>= 0.4.23-1.1), debhelper (>= 4.1.0)
    66Standards-Version: 3.7.2
    77
    88Package: sipb-xen-base
    99Architecture: all
    10 Depends: ${misc:Depends},
     10Depends: ${misc:Depends}, python-json (>= 3.4-2), python-yaml (>= 3.05)
    1111Description: Base configuration required for all SIPB xen servers
    1212 This package includes apt configuration, .k5login and other files that
  • trunk/packages/sipb-xen-base/files/usr/sbin/invirt-getconf

    r771 r778  
    22
    33"""
    4 invirt-getconf [-f FILE] KEY prints the configuration the option named KEY from
    5 the invirt configuration file FILE.  Keys are dot-separated paths into the YAML
     4invirt-getconf loads an invirt configuration file (either the original YAML
     5source or the faster-to-load JSON cache) and prints the configuration option
     6with the given name (key).  Keys are dot-separated paths into the YAML
    67configuration tree.  List indexes (0-based) are also treated as path
    78components.
    89
    910(Due to this path language, certain restrictions are placed on the keys used in
    10 the YAML configuration, e.g. they cannot contain dots.)
     11the YAML configuration; e.g., they cannot contain dots.)
    1112
    1213Examples:
     
    5859                    '%s: index %s out of range' % (progress, component))
    5960        print conf
    60     except (invirt_exception, OSError), ex:
     61    except invirt_exception, ex:
    6162        print >> stderr, ex
    6263        return 1
  • trunk/packages/sipb-xen-base/files/usr/share/python-support/sipb-xen-base/invirt/config.py

    r771 r778  
    11import json, yaml
     2from invirt.common import *
    23from os import error, makedirs
    34from os.path import dirname, getmtime
     
    89try:    default_loader = yaml.CSafeLoader
    910except: 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()
    1511
    1612def load(src_path = default_src_path,
     
    3127        else:           do_refresh  = src_mtime > cache_mtime
    3228
     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
    3334    if do_refresh:
    3435        # reload the source and regenerate the cache
    3536        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
    3939    return cfg
    4040
     41dicts = load()
     42structs = dicts2struct(dicts)
     43
    4144# vim:et:sw=4:ts=4
Note: See TracChangeset for help on using the changeset viewer.