Ignore:
Timestamp:
Jan 22, 2010, 9:45:09 AM (15 years ago)
Author:
gdb
Message:

Removed invirt-web-afs-apache

Location:
trunk/packages/invirt-base
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-base/debian/changelog

    r2766 r2920  
     1invirt-base (0.0.29) unstable; urgency=low
     2
     3  * Added a safestructs for doing config without raising.
     4
     5 -- Greg Brockman <gdb@mit.edu>  Tue, 19 Jan 2010 23:49:19 -0500
     6
    17invirt-base (0.0.28) unstable; urgency=low
    28
  • trunk/packages/invirt-base/python/invirt/common.py

    r2592 r2920  
    1111class struct(dict):
    1212    'A simple namespace object.'
    13     def __init__(self, d = {}, __prefix = None, **kwargs):
     13    def __init__(self, d = {}, __prefix = None, __default=None, **kwargs):
    1414        super(struct, self).__init__(d)
    1515        self.__prefix = __prefix
     16        self.__default = __default
    1617        self.update(kwargs)
    1718    def __getattr__(self, key):
     
    1920            return self[key]
    2021        except KeyError:
    21             # XX ideally these would point a frame higher on the stack.
    22             prefix = self.__prefix
    23             if prefix is not None:
    24                 raise InvirtConfigError('missing configuration variable %s%s'
    25                                         % (prefix, key))
     22            if self.__default is None:
     23                # XX ideally these would point a frame higher on the stack.
     24                prefix = self.__prefix
     25                if prefix is not None:
     26                    raise InvirtConfigError('missing configuration variable '
     27                                            '%s%s' % (prefix, key))
     28                else:
     29                    raise AttributeError("anonymous struct has no member '%s'"
     30                                         % (key,))
    2631            else:
    27                 raise AttributeError("anonymous struct has no member '%s'"
    28                                      % (key,))
     32                return struct({}, '', self.__default)
    2933
    30 def dicts2struct(x, prefix = None):
     34def dicts2struct(x, prefix = None, default = None):
    3135    """
    3236    Given a tree of lists/dicts, perform a deep traversal to transform all the
     
    3842        def newprefix(k): return prefix
    3943    if type(x) == dict:
    40         return struct(((k, dicts2struct(v, newprefix(k)))
     44        return struct(((k, dicts2struct(v, newprefix(k), default))
    4145                       for k,v in x.iteritems()),
    42                       prefix)
     46                      prefix,
     47                      default)
    4348    elif type(x) == list:
    44         return [dicts2struct(v, newprefix(i)) for i, v in enumerate(x)]
     49        return [dicts2struct(v, newprefix(i), default)
     50                for i, v in enumerate(x)]
    4551    elif x is None:
    46         return struct({}, prefix)
     52        return struct({}, prefix, default)
    4753    else:
    4854        return x
  • trunk/packages/invirt-base/python/invirt/config.py

    r1934 r2920  
    142142dicts = load()
    143143structs = dicts2struct(dicts, '')
     144safestructs = dicts2struct(dicts, '', '')
    144145
    145146# vim:et:sw=4:ts=4
Note: See TracChangeset for help on using the changeset viewer.