[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] != '#':
|
---|
| 26 | key, value = line.split('\t', 1)
|
---|
| 27 | value = value[1:-2] # quotes entfernen
|
---|
| 28 |
|
---|
| 29 | Defaults[key] = value
|
---|
| 30 |
|
---|
| 31 | # aufrufen
|
---|
| 32 |
|
---|
| 33 | Allparams = []
|
---|
| 34 |
|
---|
| 35 | def ParseParameters(docstring):
|
---|
| 36 | result = []
|
---|
| 37 | params = re.findall(r'\(str\)([-a-zA-Z]*)', docstring)
|
---|
| 38 |
|
---|
| 39 | for param in params:
|
---|
| 40 | if not param in Allparams:
|
---|
| 41 | Allparams.append(param)
|
---|
| 42 |
|
---|
| 43 | if not param in Defaults:
|
---|
| 44 | print 'Fehlender Defaultwert:', param
|
---|
| 45 |
|
---|
| 46 | # direkt substituieren, oder erst beim aufruf?
|
---|
| 47 | if param in Defaults:
|
---|
| 48 | param = Defaults[param]
|
---|
| 49 |
|
---|
| 50 | result.append(param)
|
---|
| 51 |
|
---|
| 52 | return result
|
---|
| 53 |
|
---|
[f89b45] | 54 | doc = eval('mol.%s.__doc__' % cmd)
|
---|
| 55 | params = ParseParameters(doc)
|
---|
| 56 |
|
---|
| 57 | print '--BEGIN-- %s mit %s --------' % (cmd, params)
|
---|
[cbb32d] | 58 |
|
---|
[f89b45] | 59 | # write command to file
|
---|
| 60 | output=open("test.py", "w")
|
---|
| 61 | output.write('import pyMoleCuilder as mol\nparams = %s\nmol.%s(*params)\n' % (params, cmd))
|
---|
| 62 | output.close()
|
---|
| 63 | # call python externally on this file and catch retcode
|
---|
| 64 | p = subprocess.Popen(["python", "test.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
---|
| 65 | stdout, stderr = p.communicate()
|
---|
| 66 | print ' --- STDOUT ---'
|
---|
| 67 | print ' %s ' % (stdout)
|
---|
| 68 | print ' --- STDERR ---'
|
---|
| 69 | print ' %s ' % (stderr)
|
---|
| 70 | retcode = p.returncode
|
---|
| 71 | if retcode == 134 or retcode == 0:
|
---|
| 72 | print ' ---- ok ----'
|
---|
| 73 | else:
|
---|
| 74 | print ' -- FAILED with %s --' % (retcode)
|
---|
| 75 | # if retcode == 1:
|
---|
| 76 | # sys.exit(1)
|
---|
| 77 | #exec('mol.%s(*params)' % cmd)
|
---|
| 78 |
|
---|
| 79 | print '---END--- %s mit %s --------' % (cmd, params)
|
---|
[cbb32d] | 80 |
|
---|
| 81 | sys.exit(0)
|
---|