--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# $Id$
+# $URL$
+
+'''
+@author: Frank Brehm
+@contact: frank@brehm-online.com
+@license: GPL3
+@copyright: (c) 2010-2011 by Frank Brehm, Berlin
+@version: 0.1.0
+@summary: This module provides a parser for configuration files in ISC style (for example named.conf)
+'''
+
+import re
+import pprint
+import os.path
+import sys
+
+from fbrehm.common.logging_obj import LoggingObject
+
+revision = '$Revision$'
+revision = re.sub( r'\$', '', revision )
+revision = re.sub( r'Revision: ', r'r', revision )
+
+__author__ = 'Frank Brehm'
+__copyright__ = '(C) 2010 by Frank Brehm, Berlin'
+__contact__ = 'frank@brehm-online.com'
+__version__ = '0.1.0 ' + revision
+__license__ = 'GPL3'
+
+#========================================================================
+class IscConfigParserError(Exception):
+ """Base class for exceptions in this module."""
+ pass
+
+#========================================================================
+class IscConfigParser(LoggingObject):
+ """Class for encapsulation of a low level hardware address.
+ """
+
+ #------------------------------------------------------
+ def __init__( self, verbose = 0, ):
+ """Constructor.
+ @param verbose: verbosity level (default: 0)
+ @type verbose: int
+ @return: None
+ @rtype: None
+ """
+
+ super( IscConfigParser, self ).__init__( verbose = verbose )
+
+ self.current_filename = None
+
+ # Other properties
+
+ #------------------------------------------------------
+ def parse( self, input, filename = None ):
+ """Read a file in a ISC-like config style.
+
+ The input can be either a file-like object or a string. If a string
+ is used you can optionally also provide a filename, which will be
+ used for raised exceptions.
+
+ The contents from the file is returned as a standard python dictionary.
+
+ @param input: file-like object or a string
+ @type input: str
+ @param filename: filename for debugging and error messages
+ @type filename: str or None
+ @return: the contents from the file as a standard python dictionary
+ @rtype: dict
+ """
+
+ result = {}
+
+ if filename is not None and not os.path.isfile( filename ):
+ raise IscConfigParserError( "File {0!r} not found.".format( filename ) )
+
+ fd = None
+ if filename is not None:
+ fd = open( filename, "r" )
+ self.current_filename = filename
+ else:
+ fs = sys.stdin
+ self.current_filename = '<stdin>'
+
+ self.logger.debug( "Reading configuration file {0!r} ...".format( self.current_filename ) )
+
+
+ if filename is not None:
+ fd.close()
+
+ return result
+
+
+#========================================================================
+
+def parse_isc_config( input, filename = None, verbose = 0 ):
+ '''Wrapper for IscConfigParser.parse()
+
+ @param input: file-like object or a string
+ @type input: str
+ @param filename: filename for debugging and error messages
+ @type filename: str or None
+ @param verbose: verbosity level (default: 0)
+ @type verbose: int
+ @return: the contents from the file as a standard python dictionary
+ @rtype: dict
+ '''
+
+ parser = IscConfigParser( verbose = verbose )
+ return parser.parse( input, filename = filename )
+
+#========================================================================
+
+if __name__ == "__main__":
+
+ opt_parser = BaseOptParser(
+ version = __version__,
+ prog = 'ipv6-hostpart.py',
+ description = u'Calculates the 64 bit host part of an IPv6 address by given MAC addresses or infiniband GUIDs.',
+ usage = u'%s [Options] <MAC address or IB-GUID> [<MAC> ...]'
+ )
+
+ opt_parser.getOpts()
+
+ verbose = opt_parser.options.verbose
+
+ files = []
+ if len( sys.argv ) > 0:
+ files = sys.argv[1:]
+ else:
+ files = os.sep + os.path.join( 'etc', 'bind', 'named.conf' )
+
+ for conffile in files:
+ conf = parse_isc_config( conffile,
+
+
+
+#========================================================================
+
+# vim: fileencoding=utf-8 filetype=python ts=4 expandtab