]> Frank Brehm's Git Trees - my-stuff/py-logrotate.git/commitdiff
Integer options behandelt
authorFrank Brehm <frank@brehm-online.com>
Wed, 4 May 2011 21:54:24 +0000 (21:54 +0000)
committerFrank Brehm <frank@brehm-online.com>
Wed, 4 May 2011 21:54:24 +0000 (21:54 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@223 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

LogRotateConfig.py

index 43e625315bb2ee979c364b24bc165a43b4ef4a16..979a91d6958d16bc89f7bc27b25524474d6f6df5 100755 (executable)
@@ -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
 
     #------------------------------------------------------------