From 5b99edf91157f87046e4210ea9a241d4cd28ee9f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Sun, 5 Dec 2010 09:51:09 +0000 Subject: [PATCH] Objekteigenschaft ignore_empty_object_props dazu git-svn-id: http://svn.brehm-online.com/svn/my-stuff/nagios/trunk@142 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- bin/nagios/cfg/struct.py | 10 ++++++++-- bin/nagios/config.py | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/nagios/cfg/struct.py b/bin/nagios/cfg/struct.py index cdf1401..a019bb1 100755 --- a/bin/nagios/cfg/struct.py +++ b/bin/nagios/cfg/struct.py @@ -25,7 +25,7 @@ class NagiosConfigStruct(object): return repr(dump) #------------------------------------------------------ - def __init__( self, logger = None ): + def __init__( self, logger = None, , ignore_empty_object_props = True ): "Constructor." # Logging-Setup @@ -45,6 +45,8 @@ class NagiosConfigStruct(object): else: self.logger = logger + self.ignore_empty_object_props = ignore_empty_object_props + #------------------------------------------------------ def __del__( self ): "Destructor" @@ -140,13 +142,17 @@ class NagiosConfigStruct(object): return result # Split line into key and value - match = re.search( r'^\s*(\w+)\s+(.*)', line ) + match = re.search( r'^\s*(\w+)(?:\s+(.*))?', line ) if match is None: raise NagiosConfigStructError( "Couldn't evaluate line {0!r}.".format( line ) ) key = match.group(1) value = match.group(2) + if value is None: + if not self.ignore_empty_object_props: + raise NagiosConfigStructError( "No value given for key {0!r}.".format( key ) ) + # User defined definitions if re.match( r'^_', key ): key_upper = key.upper() diff --git a/bin/nagios/config.py b/bin/nagios/config.py index ee1ca9c..03ce506 100644 --- a/bin/nagios/config.py +++ b/bin/nagios/config.py @@ -52,7 +52,7 @@ class NagiosConfig(object): return repr(dump) #------------------------------------------------------ - def __init__( self, new_file = file_name ): + def __init__( self, new_file = file_name, ignore_empty_object_props = True ): "Konstruktor." # Logging-Setup @@ -72,6 +72,7 @@ class NagiosConfig(object): self.objects = {} self.config_objects = {} self.objects_read = {} + self.ignore_empty_object_props = ignore_empty_object_props #------------------------------------------------------ def __del__( self ): -- 2.39.5