Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
Cmd Class Reference
Inheritance diagram for Cmd:
Pdb ProfileBrowser

Public Member Functions

def __init__
 
def cmdloop
 
def precmd
 
def postcmd
 
def preloop
 
def postloop
 
def parseline
 
def onecmd
 
def emptyline
 
def default
 
def completedefault
 
def completenames
 
def complete
 
def get_names
 
def complete_help
 
def do_help
 
def print_topics
 

Data Fields

 lastcmd
 
 completion_matches
 

Static Public Attributes

 prompt = PROMPT
 
 identchars = IDENTCHARS
 
string ruler = '='
 
string lastcmd = ''
 
list cmdqueue = []
 
 intro = None
 
string doc_leader = ""
 
string doc_header = "Documented commands (type help <topic>):"
 
string misc_header = "Miscellaneous help topics:"
 
string undoc_header = "Undocumented commands:"
 
string nohelp = "*** No help on %s"
 
int use_rawinput = 1
 

Detailed Description

Definition at line 55 of file cmd.py.

Constructor & Destructor Documentation

def __init__ (   self,
  completekey = 'tab' 
)

Definition at line 69 of file cmd.py.

References Cmd.complete(), and quest_tutorial.complete.

69 
70  def __init__(self, completekey='tab'):
71  if completekey:
72  try:
73  import readline
74  readline.set_completer(self.complete)
75  readline.parse_and_bind(completekey+": complete")
76  except ImportError:
77  pass

Member Function Documentation

def cmdloop (   self,
  intro = None 
)

Definition at line 78 of file cmd.py.

References Cmd.cmdqueue, Cmd.intro, Cmd.onecmd(), Cmd.postcmd(), Cmd.postloop(), Cmd.precmd(), Cmd.preloop(), Cmd.prompt, and Cmd.use_rawinput.

78 
79  def cmdloop(self, intro=None):
80  self.preloop()
81  if intro is not None:
82  self.intro = intro
83  if self.intro:
84  print self.intro
85  stop = None
86  while not stop:
87  if self.cmdqueue:
88  line = self.cmdqueue[0]
89  del self.cmdqueue[0]
90  else:
91  if self.use_rawinput:
92  try:
93  line = raw_input(self.prompt)
94  except EOFError:
95  line = 'EOF'
96  else:
97  sys.stdout.write(self.prompt)
98  sys.stdout.flush()
99  line = sys.stdin.readline()
100  if not len(line):
101  line = 'EOF'
102  else:
103  line = line[:-1] # chop \n
104  line = self.precmd(line)
105  stop = self.onecmd(line)
106  stop = self.postcmd(stop, line)
107  self.postloop()
def complete (   self,
  text,
  state 
)
Return the next possible completion for 'text'.

If a command has not been entered, then complete against command list.
Otherwise try to call complete_<command> to get list of completions.

Definition at line 166 of file cmd.py.

References Cmd.completedefault(), Cmd.completenames(), and Cmd.parseline().

167  def complete(self, text, state):
168  """Return the next possible completion for 'text'.
169 
170  If a command has not been entered, then complete against command list.
171  Otherwise try to call complete_<command> to get list of completions.
172  """
173  if state == 0:
174  import readline
175  origline = readline.get_line_buffer()
176  line = origline.lstrip()
177  stripped = len(origline) - len(line)
178  begidx = readline.get_begidx() - stripped
179  endidx = readline.get_endidx() - stripped
180  if begidx>0:
181  cmd, args, foo = self.parseline(line)
182  if cmd == '':
183  compfunc = self.completedefault
184  else:
185  try:
186  compfunc = getattr(self, 'complete_' + cmd)
187  except AttributeError:
188  compfunc = self.completedefault
189  else:
190  compfunc = self.completenames
191  self.completion_matches = compfunc(text, line, begidx, endidx)
192  try:
193  return self.completion_matches[state]
194  except IndexError:
195  return None
def complete_help (   self,
  args 
)

Definition at line 209 of file cmd.py.

References Cmd.completenames().

210  def complete_help(self, *args):
211  return self.completenames(*args)
def completedefault (   self,
  ignored 
)

Definition at line 159 of file cmd.py.

160  def completedefault(self, *ignored):
161  return []
def completenames (   self,
  text,
  ignored 
)

Definition at line 162 of file cmd.py.

References Cmd.get_names().

163  def completenames(self, text, *ignored):
164  dotext = 'do_'+text
165  return [a[3:] for a in self.get_names() if a.startswith(dotext)]
def default (   self,
  line 
)

Definition at line 156 of file cmd.py.

157  def default(self, line):
158  print '*** Unknown syntax:', line
def do_help (   self,
  arg 
)

Definition at line 212 of file cmd.py.

References Cmd.doc_header, Cmd.doc_leader, Cmd.get_names(), Cmd.misc_header, Cmd.nohelp, Cmd.print_topics(), and Cmd.undoc_header.

