import re
import sys
+import gettext
from optparse import OptionError
from optparse import OptionParser
#-------------------------------------------------------
def __init__( self, prog = '%prog',
version = None,
+ local_dir = None,
):
'''
Costructor.
- @param prog: The name of the calling process (e.g. sys.argv[0])
- @type prog: str
- @param version: The version string to use
- @type version: str
+
+ @param prog: The name of the calling process (e.g. sys.argv[0])
+ @type prog: str
+ @param version: The version string to use
+ @type version: str
+ @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
'''
@type: str
'''
- self.description = 'Rotates and compresses system logs.'
+ self.local_dir = local_dir
+ '''
+ @ivar: The directory, where the i18n-files (*.mo) are located.
+ @type: str or None
+ '''
+
+ self.t = gettext.translation(
+ 'LogRotateGetopts',
+ local_dir,
+ fallback = True
+ )
+ '''
+ @ivar: a gettext translation object
+ @type: gettext.translation
+ '''
+
+ _ = self.t.lgettext
+
+ self.description = _('Rotates, compresses and mails system logs.')
'''
@ivar: description of the program
@type: str
'''
- self.usage = "Usage: %s [options] <configfile>\n" %(prog)
+ self.usage = ( _("%s [options] <configfile>") + "\n" ) %(prog)
'''
@ivar: the usage string in getopt help output
@type: str
to the OptionParser object
'''
+ _ = self.t.ugettext
+ __ = self.t.ungettext
+
if self.parser.has_option('--help'):
self.parser.remove_option('--help')
default = False,
action = 'store_true',
dest = 'test',
- help = 'set this do simulate commands'
+ help = _('set this do simulate commands'),
)
self.parser.add_option(
default = False,
action = 'count',
dest = 'verbose',
- help = 'set the verbosity level'
+ help = _('set the verbosity level'),
)
self.parser.add_option(
default = False,
action = 'store_true',
dest = 'debug',
- help = "Don't do anything, just test (implies -v and -T)"
+ help = _("Don't do anything, just test (implies -v and -T)"),
)
self.parser.add_option(
default = False,
action = 'store_true',
dest = 'force',
- help = "Force file rotation"
+ help = _("Force file rotation"),
)
self.parser.add_option(
default = False,
action = 'store_true',
dest = 'configcheck',
- help = "Checks only the given configuration file and does "
- + "nothing. Conflicts with -f",
+ help = _("Checks only the given configuration file and does "
+ + "nothing. Conflicts with -f."),
)
self.parser.add_option(
'-s',
dest = "statefile",
metavar = 'FILE',
- help = 'Path of state file (different to configuration)',
+ help = _('Path of state file (different to configuration)'),
)
- ######
- # Deprecated options for compatibilty to logrotate
- group = OptionGroup(self.parser, "Deprecated options")
-
- group.add_option(
+ self.parser.add_option(
'--mail',
'-m',
dest = "mailcmd",
metavar = 'CMD',
- help = ( ( 'Should tell %s which command to use '
- + 'when mailing logs - not used.' )
- %(str(self.prog)) ),
+ help = _('Command to send mail (instead of using '
+ + 'the Phyton email package)'),
)
- self.parser.add_option_group(group)
-
######
# Option group for common options
- group = OptionGroup(self.parser, "Common options")
+ group = OptionGroup(self.parser, _("Common options"))
group.add_option(
'-h',
default = False,
action = 'help',
dest = 'help',
- help = 'shows a help message and exit'
+ help = _('Shows a help message and exit.'),
)
group.add_option(
default = False,
action = 'store_true',
dest = 'usage',
- help = 'Display brief usage message and exit'
+ help = _('Display brief usage message and exit.'),
)
group.add_option(
default = False,
action = 'version',
dest = 'version',
- help = 'shows the version number of the program and exit',
+ help = _('Shows the version number of the program and exit.'),
)
self.parser.add_option_group(group)
@return: None
'''
+ _ = self.t.ugettext
+
if not self.parsed:
self.options, self.args = self.parser.parse_args()
self.parsed = True
sys.exit(0)
if self.options.force and self.options.configcheck:
- raise LogrotateOptParserError('Invalid usage of --force and '
- + '--config-check.')
+ raise LogrotateOptParserError( _('Invalid usage of --force and '
+ + '--config-check.') )
- if self.args is None:
- raise LogrotateOptParserError('No configuration file given.')
+ if self.args is None or len(self.args) < 1:
+ raise LogrotateOptParserError( _('No configuration file given.') )
if len(self.args) != 1:
- raise LogrotateOptParserError('Only one configuration file is allowed.')
-
- if self.options.mailcmd:
- sys.stderr.write('Usage of --mail is deprecated '
- + 'in this version.\n\n')
+ raise LogrotateOptParserError(
+ _('Only one configuration file is allowed.')
+ )
#========================================================================
if __name__ == "__main__":
- main()
+ pass
#========================================================================
@contact: frank@brehm-online.com
@license: GPL3
@copyright: (c) 2010-2011 by Frank Brehm, Berlin
-@version: 0.1.0
+@version: 0.2.0
@summary: rotates and compress system logs
'''
import gettext
import os.path
-from LogRotateGetopts import LogrotateOptParser;
-from LogRotateGetopts import LogrotateOptParserError;
+from LogRotateGetopts import LogrotateOptParser
+from LogRotateGetopts import LogrotateOptParserError
revision = '$Revision$'
revision = re.sub( r'\$', '', revision )
__author__ = 'Frank Brehm'
__copyright__ = '(C) 2011 by Frank Brehm, Berlin'
__contact__ = 'frank@brehm-online.com'
-__version__ = '0.1.0 ' + revision
+__version__ = '0.2.0 ' + revision
__license__ = 'GPL3'
basedir = os.path.realpath(os.path.dirname(sys.argv[0]))
#print "Basedir: %s" % ( basedir )
+ local_dir = os.path.join(basedir, 'po')
+ if not os.path.isdir(local_dir):
+ local_dir = None
+ #print "Locale-Dir: %s" % ( local_dir )
+
+ t = gettext.translation('pylogrotate', local_dir, fallback=True)
+ _ = t.lgettext
+ __ = t.lngettext
opt_parser = LogrotateOptParser(
- prog = "logrotate",
- version = __version__,
+ prog = "logrotate",
+ version = __version__,
+ local_dir = local_dir,
)
pp = pprint.PrettyPrinter(indent=4)
try:
opt_parser.parser.print_help(sys.stderr)
sys.exit(1)
- print "Options: " + pp.pformat(opt_parser.options)
- print "Arguments: " + pp.pformat(opt_parser.args)
+ print _("Options") + ": " + pp.pformat(opt_parser.options)
+ print _("Arguments") + ": " + pp.pformat(opt_parser.args)
#========================================================================
--- /dev/null
+# German translations for pylogrotate package
+# German messages for pylogrotate.
+# Copyright (C) 2011 THE pylogrotate'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the pylogrotate package.
+# Frank Brehm <frank@brehm-online.com>, 2011.
+#
+# $Id$
+# $URL$
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: LogRotateGetopts 0.2\n"
+"Report-Msgid-Bugs-To: Frank Brehm <frank@brehm-online.com>\n"
+"POT-Creation-Date: 2011-04-18 18:40+0200\n"
+"PO-Revision-Date: 2011-04-19 10:53+0200\n"
+"Last-Translator: Frank Brehm <frank@brehm-online.com>\n"
+"Language-Team: German\n"
+"Language: de\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: LogRotateGetopts.py:106
+msgid "Rotates, compresses and mails system logs."
+msgstr "Rotiert, komprimiert und versended Systemlogdateien per Mail"
+
+#: LogRotateGetopts.py:112
+#, python-format
+msgid "%s [options] <configfile>"
+msgstr "%s [Optionen] <Konfigurationsdatei>"
+
+#: LogRotateGetopts.py:180
+msgid "set this do simulate commands"
+msgstr "Testmodus, Kommandos werden nur simuliert"
+
+#: LogRotateGetopts.py:189
+msgid "set the verbosity level"
+msgstr "bestimmt das Ausführlichkeits-Niveau"
+
+#: LogRotateGetopts.py:198
+msgid "Don't do anything, just test (implies -v and -T)"
+msgstr "Testmodus, Kommandos werden nur simuliert (beinhaltet -v und -T)"
+
+#: LogRotateGetopts.py:207
+msgid "Force file rotation"
+msgstr "Erzwingt Logratation"
+
+#: LogRotateGetopts.py:216
+msgid "Checks only the given configuration file and does nothing. Conflicts with -f."
+msgstr "Überprüft nur die gegebene Konfigurationsdatei und führt nichts aus. Beißt sich mit -f."
+
+#: LogRotateGetopts.py:225
+msgid "Path of state file (different to configuration)"
+msgstr "Pfad zur Statusdatei (im Unterschied zur Konfiguration)"
+
+#: LogRotateGetopts.py:233
+msgid "Command to send mail (instead of using the Phyton email package)"
+msgstr "Befehl zum Mailversand (anstelle der Verwendung des Python email-Paketes"
+
+#. #####
+#. Option group for common options
+#: LogRotateGetopts.py:240
+msgid "Common options"
+msgstr "Allgemeine Optionen"
+
+#: LogRotateGetopts.py:249
+msgid "Shows a help message and exit."
+msgstr "Zeigt einen Hilfetext und beendet sich."
+
+#: LogRotateGetopts.py:257
+msgid "Display brief usage message and exit."
+msgstr "Zeigt einen kurzen Text zur Verwendung und beendet sich."
+
+#: LogRotateGetopts.py:266
+msgid "Shows the version number of the program and exit."
+msgstr "Zeigt die Versionsnummer des Programms und beendet sich."
+
+#: LogRotateGetopts.py:290
+msgid "Invalid usage of --force and --config-check."
+msgstr "Ungültige Verwendung von --force und --config-check."
+
+#: LogRotateGetopts.py:294
+msgid "No configuration file given."
+msgstr "Keine Konfigurationsdatei angegeben."
+
+#: LogRotateGetopts.py:298
+msgid "Only one configuration file is allowed."
+msgstr "Es ist nur die Angabe einer Konfigurationsdatei erlaubt."
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the pylogrotate package.
+# Frank Brehm <frank@brehm-online.com>, 2011.
+#
+# $Id: $
+# $URL: $
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: pylogrotate 0.2\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-04-18 18:40+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: LogRotateGetopts.py:106
+msgid "Rotates, compresses and mails system logs."
+msgstr ""
+
+#: LogRotateGetopts.py:112
+#, python-format
+msgid "%s [options] <configfile>"
+msgstr ""
+
+#: LogRotateGetopts.py:180
+msgid "set this do simulate commands"
+msgstr ""
+
+#: LogRotateGetopts.py:189
+msgid "set the verbosity level"
+msgstr ""
+
+#: LogRotateGetopts.py:198
+msgid "Don't do anything, just test (implies -v and -T)"
+msgstr ""
+
+#: LogRotateGetopts.py:207
+msgid "Force file rotation"
+msgstr ""
+
+#: LogRotateGetopts.py:216
+msgid "Checks only the given configuration file and does nothing. Conflicts with -f."
+msgstr ""
+
+#: LogRotateGetopts.py:225
+msgid "Path of state file (different to configuration)"
+msgstr ""
+
+#: LogRotateGetopts.py:233
+msgid "Command to send mail (instead of using the Phyton email package)"
+msgstr ""
+
+#. #####
+#. Option group for common options
+#: LogRotateGetopts.py:240
+msgid "Common options"
+msgstr ""
+
+#: LogRotateGetopts.py:249
+msgid "Shows a help message and exit."
+msgstr ""
+
+#: LogRotateGetopts.py:257
+msgid "Display brief usage message and exit."
+msgstr ""
+
+#: LogRotateGetopts.py:266
+msgid "Shows the version number of the program and exit."
+msgstr ""
+
+#: LogRotateGetopts.py:290
+msgid "Invalid usage of --force and --config-check."
+msgstr ""
+
+#: LogRotateGetopts.py:294
+msgid "No configuration file given."
+msgstr ""
+
+#: LogRotateGetopts.py:298
+msgid "Only one configuration file is allowed."
+msgstr ""
--- /dev/null
+#
+# Makefile for i18n-Objects in PyLogrotate
+#
+# $Id$
+# $URL$
+#
+
+all: pylogrotate.de.mo LogRotateGetopts.de.mo
+
+pylogrotate.de.mo: pylogrotate.de.po
+ @echo
+ @echo "Compiling $@ ..."
+ msgfmt -o pylogrotate.de.mo --check -v pylogrotate.de.po
+ @if [ ! -d de_DE/LC_MESSAGES ] ; then mkdir -vp de_DE/LC_MESSAGES; fi
+ @cp -pv pylogrotate.de.mo de_DE/LC_MESSAGES/pylogrotate.mo
+
+LogRotateGetopts.de.mo: LogRotateGetopts.de.po
+ @echo
+ @echo "Compiling $@ ..."
+ msgfmt -o LogRotateGetopts.de.mo --check -v LogRotateGetopts.de.po
+ @if [ ! -d de_DE/LC_MESSAGES ] ; then mkdir -vp de_DE/LC_MESSAGES; fi
+ @cp -pv LogRotateGetopts.de.mo de_DE/LC_MESSAGES/LogRotateGetopts.mo
+
--- /dev/null
+# German translations for pylogrotate package.
+# Copyright (C) 2011 THE pylogrotate'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the pylogrotate package.
+# Frank Brehm <frank@brehm-online.com>, 2011.
+#
+# $Id$
+# $URL$
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: pylogrotate 0.2\n"
+"Report-Msgid-Bugs-To: Frank Brehm <frank@brehm-online.com>\n"
+"POT-Creation-Date: 2011-04-18 18:35+0200\n"
+"PO-Revision-Date: 2011-04-18 21:10+0200\n"
+"Last-Translator: Frank Brehm <frank@brehm-online.com>\n"
+"Language-Team: German\n"
+"Language: de\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: logrotate.py:54
+msgid "Options"
+msgstr "Optionen"
+
+#: logrotate.py:55
+msgid "Arguments"
+msgstr "Argumente"
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the pylogrotate package.
+# Frank Brehm <frank@brehm-online.com>, 2011.
+#
+# $Id: $
+# $URL: $
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-04-18 18:35+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: logrotate.py:54
+msgid "Options"
+msgstr ""
+
+#: logrotate.py:55
+msgid "Arguments"
+msgstr ""