'''
import re
+import sys
+
+from optparse import OptionError
+from optparse import OptionParser
+from optparse import OptionConflictError
+
revision = '$Revision$'
revision = re.sub( r'\$', '', revision )
#-------------------------------------------------------
def __init__( self, prog = '%prog',
version = None,
- description = '',
+ description = 'rotates and compresses system logs',
usage = 'Usage: %s [options]',
):
'''
'''
self.prog = prog
- self.version = version
+ '''
+ @ivar: The name of the calling process
+ @type: str
+ '''
+
+ self.version = __version__
+ '''
+ @ivar: The version string to use
+ @type: str
+ '''
+
self.description = description
+ '''
+ @ivar: description of the program
+ @type: str
+ '''
+
self.usage = usage %(prog)
+ '''
+ @ivar: the usage string in getopt help output
+ @type: str
+ '''
self.options = None
+ '''
+ @ivar: a dict with all given commandline options
+ after calling getOpts()
+ @type: dict or None
+ '''
+
self.args = None
- self.__options_set = False
- self.__action_set = None
+ '''
+ @ivar: a list with all commandline parameters, what are not options
+ @type: list or None
+ '''
+
self.parsed = False
+ '''
+ @ivar: flag, whether the parsing was done
+ @type: bool
+ '''
+
+ if version:
+ self.version = version
self.parser = OptionParser(
prog = self.prog,
description = self.description,
usage = self.usage
)
+ '''
+ @ivar: the working OptionParser Object
+ @type: optparse.OptionParser
+ '''
+
+ self._add_options()
+
+ #-------------------------------------------------------
+ def _add_options(self):
+ '''
+ Private function to add all necessary options
+ to the OptionParser object
+ '''
+
+ self.parser.add_option(
+ '--simulate',
+ '--test',
+ '-T',
+ default = False,
+ action = 'store_true',
+ dest = 'test',
+ help = 'set this do simulate commands'
+ )
+ self.parser.add_option(
+ '--verbose',
+ '-v',
+ default = False,
+ action = 'count',
+ dest = 'verbose',
+ help = 'set the verbosity level'
+ )
+
+ #----------------------------------------------------------------------
+ def getOpts(self):
+ '''
+ Wrapper function to OptionParser.parse_args().
+ Sets self.options and self.args with the appropriate values.
+ @return: None
+ '''
+ if not self.parsed:
+ self.options, self.args = self.parser.parse_args()
+ self.parsed = True
#========================================================================