From e007cebc17c83ba2b927a157299d82f0024ac1c7 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Sun, 27 Jul 2008 18:48:28 -0400 Subject: [PATCH] started adding simple configuration-loading module and getconfig frontend; checkpoint for moving dev to home machine which actually has yaml, etc. svn path=/trunk/packages/sipb-xen-base/; revision=726 --- files/usr/sbin/invirt-getconf | 18 ++++++++++++++++++ .../sipb-xen-base/invirt/__init__.py | 6 ++++++ .../python-support/sipb-xen-base/invirt/config.py | 10 ++++++++++ 3 files changed, 34 insertions(+) create mode 100644 files/usr/sbin/invirt-getconf create mode 100644 files/usr/share/python-support/sipb-xen-base/invirt/config.py diff --git a/files/usr/sbin/invirt-getconf b/files/usr/sbin/invirt-getconf new file mode 100644 index 0000000..cbb0a85 --- /dev/null +++ b/files/usr/sbin/invirt-getconf @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +from invirt.config import load +from sys import argv, stderr + +def main( argv ): + try: command, key = argv + except: print >> stderr, 'invirt-getconf KEY' + conf = load() + for component in key.split('.')[:-1]: + if component.isdigit(): component = int( component ) + conf = conf[ component ] + print conf[key] + +if __name__ == '__main__': + main( argv ) + +# vim:et:sw=4:ts=4 diff --git a/files/usr/share/python-support/sipb-xen-base/invirt/__init__.py b/files/usr/share/python-support/sipb-xen-base/invirt/__init__.py index 18d44f9..d880252 100644 --- a/files/usr/share/python-support/sipb-xen-base/invirt/__init__.py +++ b/files/usr/share/python-support/sipb-xen-base/invirt/__init__.py @@ -19,3 +19,9 @@ Consult the source files for details. # You should have received a copy of the GNU General Public License # along with Invirt. If not, see . + +__author__ = 'MIT SIPB' +__version__ = '0.1' +__copyright__ = 'Copyright (c) 2008 MIT SIPB' + +# vim:et:sw=4:ts=4 diff --git a/files/usr/share/python-support/sipb-xen-base/invirt/config.py b/files/usr/share/python-support/sipb-xen-base/invirt/config.py new file mode 100644 index 0000000..42e3b2f --- /dev/null +++ b/files/usr/share/python-support/sipb-xen-base/invirt/config.py @@ -0,0 +1,10 @@ +from __future__ import with_statement +import yaml + +default_path = '/etc/invirt/master.yaml' + +def load( path = default_path ): + with file( path ) as f: + return yaml.load( f, yaml.CSafeLoader ) + +# vim:et:sw=4:ts=4 -- 1.7.9.5