home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / PythonLib / cmd.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-10-27  |  3.3 KB  |  101 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import string
  5. import sys
  6. import linecache
  7. PROMPT = '(Cmd) '
  8. IDENTCHARS = string.letters + string.digits + '_'
  9.  
  10. class Cmd:
  11.     
  12.     def __init__(self):
  13.         self.prompt = PROMPT
  14.         self.identchars = IDENTCHARS
  15.         self.lastcmd = ''
  16.  
  17.     
  18.     def cmdloop(self):
  19.         stop = None
  20.         while not stop:
  21.             
  22.             try:
  23.                 line = raw_input(self.prompt)
  24.             except EOFError:
  25.                 line = 'EOF'
  26.  
  27.             stop = self.onecmd(line)
  28.  
  29.     
  30.     def onecmd(self, line):
  31.         line = string.strip(line)
  32.         if not line:
  33.             line = self.lastcmd
  34.         else:
  35.             self.lastcmd = line
  36.         (i, n) = (0, len(line))
  37.         while i < n and line[i] in self.identchars:
  38.             i = i + 1
  39.         (cmd, arg) = (line[:i], string.strip(line[i:]))
  40.         if cmd == '':
  41.             return self.default(line)
  42.         else:
  43.             
  44.             try:
  45.                 func = getattr(self, 'do_' + cmd)
  46.             except AttributeError:
  47.                 return self.default(line)
  48.  
  49.             return func(arg)
  50.  
  51.     
  52.     def default(self, line):
  53.         print '*** Unknown syntax:', line
  54.  
  55.     
  56.     def do_help(self, arg):
  57.         if arg:
  58.             
  59.             try:
  60.                 func = getattr(self, 'help_' + arg)
  61.             except:
  62.                 print '*** No help on', `arg`
  63.                 return None
  64.  
  65.             func()
  66.         else:
  67.             import newdir
  68.             names = newdir.dir(self.__class__)
  69.             cmds_doc = []
  70.             cmds_undoc = []
  71.             help = { }
  72.             for name in names:
  73.                 pass
  74.             
  75.             for name in names:
  76.                 pass
  77.             
  78.             print 
  79.             self.print_topics('Documented commands (type help <topic>):', cmds_doc, 15, 80)
  80.             self.print_topics('Miscellaneous help topics:', help.keys(), 15, 80)
  81.             self.print_topics('Undocumented commands:', cmds_undoc, 15, 80)
  82.  
  83.     
  84.     def print_topics(self, header, cmds, cmdlen, maxcol):
  85.         if cmds:
  86.             print header
  87.             print '=' * len(header)
  88.             (cmds_per_line, junk) = divmod(maxcol, cmdlen)
  89.             col = cmds_per_line
  90.             for cmd in cmds:
  91.                 if col == 0:
  92.                     print 
  93.                 
  94.                 print ('%-' + `cmdlen` + 's') % cmd,
  95.                 col = (col + 1) % cmds_per_line
  96.             
  97.             print '\n'
  98.         
  99.  
  100.  
  101.