From: Frank Brehm Date: Thu, 23 Jun 2011 16:33:48 +0000 (+0000) Subject: logrotate.py fertig X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=d11d0101236650b00c6c9b352a86144117fd3251;p=my-stuff%2Fpy-logrotate.git logrotate.py fertig git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@258 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- diff --git a/LogRotateHandler.py b/LogRotateHandler.py index 1c7c250..50af20e 100755 --- a/LogRotateHandler.py +++ b/LogRotateHandler.py @@ -62,36 +62,39 @@ class LogrotateHandler(object): #------------------------------------------------------- def __init__( self, config_file, - test = False, - verbose = 0, - force = False, - state_file = None, - pid_file = None, - mail_cmd = None, - local_dir = None, + test = False, + verbose = 0, + force = False, + config_check = False, + state_file = None, + pid_file = None, + mail_cmd = None, + local_dir = None, ): ''' Costructor. - @param config_file: the configuration file to use - @type config_file: str - @param prog: testmode, no real actions are made - @type prog: bool - @param verbose: verbosity (debug) level - @type verbose: int - @param force: Force file rotation - @type force: bool - @param state_file: Path of state file (different to configuration) - @type state_file: str or None - @param pid_file: Path of PID file (different to configuration) - @type pid_file: str or None - @param mail_cmd: command to send mail (instead of using - the Phyton email package) - @type mail_cmd: str or None - @param local_dir: The directory, where the i18n-files (*.mo) - are located. If None, then system default - (/usr/share/locale) is used. - @type local_dir: str or None + @param config_file: the configuration file to use + @type config_file: str + @param prog: testmode, no real actions are made + @type prog: bool + @param verbose: verbosity (debug) level + @type verbose: int + @param force: Force file rotation + @type force: bool + @param config_check: Checks only the configuration and does nothing + @type config_check: bool + @param state_file: Path of state file (different to configuration) + @type state_file: str or None + @param pid_file: Path of PID file (different to configuration) + @type pid_file: str or None + @param mail_cmd: command to send mail (instead of using + the Phyton email package) + @type mail_cmd: str or None + @param local_dir: The directory, where the i18n-files (*.mo) + are located. If None, then system default + (/usr/share/locale) is used. + @type local_dir: str or None @return: None ''' @@ -235,6 +238,9 @@ class LogrotateHandler(object): self.logger.error( _('Could not read configuration') ) sys.exit(1) + if config_check: + return + if not self._check_pidfile(): sys.exit(3) @@ -495,6 +501,18 @@ class LogrotateHandler(object): return True + #------------------------------------------------------------ + def rotate(self): + pass + + #------------------------------------------------------------ + def delete_oldfiles(self): + pass + + #------------------------------------------------------------ + def compress(self): + pass + #======================================================================== if __name__ == "__main__": diff --git a/logrotate.py b/logrotate.py index 1d40535..7ce1dc6 100755 --- a/logrotate.py +++ b/logrotate.py @@ -18,6 +18,7 @@ import sys import pprint import gettext import os.path +from datetime import datetime from LogRotateGetopts import LogrotateOptParser from LogRotateGetopts import LogrotateOptParserError @@ -50,6 +51,8 @@ def main(): _ = t.lgettext __ = t.lngettext + cur_proc = sys.argv[0] + opt_parser = LogrotateOptParser( prog = "logrotate", version = __version__, @@ -63,7 +66,7 @@ def main(): opt_parser.parser.print_help(sys.stderr) sys.exit(1) - if opt_parser.options.verbose > 2: + if opt_parser.options.verbose > 6: print _("Options") + ": " + pp.pformat(opt_parser.options) print _("Arguments") + ": " + pp.pformat(opt_parser.args) @@ -78,17 +81,41 @@ def main(): if verbose_level < 1: verbose_level = 1 + if not testmode: + print "\n" + ('#' * 79) + print ( _("[%(date)s]: %(prog)s is starting logrotation.") + % {'prog': cur_proc, 'date': datetime.now().isoformat(' '), } + ) + "\n" + + sep_line = '-' * 79 + + if testmode: + print _("Test mode is ON.") + if verbose_level > 0: + print (_("Verbose mode is ON on level: %d") % (verbose_level)) + if opt_parser.options.force: + print _("Force mode is ON.") + if opt_parser.options.configcheck: + print _("Configuration check only.") + + if not opt_parser.options.configcheck: + print "" + if verbose_level > 0: + print sep_line + "\n" + print _("Stage 1: reading configuration") + "\n" + lr_handler = None try: lr_handler = LogrotateHandler( opt_parser.args[0], - test = testmode, - verbose = verbose_level, - force = opt_parser.options.force, - state_file = opt_parser.options.statefile, - pid_file = opt_parser.options.pidfile, - mail_cmd = opt_parser.options.mailcmd, - local_dir = local_dir, + test = testmode, + verbose = verbose_level, + force = opt_parser.options.force, + config_check = opt_parser.options.configcheck, + state_file = opt_parser.options.statefile, + pid_file = opt_parser.options.pidfile, + mail_cmd = opt_parser.options.mailcmd, + local_dir = local_dir, ) except LogrotateHandlerError, e: sys.stderr.write(str(e) + "\n") @@ -97,6 +124,37 @@ def main(): if opt_parser.options.verbose > 2: print _("Handler object structure") + ':\n' + str(lr_handler) + if opt_parser.options.configcheck: + sys.exit(0) + + print "" + if verbose_level > 0: + print sep_line + "\n" + print _("Stage 2: underlying log rotation") + "\n" + lr_handler.rotate() + + print "" + if verbose_level > 0: + print sep_line + "\n" + print _("Stage 3: deleting of old logfiles") + "\n" + lr_handler.delete_oldfiles() + + print "" + if verbose_level > 0: + print sep_line + "\n" + print _("Stage 4: compression of old log files") + "\n" + lr_handler.compress() + + lr_handler = None + + if not testmode: + print "" + print ( _("[%(date)s]: %(prog)s ended logrotation.") + % {'prog': cur_proc, 'date': datetime.now().isoformat(' '), } + ) + "\n" + + sys.exit(0) + #======================================================================== if __name__ == "__main__": diff --git a/po/pylogrotate.de.po b/po/pylogrotate.de.po index 03b5f1a..4e4a5d5 100644 --- a/po/pylogrotate.de.po +++ b/po/pylogrotate.de.po @@ -20,14 +20,58 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: logrotate.py:67 +#: logrotate.py:70 msgid "Options" msgstr "Optionen" -#: logrotate.py:68 +#: logrotate.py:71 msgid "Arguments" msgstr "Argumente" -#: logrotate.py:92 +#: logrotate.py:86 +#, python-format +msgid "[%(date)s]: %(prog)s is starting logrotation." +msgstr "[%(date)s]: %(prog)s beginnt mit Logratation." + +#: logrotate.py:93 +msgid "Test mode is ON." +msgstr "Testmodus ist AN." + +#: logrotate.py:95 +#, python-format +msgid "Verbose mode is ON on level: %d" +msgstr "Ausführlichkeitmodus is AN auf Level: %d" + +#: logrotate.py:97 +msgid "Force mode is ON." +msgstr "Zwangsmodus ist AN." + +#: logrotate.py:99 +msgid "Configuration check only." +msgstr "Nur Überprüfung der Konfiguration." + +#: logrotate.py:105 +msgid "Stage 1: reading configuration" +msgstr "Phase 1: Einlesen der Konfiguration" + +#: logrotate.py:125 msgid "Handler object structure" msgstr "Struktur des Handlerobjektes" + +#: logrotate.py:133 +msgid "Stage 2: underlying log rotation" +msgstr "Phase 2: Eigentliches Rotieren" + +#: logrotate.py:139 +msgid "Stage 3: deleting of old logfiles" +msgstr "Phase 3: Löschen der alten Logdateien" + +#: logrotate.py:145 +msgid "Stage 4: compression of old log files" +msgstr "Phase 4: Komprimieren der alten Logdateien" + +#: logrotate.py:152 +#, python-format +msgid "[%(date)s]: %(prog)s ended logrotation." +msgstr "[%(date)s]: %(prog)s hat Logrotation beendet." + diff --git a/po/pylogrotate.pot b/po/pylogrotate.pot index dd962d9..759c530 100644 --- a/po/pylogrotate.pot +++ b/po/pylogrotate.pot @@ -20,14 +20,58 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: logrotate.py:67 +#: logrotate.py:70 msgid "Options" msgstr "" -#: logrotate.py:68 +#: logrotate.py:71 msgid "Arguments" msgstr "" -#: logrotate.py:92 +#: logrotate.py:86 +#, python-format +msgid "[%(date)s]: %(prog)s is starting logrotation." +msgstr "" + +#: logrotate.py:93 +msgid "Test mode is ON." +msgstr "" + +#: logrotate.py:95 +#, python-format +msgid "Verbose mode is ON on level: %d" +msgstr "" + +#: logrotate.py:97 +msgid "Force mode is ON." +msgstr "" + +#: logrotate.py:99 +msgid "Configuration check only." +msgstr "" + +#: logrotate.py:105 +msgid "Stage 1: reading configuration" +msgstr "" + +#: logrotate.py:125 msgid "Handler object structure" msgstr "" + +#: logrotate.py:133 +msgid "Stage 2: underlying log rotation" +msgstr "" + +#: logrotate.py:139 +msgid "Stage 3: deleting of old logfiles" +msgstr "" + +#: logrotate.py:145 +msgid "Stage 4: compression of old log files" +msgstr "" + +#: logrotate.py:152 +#, python-format +msgid "[%(date)s]: %(prog)s ended logrotation." +msgstr "" +