now operating on file, only on stdout if input comes from stdin

This commit is contained in:
Martin Diehl 2015-05-20 19:07:52 +00:00
parent 973f092fd9
commit d99f13a49f
1 changed files with 12 additions and 9 deletions

View File

@ -21,16 +21,15 @@ def outMentat(cmd,locals):
return return
#------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------
def outStdout(cmd,locals): def outFile(cmd,locals,dest):
#------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------
if cmd[0:3] == '(!)': if cmd[0:3] == '(!)':
exec(cmd[3:]) exec(cmd[3:])
elif cmd[0:3] == '(?)': elif cmd[0:3] == '(?)':
cmd = eval(cmd[3:]) cmd = eval(cmd[3:])
sys.stdout.write(cmd+'\n') dest.write(cmd+'\n')
else: else:
print(cmd) dest.write(cmd+'\n')
sys.stdout.write(cmd+'\n')
return return
#------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------
@ -40,10 +39,10 @@ def output(cmds,locals,dest):
if isinstance(cmd,list): if isinstance(cmd,list):
output(cmd,locals,dest) output(cmd,locals,dest)
else: else:
{\ if dest == 'Mentat':
'Mentat': outMentat,\ outMentat(str(cmd),locals)
'Stdout': outStdout,\ else:
}[dest](str(cmd),locals) outFile(str(cmd),locals,dest)
return return
@ -266,6 +265,7 @@ for file in files:
geometry(), geometry(),
initial_conditions(homog,microstructures), initial_conditions(homog,microstructures),
'*identify_sets', '*identify_sets',
'*show_model',
'*redraw', '*redraw',
] ]
@ -275,4 +275,7 @@ for file in files:
output(cmds,outputLocals,'Mentat') output(cmds,outputLocals,'Mentat')
py_disconnect() py_disconnect()
else: else:
output(cmds,outputLocals,'Stdout') output(cmds,outputLocals,file['output'])
if file['name'] != 'STDIN':
file['output'].close()
os.rename(file['name']+'_tmp',os.path.splitext(file['name'])[0] +'.proc')