comparison cmd2.py @ 286:3c4ba65cb303

sprucing up comments
author catherine@bothari
date Fri, 16 Oct 2009 17:52:47 -0400
parents 58be960b8bf9
children 1cd23003e8d5
comparison
equal deleted inserted replaced
285:58be960b8bf9 286:3c4ba65cb303
33 self.values._exit = True 33 self.values._exit = True
34 if msg: 34 if msg:
35 print msg 35 print msg
36 36
37 def print_help(self, *args, **kwargs): 37 def print_help(self, *args, **kwargs):
38 # now, I need to call help of the calling function. Hmm.
39 try: 38 try:
40 print self._func.__doc__ 39 print self._func.__doc__
41 except AttributeError: 40 except AttributeError:
42 pass 41 pass
43 optparse.OptionParser.print_help(self, *args, **kwargs) 42 optparse.OptionParser.print_help(self, *args, **kwargs)
63 matchObj = re.search(pattern, oldArgs) 62 matchObj = re.search(pattern, oldArgs)
64 return oldArgs[matchObj.start():] 63 return oldArgs[matchObj.start():]
65 64
66 def _attr_get_(obj, attr): 65 def _attr_get_(obj, attr):
67 '''Returns an attribute's value, or None (no error) if undefined. 66 '''Returns an attribute's value, or None (no error) if undefined.
68 Analagous to .get() for dictionaries.''' 67 Analagous to .get() for dictionaries. Useful when checking for
68 value of options that may not have been defined on a given
69 method.'''
69 try: 70 try:
70 return getattr(obj, attr) 71 return getattr(obj, attr)
71 except AttributeError: 72 except AttributeError:
72 return None 73 return None
73 74
84 try: 85 try:
85 if hasattr(arg, 'parsed'): 86 if hasattr(arg, 'parsed'):
86 args = arg.parsed.raw 87 args = arg.parsed.raw
87 else: 88 else:
88 args = arg 89 args = arg
89 opts, newArgList = optionParser.parse_args(args.split()) # doesn't understand quoted strings shouldn't be dissected! 90 opts, newArgList = optionParser.parse_args(args.split())
90 # Must find the remaining args in the original argument list, but 91 # Must find the remaining args in the original argument list, but
91 # mustn't include the command itself 92 # mustn't include the command itself
92 if hasattr(arg, 'parsed') and newArgList[0] == arg.parsed.command: 93 if hasattr(arg, 'parsed') and newArgList[0] == arg.parsed.command:
93 newArgList = newArgList[1:] 94 newArgList = newArgList[1:]
94 newArgs = remainingArgs(args, newArgList) # should it permit flags after args? 95 newArgs = remainingArgs(args, newArgList)
95 except (optparse.OptionValueError, optparse.BadOptionError, 96 except (optparse.OptionValueError, optparse.BadOptionError,
96 optparse.OptionError, optparse.AmbiguousOptionError, 97 optparse.OptionError, optparse.AmbiguousOptionError,
97 optparse.OptionConflictError), e: 98 optparse.OptionConflictError), e:
98 print e 99 print e
99 optionParser.print_help() 100 optionParser.print_help()
127 to be installed on operating system. 128 to be installed on operating system.
128 On Debian/Ubuntu, 'sudo apt-get install xclip' will install it.""" 129 On Debian/Ubuntu, 'sudo apt-get install xclip' will install it."""
129 def __init__(self): 130 def __init__(self):
130 Exception.__init__(self, self.errmsg) 131 Exception.__init__(self, self.errmsg)
131 132
132 '''check here if functions exist; otherwise, stub out'''
133 pastebufferr = """Redirecting to or from paste buffer requires %s 133 pastebufferr = """Redirecting to or from paste buffer requires %s
134 to be installed on operating system. 134 to be installed on operating system.
135 %s""" 135 %s"""
136
136 if subprocess.mswindows: 137 if subprocess.mswindows:
137 try: 138 try:
138 import win32clipboard 139 import win32clipboard
139 def getPasteBuffer(): 140 def getPasteBuffer():
140 win32clipboard.OpenClipboard(0) 141 win32clipboard.OpenClipboard(0)
269 if softspace(sys.stdout, 0): 270 if softspace(sys.stdout, 0):
270 print 271 print
271 272
272 class Cmd(cmd.Cmd): 273 class Cmd(cmd.Cmd):
273 echo = False 274 echo = False
274 case_insensitive = True 275 case_insensitive = True # Commands recognized regardless of case
275 continuation_prompt = '> ' 276 continuation_prompt = '> '
276 timing = False 277 timing = False # Prints elapsed time for each command
277 legalChars = '!#$%.:?@_' + pyparsing.alphanums + pyparsing.alphas8bit # make sure your terminators are not in here! 278 # make sure your terminators are not in legalChars!
279 legalChars = '!#$%.:?@_' + pyparsing.alphanums + pyparsing.alphas8bit
278 shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'} 280 shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
279 excludeFromHistory = '''run r list l history hi ed edit li eof'''.split() 281 excludeFromHistory = '''run r list l history hi ed edit li eof'''.split()
280 noSpecialParse = 'set ed edit exit'.split() 282 noSpecialParse = 'set ed edit exit'.split()
281 defaultExtension = 'txt' 283 defaultExtension = 'txt' # For ``save``, ``load``, etc.
282 default_file_name = 'command.txt' 284 default_file_name = 'command.txt' # For ``save``, ``load``, etc.
283 abbrev = True 285 abbrev = True
284 nonpythoncommand = 'cmd' 286 nonpythoncommand = 'cmd'
285 current_script_dir = None 287 current_script_dir = None
286 reserved_words = [] 288 reserved_words = []
287 feedback_to_output = False 289 feedback_to_output = False