From 65769529b00355013e12d405c3e573c6961be513 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 4 May 2011 21:54:24 +0000 Subject: [PATCH] Integer options behandelt git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@223 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- LogRotateConfig.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/LogRotateConfig.py b/LogRotateConfig.py index 43e6253..979a91d 100755 --- a/LogRotateConfig.py +++ b/LogRotateConfig.py @@ -57,6 +57,16 @@ unsupported_options = ( 'error', ) +options_with_values = ( + 'mail', + 'compresscmd', + 'statusfile', + 'pidfile', + 'compressext', + 'rotate', + 'maxage', +) + boolean_options = ( 'compress', 'copytruncate', @@ -65,6 +75,12 @@ boolean_options = ( 'sharedscripts', ) +integer_options = ( + 'delaycompress', + 'rotate', + 'start', +) + #======================================================================== class LogrotateConfigurationError(Exception): @@ -943,6 +959,48 @@ class LogrotateConfigurationReader(object): directive[key] = option_value return True + # Check for integer options + pattern = r'^(not?)?(' + '|'.join(integer_options) + r')$' + match = re.search(pattern, option, re.IGNORECASE) + if match: + negated = match.group(1) + key = match.group(2).lower() + option_value = 0 + if negated is None: + if key in options_with_values: + if val is None or val == '': + self.logger.warning( + ( _("Option »%s« without a necessary value.") + % (key) + ) + ) + return False + try: + option_value = long(val) + except ValueError, e: + self.logger.warning( + ( _("Option »%s« has no integer value: %s.") + % (key, str(e)) + ) + ) + return False + if option_value < 0: + self.logger.warning( + ( _("Negative value %s for option »%s« is not allowed.") + % (str(option_value), key) + ) + ) + return False + if self.verbose > 4: + self.logger.debug( + ( _("Setting integer option »%s« in »%s« to »%s«. " + + "(file »%s«, line %s)") + % (key, directive_str, str(option_value), filename, linenr) + ) + ) + directive[key] = option_value + return True + return True #------------------------------------------------------------ -- 2.39.5