Changeset 230
- Timestamp:
- 07/20/2010 03:59:07 PM (13 years ago)
- Location:
- SHX/trunk/src/SeismicHandler
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
SHX/trunk/src/SeismicHandler/commands/__init__.py
r224 r230 20 20 import os 21 21 22 path = os.path.split(__file__) 22 path = os.path.split(__file__)[0] 23 23 list = {} 24 24 25 25 # XXX This should respect a user defined command directory. 26 for root, dirs, files in os.walk(path [0]):26 for root, dirs, files in os.walk(path): 27 27 for f in files: 28 28 if not f.endswith(".py"): … … 32 32 33 33 a = __import__(f[:-3], globals(), locals(), ["SeismicHandler.commands"]) 34 for k in a.provides: 35 list[k] = a.provides[k] 34 35 for k in a.provides: 36 list[k] = getattr(a, a.provides[k]) 36 37 37 38 # only visit current directory -
SHX/trunk/src/SeismicHandler/commands/echo.py
r224 r230 73 73 'foo bar qux\\n' 74 74 >>> Settings.echo_channel = oldout # restore output channel 75 76 URI:http://www.seismic-handler.org/portal/wiki/ShEcho 75 77 """ 76 78 -
SHX/trunk/src/SeismicHandler/commands/echo_ch.py
r224 r230 61 61 ECHO_CH ! closes a previously opened ECHO-file and 62 62 ! switches output back to screen 63 """ 63 64 URI:http://www.seismic-handler.org/portal/wiki/ShEchoCh 65 """ 64 66 65 67 known_qualifiers = [ -
SHX/trunk/src/SeismicHandler/core/__init__.py
r221 r230 22 22 from SeismicHandler.core.history import History as history 23 23 from SeismicHandler.core import codes 24 24 from SeismicHandler.core.log import Logging 25 25 from SeismicHandler.core.runtime import runtime 26 26 -
SHX/trunk/src/SeismicHandler/core/parser.py
r224 r230 30 30 import re 31 31 import inspect 32 from SeismicHandler.core import Settings 32 from SeismicHandler.core import Settings, Logging 33 33 import SeismicHandler.commands as commands 34 34 … … 79 79 >>> x["shx_qualifier"]["FOO"] 80 80 '1' 81 82 Please not that the "suspected" file name is also present as switch:81 82 Please note that the "suspected" file name is also present as switch: 83 83 >>> sorted(x["shx_qualifier"].keys()) 84 84 ['BLA', 'FOO', 'SW', 'TEST', 'TMP'] … … 97 97 >>> x["shx_parameter"] 98 98 ['', '2', '3', '4', '', '6', '7'] 99 99 100 100 >>> x = parse('ECHO;;;;foo;bar;;').parsed 101 101 >>> x["shx_parameter"] … … 111 111 self.input = input 112 112 113 if Settings. CapConv:113 if Settings.swCapconv: 114 114 input = input.upper() 115 115 … … 199 199 >>> strm = StringIO("echo line1\\necho line2\\n") 200 200 >>> symb = symbol() 201 >>> Settings. Echo = True201 >>> Settings.swEcho = True 202 202 >>> x = script(strm, symb) 203 203 >>> x.run() 204 204 echo line1 205 205 echo line2 206 207 It's possible to add more commands at runtime. The script will continue 206 207 It's possible to add more commands at runtime. The script will continue 208 208 there. 209 209 >>> x.feed(StringIO("echo line3\\n")) … … 286 286 cmd = self.next() 287 287 288 if Settings. Echo:288 if Settings.swEcho: 289 289 print cmd 290 290 291 291 cmd = parse(cmd).parsed 292 292 293 # Start script if unknown command found: 294 if not cmd["shx_command"] in commands.list: 293 294 # Execute command... 295 if cmd["shx_command"] in commands.list: 296 commands.list[cmd["shx_command"]](*cmd["shx_parameter"], **cmd["shx_qualifier"]) 297 298 # .. or start script. 299 else: 295 300 symb = symbol() 296 301 try: 297 302 ns = script(cmd["shx_command"], symb) 298 303 ns.run() 299 except: 300 # XXX behaviour must respect global settings 301 raise Exception("Cannot run script '%s'!" % cmd["shx_command"]) 304 except Exception, e: 305 msg = "Cannot run script '%s'!" % cmd["shx_command"] 306 307 # Respect global settings: 308 if Settings.swSherrstop: 309 import sys 310 print >> sys.stderr, msg 311 quit() 312 313 if Settings.swCmderrstop: 314 raise Exception(msg) 315 316 if not Settings.swNoerrmsg: 317 import warnings 318 warnings.warn(msg) 319 302 320 except StopIteration: 303 321 break … … 370 388 371 389 class translate(object): 390 """ 391 Translate variables in command. 392 """ 372 393 def __init__(self): 373 394 pass … … 422 443 def __setattr__(self, name, value): 423 444 name = name.upper() 424 445 425 446 self.__dict__[name] = value 426 447 … … 447 468 def setGlobal(self, name, value): 448 469 name = name.upper() 449 470 450 471 self.__dict__["__globals"][name] = value 451 472 -
SHX/trunk/src/SeismicHandler/core/runtime.py
r224 r230 29 29 __echo_channel = sys.stdout 30 30 31 # convert to upper case 32 CapConv = True 33 # echo command before execution 34 Echo = False 35 # verify command 36 Verify = False 37 # cancel script on error 38 CmdErrStop = True 39 # exit SH on error 40 ShErrStop = False 31 # global switches (see http://www.seismic-handler.org/portal/wiki/ShSwitch) 32 _Switches = { 33 # convert to upper case 34 "Capconv": True, 35 # echo command before execution 36 "Echo": False, 37 # verify command 38 "Verify": False, 39 # cancel script on error 40 "Cmderrstop": True, 41 # exit SH on error 42 "Sherrstop": False, 43 # no error message at all 44 "Noerrmsg": False, 45 # verbose 46 "Chatty": True, 47 # indicate startup file 48 "Startup": False, 49 } 41 50 42 51 # dictionary of global variables … … 56 65 57 66 return cls.__instance 67 68 def __getattr__(self, name): 69 if name.startswith("sw"): 70 return getattr(self, "_Switches")[name[2:]] 71 else: 72 # return self.__class__.__dict__[name] 73 return object.__getattribute__(self, name) 74 75 def __setattr__(self, name, value): 76 if name.startswith("sw"): 77 if not name[2:] in self.__class__.__dict__["_Switches"].keys(): 78 raise Exception("Unknown switch!") 79 80 self.__class__.__dict__["_Switches"][name[2:]] = value 81 elif name == "echo_channel": 82 object.__setattr__(self, "echo_channel", value) 83 else: 84 self.__dict__[name] = value 58 85 59 86 @Property … … 106 133 if __name__ == "__main__": 107 134 Settings = runtime() 108 135 109 136 print >> Settings.echo_channel, Settings.echo_channel 110 137 Settings.echo_channel = "TEST" -
SHX/trunk/src/SeismicHandler/tests/data
-
Property
svn:ignore
set to
.SCRIPT1.SHC.swp
-
Property
svn:ignore
set to
-
SHX/trunk/src/SeismicHandler/tests/test_base.py
r175 r230 22 22 """ 23 23 24 from SeismicHandler.core. base.command import BaseCommand24 from SeismicHandler.core.command import BaseCommand 25 25 import unittest 26 26 import sys … … 36 36 def testBaseCommand1(self): 37 37 """ 38 Check for proper test of initialization.39 """40 41 # assertRaise needs a callable - not just a class init42 try:43 cmd = BaseCommand()44 except NotImplementedError:45 pass46 else:47 self.fail("check failed")48 49 def testBaseCommand2(self):50 """51 38 Check dummy command 52 39 """ … … 56 43 test help text 57 44 """ 45 known_qualifiers = [] 46 expectFilename = False 58 47 def run(self): 59 48 self.x = "test"
Note: See TracChangeset
for help on using the changeset viewer.