| [6ca7b9] | 1 | #!/usr/bin/python
 | 
|---|
 | 2 | #
 | 
|---|
 | 3 | # gathers all Actions in pyMoleCuilder module and tests them with some default
 | 
|---|
 | 4 | # values.
 | 
|---|
 | 5 | #
 | 
|---|
 | 6 | # date: Oct 5, 2011
 | 
|---|
 | 7 | # author: Gregor Bollerhey
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | import pyMoleCuilder as mol
 | 
|---|
| [cbb32d] | 10 | import sys, re, subprocess
 | 
|---|
| [6ca7b9] | 11 | 
 | 
|---|
| [f89b45] | 12 | # cmd given?
 | 
|---|
 | 13 | if len(sys.argv) < 1:
 | 
|---|
 | 14 |   sys.stderr.write("Usage: "+sys.argv[0]+" <cmd>\n")
 | 
|---|
 | 15 |   sys.exit(255)
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 | cmd = sys.argv[1]
 | 
|---|
| [6ca7b9] | 18 | 
 | 
|---|
 | 19 | # options.dat einlesen
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | Defaults = {}
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | with open('options.dat') as f:
 | 
|---|
 | 24 |     for line in f:
 | 
|---|
 | 25 |         if len(line) > 0 and line[0] != '#':
 | 
|---|
| [61c364] | 26 |             try:
 | 
|---|
 | 27 |               key, value = line.split('\t', 1)
 | 
|---|
 | 28 |             except ValueError:
 | 
|---|
 | 29 |               print "line needs two values, tab-separated: "+line
 | 
|---|
 | 30 |               sys.exit(1)
 | 
|---|
| [6ca7b9] | 31 |             value = value[1:-2] # quotes entfernen
 | 
|---|
 | 32 |         
 | 
|---|
 | 33 |             Defaults[key] = value
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | # aufrufen
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | Allparams = []
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | def ParseParameters(docstring):
 | 
|---|
 | 40 |     result = []
 | 
|---|
 | 41 |     params = re.findall(r'\(str\)([-a-zA-Z]*)', docstring)
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 |     for param in params:
 | 
|---|
 | 44 |         if not param in Allparams:
 | 
|---|
 | 45 |             Allparams.append(param)
 | 
|---|
 | 46 |             
 | 
|---|
 | 47 |             if not param in Defaults:
 | 
|---|
 | 48 |                 print 'Fehlender Defaultwert:', param
 | 
|---|
 | 49 |         
 | 
|---|
 | 50 |         # direkt substituieren, oder erst beim aufruf?
 | 
|---|
 | 51 |         if param in Defaults:
 | 
|---|
 | 52 |             param = Defaults[param]
 | 
|---|
 | 53 |         
 | 
|---|
 | 54 |         result.append(param)
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 |     return result
 | 
|---|
 | 57 | 
 | 
|---|
| [f89b45] | 58 | doc = eval('mol.%s.__doc__' % cmd)
 | 
|---|
 | 59 | params = ParseParameters(doc)
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | print '--BEGIN-- %s mit %s --------' % (cmd, params)
 | 
|---|
| [cbb32d] | 62 |    
 | 
|---|
| [f89b45] | 63 | # write command to file
 | 
|---|
 | 64 | output=open("test.py", "w")
 | 
|---|
| [975b83] | 65 | output.write('import pyMoleCuilder as mol\nparams = %s\nmol.%s(*params)\nmol.wait()\n' % (params, cmd))
 | 
|---|
| [f89b45] | 66 | output.close()
 | 
|---|
 | 67 | # call python externally on this file and catch retcode
 | 
|---|
 | 68 | p = subprocess.Popen(["python", "test.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 | 
|---|
 | 69 | stdout, stderr = p.communicate()
 | 
|---|
 | 70 | print ' --- STDOUT ---'
 | 
|---|
 | 71 | print ' %s ' % (stdout)
 | 
|---|
 | 72 | print ' --- STDERR ---'
 | 
|---|
 | 73 | print ' %s ' % (stderr)
 | 
|---|
 | 74 | retcode = p.returncode
 | 
|---|
 | 75 | if retcode == 134 or retcode == 0:
 | 
|---|
 | 76 |   print ' ---- ok ----'
 | 
|---|
 | 77 | else:
 | 
|---|
 | 78 |   print ' -- FAILED with %s --' % (retcode)
 | 
|---|
 | 79 | #  if retcode == 1:
 | 
|---|
 | 80 | #    sys.exit(1)
 | 
|---|
 | 81 | #exec('mol.%s(*params)' % cmd)
 | 
|---|
 | 82 | 
 | 
|---|
 | 83 | print '---END--- %s mit %s --------' % (cmd, params)
 | 
|---|
| [cbb32d] | 84 | 
 | 
|---|
 | 85 | sys.exit(0)
 | 
|---|