From: Yang Zhang Date: Sun, 27 Jul 2008 22:48:28 +0000 (-0400) Subject: started adding simple configuration-loading module and getconfig frontend; checkpoint... X-Git-Tag: sipb-xen-base/8.4~1 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-base.git/commitdiff_plain/e007cebc17c83ba2b927a157299d82f0024ac1c7?hp=c475143b2b047a068fe5615dcd6c961b98c2b36d 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 --- 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