Cat
arguments.py
Go to the documentation of this file.
1 """
2 CAT usage :
3 
4 cat.py [-o <...> --options<=...>] <script>
5 
6  -b / --banner [True] : no banner at startup
7  -i / --file <file> : load a python initialisation script file <filename>
8  -q / --quit [False] : stop after script execution
9  -h / --help : print out this message
10  -g / --gui : starts cat in gui mode
11  -o / --output <level> : set the requested output level
12  level=VERBOSE, DEBUG, INFO, WARNING, FATAL
13  -s / --shell [True] : starts cat shell session
14  -v / --version : print out version number
15 """
16 
17 import os, sys, getopt, code
18 import version
19 
20 class arguments:
21  def __init__(self, argv=None):
22  self.banner=False
23  self.file=""
24  self.bkgMode=False
25  self.output="INFO"
26  self.shellMode=True
27  self.decode(argv)
28 
29  def decode(self, argv):
30  if argv==None:
31  argv = sys.argv
32  # parse command line options
33  try:
34  try:
35  opts, args = getopt.getopt(argv[1:],"bf:ghqo:sv",
36  ["banner","file=","gui","help","quit","output=","shell","version"])
37  except getopt.error, msg:
38  raise Usage(msg)
39  # check argument
40  if (len(args)>2):
41  raise Usage("Too many arguments.")
42  vers=version.version()
43  # process options
44  for o, a in opts:
45  if o in ("-b", "--banner"):
46  self.banner=False
47  if o in ("-f", "--file"):
48  self.file=a
49  if (False==os.path.exists(a)):
50  raise Usage("File "+a+" does not exists.")
51  return 2
52  if o in ("-g", "--gui"):
53  self.shellMode=False
54  return
55  if o in ("-h", "--help"):
56  print __doc__
57  return 2
58  if o in ("-s", "--shell"):
59  self.shellMode=True
60  return
61  if o in ("-q", "--quit"):
62  print "Not implemented."
63  return 2
64  if o in ("-o", "--output"):
65  self.output=a
66  return
67  if o in ("-v", "--version"):
68  vers.info()
69  return 2
70  except Usage, err:
71  print >>sys.stderr, err.msg
72  print __doc__
73 
74  def printout(self):
75  print "Cat options are : "
76  if (self.banner):
77  print " Banner : True"
78  else:
79  print " Banner : False"
80  print " File =",self.file
81  if (self.bkgMode):
82  print " Background mode : True"
83  else:
84  print " Background mode : False"
85  print " OutputLevel =",self.output
86  if (self.shellMode):
87  print " Shell mode : True"
88  else:
89  print " Shell mode : False"
90 
91 
92 class Usage(Exception):
93  def __init__(self, msg):
94  self.msg = msg
95 
def __init__(self, msg)
Definition: arguments.py:93
def printout(self)
Definition: arguments.py:74
def decode(self, argv)
Definition: arguments.py:29
def __init__(self, argv=None)
Definition: arguments.py:21