213  def do_help(self, arg):
214  if arg:
215  # XXX check arg syntax
216  try:
217  func = getattr(self, 'help_' + arg)
218  except:
219  try:
220  doc=getattr(self, 'do_' + arg).__doc__
221  if doc:
222  print doc
223  return
224  except:
225  pass
226  print self.nohelp % (arg,)
227  return
228  func()
229  else:
230  names = self.get_names()
231  cmds_doc = []
232  cmds_undoc = []
233  help = {}
234  for name in names:
235  if name[:5] == 'help_':
236  help[name[5:]]=1
237  names.sort()
238  # There can be duplicates if routines overridden
239  prevname = ''
240  for name in names:
241  if name[:3] == 'do_':
242  if name == prevname:
243  continue
244  prevname = name
245  cmd=name[3:]
246  if help.has_key(cmd):
247  cmds_doc.append(cmd)
248  del help[cmd]
249  elif getattr(self, name).__doc__:
250  cmds_doc.append(cmd)
251  else:
252  cmds_undoc.append(cmd)
253  print self.doc_leader
254  self.print_topics(self.doc_header, cmds_doc, 15,80)
255  self.print_topics(self.misc_header, help.keys(),15,80)
256  self.print_topics(self.undoc_header, cmds_undoc, 15,80)
def emptyline (   self)

Definition at line 152 of file cmd.py.

References Cmd.lastcmd, and Cmd.onecmd().

153  def emptyline(self):
154  if self.lastcmd:
155  return self.onecmd(self.lastcmd)
def get_names (   self)

Definition at line 196 of file cmd.py.

References SymbolTable.__class__, and sre_parse.dir.

197  def get_names(self):
198  # Inheritance says we have to look in class and
199  # base classes; order is not important.
200  names = []
201  classes = [self.__class__]
202  while classes:
203  aclass = classes[0]
204  if aclass.__bases__:
205  classes = classes + list(aclass.__bases__)
206  names = names + dir(aclass)
207  del classes[0]
208  return names
def onecmd (   self,
  line 
)

Definition at line 136 of file cmd.py.

References Cmd.default(), Cmd.emptyline(), and Cmd.parseline().

137  def onecmd(self, line):
138  cmd, arg, line = self.parseline(line)
139  if not line:
140  return self.emptyline()
141  if cmd is None:
142  return self.default(line)
143  self.lastcmd = line
144  if cmd == '':
145  return self.default(line)
146  else:
147  try:
148  func = getattr(self, 'do_' + cmd)
149  except AttributeError:
150  return self.default(line)
151  return func(arg)
def parseline (   self,
  line 
)

Definition at line 120 of file cmd.py.

121  def parseline(self, line):
122  line = line.strip()
123  if not line:
124  return None, None, line
125  elif line[0] == '?':
126  line = 'help ' + line[1:]
127  elif line[0] == '!':
128  if hasattr(self, 'do_shell'):
129  line = 'shell ' + line[1:]
130  else:
131  return None, None, line
132  i, n = 0, len(line)
133  while i < n and line[i] in self.identchars: i = i+1
134  cmd, arg = line[:i], line[i:].strip()
135  return cmd, arg, line
def postcmd (   self,
  stop,
  line 
)

Definition at line 111 of file cmd.py.

112  def postcmd(self, stop, line):
113  return stop
def postloop (   self)

Definition at line 117 of file cmd.py.

118  def postloop(self):
119  pass
def precmd (   self,
  line 
)

Definition at line 108 of file cmd.py.

109  def precmd(self, line):
110  return line
def preloop (   self)

Definition at line 114 of file cmd.py.

115  def preloop(self):
116  pass
def print_topics (   self,
  header,
  cmds,
  cmdlen,
  maxcol 
)

Definition at line 257 of file cmd.py.

References Cmd.ruler.

258  def print_topics(self, header, cmds, cmdlen, maxcol):
259  if cmds:
260  print header
261  if self.ruler:
262  print self.ruler * len(header)
263  (cmds_per_line,junk)=divmod(maxcol,cmdlen)
264  col=cmds_per_line
265  for cmd in cmds:
266  if col==0: print
267  print (("%-"+`cmdlen`+"s") % cmd),
268  col = (col+1) % cmds_per_line
269  print "\n"

Field Documentation

list cmdqueue = []
static

Definition at line 60 of file cmd.py.

completion_matches

Definition at line 190 of file cmd.py.

string doc_header = "Documented commands (type help <topic>):"
static

Definition at line 63 of file cmd.py.

string doc_leader = ""
static

Definition at line 62 of file cmd.py.

identchars = IDENTCHARS
static

Definition at line 57 of file cmd.py.

intro = None
static

Definition at line 61 of file cmd.py.

string lastcmd = ''
static

Definition at line 59 of file cmd.py.

lastcmd

Definition at line 142 of file cmd.py.

string misc_header = "Miscellaneous help topics:"
static

Definition at line 64 of file cmd.py.

string nohelp = "*** No help on %s"
static

Definition at line 66 of file cmd.py.

prompt = PROMPT
static

Definition at line 56 of file cmd.py.

string ruler = '='
static

Definition at line 58 of file cmd.py.

string undoc_header = "Undocumented commands:"
static

Definition at line 65 of file cmd.py.

int use_rawinput = 1
static

Definition at line 67 of file cmd.py.


The documentation for this class was generated from the following file: