__license__ = 'GPL3'
+#========================================================================
+
+class LogrotateOptParserError(Exception):
+ '''
+ Class for exceptions in this module, escpacially
+ due to false commandline options.
+ '''
+
#========================================================================
class LogrotateOptParser(object):
@type: str
'''
- self.description = 'rotates and compresses system logs'
+ self.description = 'Rotates and compresses system logs.'
'''
@ivar: description of the program
@type: str
# Deprecated options for compatibilty to logrotate
group = OptionGroup(self.parser, "Deprecated options")
+ group.add_option(
+ '--mail',
+ '-m',
+ dest = "mailcmd",
+ metavar = 'CMD',
+ help = ( ( 'Should tell %s which command to use '
+ + 'when mailing logs - not used.' )
+ %(str(self.prog)) ),
+ )
+
+ self.parser.add_option_group(group)
+
######
# Option group for common options
self.options, self.args = self.parser.parse_args()
self.parsed = True
+ if self.options.force and self.options.configcheck:
+ raise LogrotateOptParserError('Invalid usage of --force and '
+ + '--config-check.')
+
+ if self.args is None:
+ 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')
+
#========================================================================
if __name__ == "__main__":
import pprint
from LogRotateGetopts import LogrotateOptParser;
+from LogRotateGetopts import LogrotateOptParserError;
revision = '$Revision$'
revision = re.sub( r'\$', '', revision )
version = __version__,
)
pp = pprint.PrettyPrinter(indent=4)
- opt_parser.getOpts()
+ try:
+ opt_parser.getOpts()
+ except LogrotateOptParserError, e:
+ sys.stderr.write(str(e) + "\n\n")
+ opt_parser.parser.print_help(sys.stderr)
+ sys.exit(1)
print "Options: " + pp.pformat(opt_parser.options)
print "Arguments: " + pp.pformat(opt_parser.args)