From 3979476b39dba55177729070a084069b48e0ac5a Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 9 May 2011 21:13:39 +0000 Subject: [PATCH] =?utf8?q?Option=20=C2=BBsize=C2=AB=20behandelt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@231 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- LogRotateCommon.py | 15 +++++++++------ LogRotateConfig.py | 21 ++++++++++++++++++++- test/apache2 | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/LogRotateCommon.py b/LogRotateCommon.py index 2092fc4..84f46ff 100755 --- a/LogRotateCommon.py +++ b/LogRotateCommon.py @@ -213,29 +213,32 @@ def human2bytes(value, si_conform = True, use_locale_radix = False, verbose = 0) if re.search(r'^\s*(?:b(?:yte)?)?\s*$', prefix, re.IGNORECASE): factor = long(1) - elif re.search(r'^\s*k[bB](?i:yte)?\s*$', prefix): + elif re.search(r'^\s*k[bB](?:[Yy][Tt][Ee])?\s*$', prefix): factor = factor_si - elif re.search(r'^\s*Ki?[bB](?i:yte)?\s*$', prefix): + elif re.search(r'^\s*Ki?[bB](?:[Yy][Tt][Ee])?\s*$', prefix): factor = factor_bin - elif re.search(r'^\s*MB(?:yte)?\s*$', prefix, re.IGNORECASE): + elif re.search(r'^\s*M(?:B(?:yte)?)?\s*$', prefix, re.IGNORECASE): factor = (factor_si * factor_si) elif re.search(r'^\s*MiB(?:yte)?\s*$', prefix, re.IGNORECASE): factor = (factor_bin * factor_bin) - elif re.search(r'^\s*GB(?:yte)?\s*$', prefix, re.IGNORECASE): + elif re.search(r'^\s*G(?:B(?:yte)?)?\s*$', prefix, re.IGNORECASE): factor = (factor_si * factor_si * factor_si) elif re.search(r'^\s*GiB(?:yte)?\s*$', prefix, re.IGNORECASE): factor = (factor_bin * factor_bin * factor_bin) - elif re.search(r'^\s*TB(?:yte)?\s*$', prefix, re.IGNORECASE): + elif re.search(r'^\s*T(?:B(?:yte)?)?\s*$', prefix, re.IGNORECASE): factor = (factor_si * factor_si * factor_si * factor_si) elif re.search(r'^\s*TiB(?:yte)?\s*$', prefix, re.IGNORECASE): factor = (factor_bin * factor_bin * factor_bin * factor_bin) - elif re.search(r'^\s*PB(?:yte)?\s*$', prefix, re.IGNORECASE): + elif re.search(r'^\s*P(?:B(?:yte)?)?\s*$', prefix, re.IGNORECASE): factor = (factor_si * factor_si * factor_si * factor_si * factor_si) elif re.search(r'^\s*PiB(?:yte)?\s*$', prefix, re.IGNORECASE): factor = (factor_bin * factor_bin * factor_bin * factor_bin * factor_bin) else: raise ValueError("human2bytes(): Couldn't detect prefix »%s«." %(prefix)) + if verbose > 5: + sys.stderr.write("human2bytes(): found factor %d\n" % (factor)) + return long(factor * value_float) #------------------------------------------------------------------------ diff --git a/LogRotateConfig.py b/LogRotateConfig.py index 2dffab7..96edcfe 100755 --- a/LogRotateConfig.py +++ b/LogRotateConfig.py @@ -22,7 +22,7 @@ import os.path import pwd import grp -from LogRotateCommon import split_parts, email_valid, period2days +from LogRotateCommon import split_parts, email_valid, period2days, human2bytes revision = '$Revision$' revision = re.sub( r'\$', '', revision ) @@ -1327,6 +1327,25 @@ class LogrotateConfigurationReader(object): directive['olddir']['group'] = group return True + # Check for minimum size for ratation + match = re.search(r'^size(?:(?:\s*=|\s)|$)', line, re.IGNORECASE) + if match: + size_str = re.sub(r'^size(?:\s*=\s*|\s+)', '', line) + if self.verbose > 5: + self.logger.debug( ( _("Checking for option »size«, value: »%s« ... (file »%s«, line %s)") % (size_str, filename, linenr))) + if size_str is None: + self.logger.warning( _("Failing size definition.")) + return False + size_bytes = None + try: + size_bytes = human2bytes(size_str, verbose = self.verbose) + except ValueError, e: + self.logger.warning( ( _("Invalid definition for »size«: »%s«.") %(size_str))) + return False + if self.verbose > 4: + self.logger.debug( ( _("Got a rotation size of %d bytes. (file »%s«, line %s)") % (size_bytes, filename, linenr))) + directive['size'] = size_bytes + return True diff --git a/test/apache2 b/test/apache2 index ccd17a5..c559729 100644 --- a/test/apache2 +++ b/test/apache2 @@ -14,7 +14,7 @@ #error bla weekly #period 4.5days 2 hours 3.4y - size 1m + size 1M maxage 0.5y mail test@uhu-banane.de #olddir /var/log/apache2/%Y-%m -- 2.39.5