#-------------------------------------------------------
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
'''
self.logger.error( _('Could not read configuration') )
sys.exit(1)
+ if config_check:
+ return
+
if not self._check_pidfile():
sys.exit(3)
return True
+ #------------------------------------------------------------
+ def rotate(self):
+ pass
+
+ #------------------------------------------------------------
+ def delete_oldfiles(self):
+ pass
+
+ #------------------------------------------------------------
+ def compress(self):
+ pass
+
#========================================================================
if __name__ == "__main__":
import pprint
import gettext
import os.path
+from datetime import datetime
from LogRotateGetopts import LogrotateOptParser
from LogRotateGetopts import LogrotateOptParserError
_ = t.lgettext
__ = t.lngettext
+ cur_proc = sys.argv[0]
+
opt_parser = LogrotateOptParser(
prog = "logrotate",
version = __version__,
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)
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")
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__":
"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."
+
"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 ""
+