From: Frank Brehm Date: Sat, 7 May 2011 23:28:57 +0000 (+0000) Subject: dateext behandelt X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=2bfc3be0377680cdbce9ea0a56695fe5ba810471;p=my-stuff%2Fpy-logrotate.git dateext behandelt git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@228 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- diff --git a/LogRotateConfig.py b/LogRotateConfig.py index 47e3195..edb3da1 100755 --- a/LogRotateConfig.py +++ b/LogRotateConfig.py @@ -98,21 +98,37 @@ path_options = ( ) valid_periods = { - 'hourly': (1/24), - '2hourly': (1/12), - '4hourly': (1/6), - '6hourly': (1/4), - '12hourly': (1/2), - 'daily': 1, - '2daily': 2, - 'weekly': 7, - 'monthly': 30, - '2monthly': 60, - '4monthly': 120, - '6monthly': 182, - 'yearly': 365, + 'hourly': (1/24), + '2hourly': (1/12), + '4hourly': (1/6), + '6hourly': (1/4), + '12hourly': (1/2), + 'daily': 1, + '2daily': 2, + 'weekly': 7, + 'monthly': 30, + '2monthly': 60, + '4monthly': 120, + '6monthly': 182, + 'yearly': 365, } +yes_values = ( + '1', + 'on', + 'y', + 'yes', + 'true', +) + +no_values = ( + '0', + 'off', + 'n', + 'no', + 'false', +) + #======================================================================== @@ -1200,6 +1216,97 @@ class LogrotateConfigurationReader(object): directive['period'] = option_value return True + # get maximum age of old rotated log files + match = re.search(r'^(not?)?maxage$', option, re.IGNORECASE) + if match: + negated = False + if match.group(1) is not None: + negated = True + if (val is None) or re.search(r'^\s*$', val) is not None: + negated = True + option_value = 0 + if not negated: + try: + option_value = period2days(val, verbose = self.verbose) + except ValueError, e: + self.logger.warning( + ( _("Invalid maxage definition: »%s«") %(val) ) + ) + return False + if self.verbose > 4: + self.logger.debug( + ( _("Setting »maxage« to %f days. (file »%s«, line %s)") + % (option_value, filename, linenr) + ) + ) + directive['maxage'] = option_value + return True + + # Setting date extension of rotated log files + match = re.search(r'^(no)?dateext$', option, re.IGNORECASE) + if match: + + negated = False + if match.group(1) is not None: + negated = True + use_dateext = False + dateext = None + + if self.verbose > 4: + self.logger.debug( + ( _("Checking »dateext«, negated: »%s«. " + + "(file »%s«, line %s)") + % (str(negated), filename, linenr) + ) + ) + values = [] + if val is not None: + values = split_parts(val) + + if not negated: + first_val = '' + if len(values) > 0: + first_val = values[0].lower() + option_value = first_val + if first_val is None or \ + re.search(r'^\s*$', first_val) is not None: + option_value = 'true' + if self.verbose > 4: + self.logger.debug( + ( _("»dateext«: first_val: »%s«, option_value: »%s«. " + + "(file »%s«, line %s)") + % (first_val, option_value, filename, linenr) + ) + ) + if option_value in yes_values: + use_dateext = True + elif option_value in no_values: + use_dateext = False + else: + use_dateext = True + dateext = val + + if self.verbose > 4: + self.logger.debug( + ( _("Setting »dateext« to »%s«. (file »%s«, line %s)") + % (str(use_dateext), filename, linenr) + ) + ) + directive['dateext'] = use_dateext + + if dateext is not None: + if self.verbose > 4: + self.logger.debug( + ( _("Setting »datepattern« to »%s«. " + + "(file »%s«, line %s)") + % (dateext, filename, linenr) + ) + ) + directive['datepattern'] = dateext + + return True + + return True #------------------------------------------------------------ diff --git a/test/apache2 b/test/apache2 index fce39be..8931982 100644 --- a/test/apache2 +++ b/test/apache2 @@ -9,10 +9,13 @@ notifempty sharedscripts rotate 10 - error bla + #dateext '%Y%m%d' + dateext + #error bla weekly #period 4.5days 2 hours 3.4y size 1m + maxage 0.5y mail test@uhu-banane.de olddir /var/log/apache2/%Y-%m postrotate