Index: /package_tags/sipb-xen-base/8.9/debian/changelog
===================================================================
--- /package_tags/sipb-xen-base/8.9/debian/changelog	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/debian/changelog	(revision 780)
@@ -0,0 +1,118 @@
+sipb-xen-base (8.9) unstable; urgency=low
+
+  * 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
+
+ -- Yang Zhang <y_z@mit.edu>  Tue, 29 Jul 2008 01:03:16 -0400
+
+sipb-xen-base (8.8) unstable; urgency=low
+
+  * added timestamp-based JSON caching of configuration for faster loading
+  * exposed (more) options to command-line frontend
+  * improved error messages/handling/help
+  * removed all python 2.5-isms
+  * reformatted to fit project style conventions
+
+ -- Yang Zhang <y_z@mit.edu>  Mon, 28 Jul 2008 12:25:03 -0400
+
+sipb-xen-base (8.7) unstable; urgency=low
+
+  * back to 2.4 compatibility
+
+ -- Greg Price <price@mit.edu>  Mon, 28 Jul 2008 07:44:27 -0400
+
+sipb-xen-base (8.6) unstable; urgency=low
+
+  * switching to python 2.5 only
+  * added y_z to .k5login
+
+ -- Yang Zhang <y_z@mit.edu>  Sun, 27 Jul 2008 20:23:54 -0400
+
+sipb-xen-base (8.5) unstable; urgency=low
+
+  * using python 2.5
+  * initial working version of invirt-getconf that reads & navigates YAML
+
+ -- Yang Zhang <y_z@linerva.mit.edu>  Sun, 27 Jul 2008 20:12:28 -0400
+
+sipb-xen-base (8.4) unstable; urgency=low
+
+  [ Greg Price ]
+  * begin a Python package 'invirt'
+
+  [ Yang Zhang ]
+  * added invirt-getconf to read configuration files
+
+ -- Yang Zhang <y_z@mit.edu>  Sun, 27 Jul 2008 19:10:10 -0400
+
+sipb-xen-base (8.3) unstable; urgency=low
+
+  * add invirt-reload to regenerate and reload configs
+
+ -- Greg Price <price@mit.edu>  Mon, 21 Jul 2008 20:35:42 -0400
+
+sipb-xen-base (8.2) unstable; urgency=low
+
+  * leave out debathena-system so we get only the packages we ask for
+
+ -- Greg Price <price@mit.edu>  Sun, 20 Jul 2008 13:58:52 -0400
+
+sipb-xen-base (8.1) unstable; urgency=low
+
+  * include debathena to make stuff like kerberos config easier
+
+ -- Greg Price <price@mit.edu>  Sat, 19 Jul 2008 23:16:47 -0400
+
+sipb-xen-base (8) unstable; urgency=low
+
+  * update .k5login to match black-mesa
+
+ -- Greg Price <price@mit.edu>  Sun,  4 May 2008 20:28:28 -0400
+
+sipb-xen-base (7) unstable; urgency=low
+
+  * include backports.org
+  * sources.list.d doesn't actually need a .sources.list, just .list
+
+ -- Greg Price <price@mit.edu>  Thu,  1 May 2008 19:45:50 -0400
+
+sipb-xen-base (6) unstable; urgency=low
+
+  * actually use sources.list.d correctly
+
+ -- Greg Price <price@mit.edu>  Sat, 26 Apr 2008 21:22:12 -0400
+
+sipb-xen-base (5) unstable; urgency=low
+
+  * update sources.list, use sources.list.d
+
+ -- Greg Price <price@mit.edu>  Sat, 26 Apr 2008 21:06:05 -0400
+
+sipb-xen-base (4) unstable; urgency=low
+
+  * sipb-vm-1 becomes sipb-xen-dev
+
+ -- Sam Hartman <hartmans@debian.org>  Tue,  4 Sep 2007 15:48:50 -0400
+
+sipb-xen-base (3) unstable; urgency=low
+
+  * We want security updates too
+
+ -- Sam Hartman <hartmans@debian.org>  Fri, 10 Aug 2007 20:39:14 -0400
+
+sipb-xen-base (2) unstable; urgency=low
+
+  * Update sources.list to include our debian mirror
+
+ -- Sam Hartman <hartmans@debian.org>  Sat,  4 Aug 2007 19:11:18 -0400
+
+sipb-xen-base (1) unstable; urgency=low
+
+  * New upstream version
+
+ -- Sam Hartman <hartmans@debian.org>  Sat,  4 Aug 2007 18:44:21 -0400
+
Index: /package_tags/sipb-xen-base/8.9/debian/compat
===================================================================
--- /package_tags/sipb-xen-base/8.9/debian/compat	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/debian/compat	(revision 780)
@@ -0,0 +1,1 @@
+4
Index: /package_tags/sipb-xen-base/8.9/debian/control
===================================================================
--- /package_tags/sipb-xen-base/8.9/debian/control	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/debian/control	(revision 780)
@@ -0,0 +1,14 @@
+Source: sipb-xen-base
+Section: base
+Priority: extra
+Maintainer: SIPB Xen Project <sipb-xen@mit.edu>
+Build-Depends: cdbs (>= 0.4.23-1.1), debhelper (>= 4.1.0)
+Standards-Version: 3.7.2
+
+Package: sipb-xen-base
+Architecture: all
+Depends: ${misc:Depends}, python-json (>= 3.4-2), python-yaml (>= 3.05)
+Description: Base configuration required for all SIPB xen servers
+ This package includes apt configuration, .k5login and other files that
+ should be synchronized among all our servers.
+ Installing this on a non-sipb-xen machine would be very anti-social.
Index: /package_tags/sipb-xen-base/8.9/debian/copyright
===================================================================
--- /package_tags/sipb-xen-base/8.9/debian/copyright	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/debian/copyright	(revision 780)
@@ -0,0 +1,3 @@
+This package was created for internal use of the SIPB Xen Project of
+the MIT Student Information Processing Board.  Ask tabbott@mit.edu if
+you have questions about redistribution.
Index: /package_tags/sipb-xen-base/8.9/debian/rules
===================================================================
--- /package_tags/sipb-xen-base/8.9/debian/rules	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/debian/rules	(revision 780)
@@ -0,0 +1,7 @@
+#!/usr/bin/make -f
+
+include /usr/share/cdbs/1/rules/debhelper.mk
+
+# do we, should we, care between pysupport and pycentral?
+binary-install/sipb-xen-base::
+	dh_pysupport -psipb-xen-base
Index: /package_tags/sipb-xen-base/8.9/debian/sipb-xen-base.install
===================================================================
--- /package_tags/sipb-xen-base/8.9/debian/sipb-xen-base.install	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/debian/sipb-xen-base.install	(revision 780)
@@ -0,0 +1,1 @@
+files/* .
Index: /package_tags/sipb-xen-base/8.9/files/etc/apt/sources.list.d/debathena.list
===================================================================
--- /package_tags/sipb-xen-base/8.9/files/etc/apt/sources.list.d/debathena.list	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/files/etc/apt/sources.list.d/debathena.list	(revision 780)
@@ -0,0 +1,2 @@
+deb     http://debathena.mit.edu/apt etch debathena debathena-config
+deb-src http://debathena.mit.edu/apt etch debathena debathena-config
Index: /package_tags/sipb-xen-base/8.9/files/etc/apt/sources.list.d/sipb-xen.list
===================================================================
--- /package_tags/sipb-xen-base/8.9/files/etc/apt/sources.list.d/sipb-xen.list	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/files/etc/apt/sources.list.d/sipb-xen.list	(revision 780)
@@ -0,0 +1,4 @@
+deb     http://sipb-xen-dev.mit.edu/sipb-xen stable main
+deb-src http://sipb-xen-dev.mit.edu/sipb-xen stable main
+deb     http://www.backports.org/debian etch-backports main
+deb-src http://www.backports.org/debian etch-backports main
Index: /package_tags/sipb-xen-base/8.9/files/root/.k5login
===================================================================
--- /package_tags/sipb-xen-base/8.9/files/root/.k5login	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/files/root/.k5login	(revision 780)
@@ -0,0 +1,22 @@
+hartmans@ATHENA.MIT.EDU
+hartmans/root@ATHENA.MIT.EDU
+jbarnold@ATHENA.MIT.EDU
+jbarnold/root@ATHENA.MIT.EDU
+andersk@ATHENA.MIT.EDU
+andersk/root@ATHENA.MIT.EDU
+nelhage@ATHENA.MIT.EDU
+nelhage/root@ATHENA.MIT.EDU
+tabbott@ATHENA.MIT.EDU
+tabbott/root@ATHENA.MIT.EDU
+quentin/root@ATHENA.MIT.EDU
+ecprice@ATHENA.MIT.EDU
+ecprice/root@ATHENA.MIT.EDU
+price@ATHENA.MIT.EDU
+price/root@ATHENA.MIT.EDU
+broder/root@ATHENA.MIT.EDU
+neboat@ATHENA.MIT.EDU
+geofft/root@ATHENA.MIT.EDU
+zev/root@ATHENA.MIT.EDU
+ccpost/root@ATHENA.MIT.EDU
+y_z@ATHENA.MIT.EDU
+y_z/root@ATHENA.MIT.EDU
Index: /package_tags/sipb-xen-base/8.9/files/usr/sbin/invirt-getconf
===================================================================
--- /package_tags/sipb-xen-base/8.9/files/usr/sbin/invirt-getconf	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/files/usr/sbin/invirt-getconf	(revision 780)
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+"""
+invirt-getconf loads an invirt configuration file (either the original YAML
+source or the faster-to-load JSON cache) and prints the configuration option
+with the given name (key).  Keys are dot-separated paths into the YAML
+configuration tree.  List indexes (0-based) are also treated as path
+components.
+
+(Due to this path language, certain restrictions are placed on the keys used in
+the YAML configuration; e.g., they cannot contain dots.)
+
+Examples:
+
+  invirt-getconf db.uri
+  invirt-getconf authn.0.type
+"""
+
+from invirt.config import load
+from sys import argv, exit, stderr
+from optparse import OptionParser
+
+class invirt_exception(Exception): pass
+
+def main(argv):
+    try:
+        parser = OptionParser(usage = '%prog [options] key',
+                description = __doc__.strip().split('\n\n')[0])
+        parser.add_option('-s', '--src',
+                default = '/etc/invirt/master.yaml',
+                help = 'the source YAML configuration file to read from')
+        parser.add_option('-c', '--cache',
+                default = '/var/lib/invirt/invirt.json',
+                help = 'path to the JSON cache')
+        parser.add_option('-r', '--refresh',
+                action = 'store_true',
+                help = 'force the cache to be regenerated')
+        opts, args = parser.parse_args()
+
+        try: [key] = args
+        except: raise invirt_exception(__doc__.strip())
+
+        conf = load(opts.src, opts.cache, opts.refresh)
+        components = key.split('.')
+        for i, component in enumerate(components):
+            progress = '.'.join(components[:i])
+            if type(conf) not in [dict, list]:
+                raise invirt_exception(
+                        '%s: node has no children (atomic datum)' % progress)
+            if type(conf) == list:
+                try: component = int(component)
+                except: raise invirt_exception(
+                        '%s: node a list; integer path component required, '
+                        'but got "%s"' % (progress, component))
+            try: conf = conf[component]
+            except KeyError: raise invirt_exception(
+                    '%s: key "%s" not found' % (progress, component))
+            except IndexError: raise invirt_exception(
+                    '%s: index %s out of range' % (progress, component))
+        print conf
+    except invirt_exception, ex:
+        print >> stderr, ex
+        return 1
+
+if __name__ == '__main__':
+    exit(main(argv))
+
+# vim:et:sw=4:ts=4
Index: /package_tags/sipb-xen-base/8.9/files/usr/sbin/invirt-reload
===================================================================
--- /package_tags/sipb-xen-base/8.9/files/usr/sbin/invirt-reload	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/files/usr/sbin/invirt-reload	(revision 780)
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+for script in $(run-parts --test /etc/init.d); do
+    if [ "${script#/etc/init.d/sipb-xen-}" != "$script" \
+        -o "${script#/etc/init.d/invirt-}" != "$script" ]; then
+	"$script" reload
+    fi
+done
Index: /package_tags/sipb-xen-base/8.9/files/usr/share/python-support/sipb-xen-base/invirt/__init__.py
===================================================================
--- /package_tags/sipb-xen-base/8.9/files/usr/share/python-support/sipb-xen-base/invirt/__init__.py	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/files/usr/share/python-support/sipb-xen-base/invirt/__init__.py	(revision 780)
@@ -0,0 +1,27 @@
+'''Invirt - a virtualization management system
+
+Invirt was developed at the Student Information Processing Board of
+the Massachusetts Institute of Technology.  See http://xvm.mit.edu/.
+
+Invirt is free software available under the GNU GPL, version 2 or later.
+Consult the source files for details.
+'''
+
+# Invirt is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 2 of the License, or (at your
+# option) any later version.
+
+# Invirt is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with Invirt.  If not, see <http://www.gnu.org/licenses/>.
+
+__author__    = 'MIT SIPB'
+__version__   = '0.1'
+__copyright__ = 'Copyright (c) 2008 MIT SIPB'
+
+# vim:et:sw=4:ts=4
Index: /package_tags/sipb-xen-base/8.9/files/usr/share/python-support/sipb-xen-base/invirt/common.py
===================================================================
--- /package_tags/sipb-xen-base/8.9/files/usr/share/python-support/sipb-xen-base/invirt/common.py	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/files/usr/share/python-support/sipb-xen-base/invirt/common.py	(revision 780)
@@ -0,0 +1,41 @@
+import unittest
+
+class struct(object):
+    'A simple namespace object.'
+    def __init__(self, d = {}):
+        'd is the dictionary to update my __dict__ with.'
+        self.__dict__.update(d)
+
+def dicts2struct(x):
+    """
+    Given a tree of lists/dicts, perform a deep traversal to transform all the
+    dicts to structs.
+    """
+    if type(x) == dict:
+        return struct((k, dicts2struct(v)) for k,v in x.iteritems())
+    elif type(x) == list:
+        return [dicts2struct(v) for v in x]
+    else:
+        return x
+
+def wrap(rsrc, func):
+    "Utility to that emulates with Python 2.5's `with closing(rsrc)`."
+    try: return func(rsrc)
+    finally: rsrc.close()
+
+class common_tests(unittest.TestCase):
+    def test_dicts2structs(self):
+        dicts = {
+                'atom': 0,
+                'dict': { 'atom': 'atom', 'list': [1,2,3] },
+                'list': [ 'atom', {'key': 'value'} ]
+                }
+        structs = dicts2struct(dicts)
+        self.assertEqual(structs.atom,        dicts['atom'])
+        self.assertEqual(structs.dict.atom,   dicts['dict']['atom'])
+        self.assertEqual(structs.dict.list,   dicts['dict']['list'])
+        self.assertEqual(structs.list[0],     dicts['list'][0])
+        self.assertEqual(structs.list[1].key, dicts['list'][1]['key'])
+
+if __name__ == '__main__':
+    unittest.main()
Index: /package_tags/sipb-xen-base/8.9/files/usr/share/python-support/sipb-xen-base/invirt/config.py
===================================================================
--- /package_tags/sipb-xen-base/8.9/files/usr/share/python-support/sipb-xen-base/invirt/config.py	(revision 780)
+++ /package_tags/sipb-xen-base/8.9/files/usr/share/python-support/sipb-xen-base/invirt/config.py	(revision 780)
@@ -0,0 +1,44 @@
+import json, yaml
+from invirt.common import *
+from os import error, makedirs
+from os.path import dirname, getmtime
+
+default_src_path   = '/etc/invirt/master.yaml'
+default_cache_path = '/var/lib/invirt/invirt.json'
+
+try:    default_loader = yaml.CSafeLoader
+except: default_loader = yaml.SafeLoader
+
+def load(src_path = default_src_path,
+         cache_path = default_cache_path,
+         force_refresh = False):
+    """
+    Try loading the configuration from the faster-to-load JSON cache at
+    cache_path.  If it doesn't exist or is outdated, load the configuration
+    instead from the original YAML file at src_path and regenerate the cache.
+    I assume I have the permissions to write to the cache directory.
+    """
+    if force_refresh:
+        do_refresh = True
+    else:
+        src_mtime = getmtime(src_path)
+        try:            cache_mtime = getmtime(cache_path)
+        except OSError: do_refresh  = True
+        else:           do_refresh  = src_mtime > cache_mtime
+
+    if not do_refresh:
+        # try reading from the cache first
+        try: cfg = wrap(file(cache_path), lambda f: json.read(f.read()))
+        except: do_refresh = True
+
+    if do_refresh:
+        # reload the source and regenerate the cache
+        cfg = wrap(file(src_path), lambda f: yaml.load(f, default_loader))
+        try: wrap(file(cache_path, 'w'), lambda f: f.write(json.write(cfg)))
+        except: pass # silent failure
+    return cfg
+
+dicts = load()
+structs = dicts2struct(dicts)
+
+# vim:et:sw=4:ts=4
