#!/usr/bin/env /usr/bin/python3 import cgi, os import cgitb import subprocess cgitb.enable() cgi.maxlen=1024 * 1024 form = cgi.FieldStorage() fn1="" fn2="" fn3="" fn4="" fn5="" message1="" message2="" message3="" message4="" message5="" fileitem = form['filename1'] if fileitem.filename: fn1 = os.path.basename(fileitem.filename) if fn1.endswith('.txt') : open('files/' + fn1, 'wb').write(fileitem.file.read()) message1 = 'The file "' + fn1 + '" was uploaded successfully' else: message1 = 'Need to be a txt file' fn1 = "" else: message1 = 'No file was uploaded' fileitem = form['filename2'] if fileitem.filename: fn2 = os.path.basename(fileitem.filename) if fn2.endswith('.txt') : open('files/' + fn2, 'wb').write(fileitem.file.read()) message2 = 'The file "' + fn2 + '" was uploaded successfully' else: message2 = 'Need to be a txt file' fn2 = "" else: message2 = 'No file was uploaded' fileitem = form['filename3'] if fileitem.filename: fn3 = os.path.basename(fileitem.filename) if fn3.endswith('.txt') : open('files/' + fn3, 'wb').write(fileitem.file.read()) message3 = 'The file "' + fn3 + '" was uploaded successfully' else: message3 = 'Need to be a txt file' fn3 = "" else: message3 = 'No file was uploaded' fileitem = form['filename4'] if fileitem.filename: fn4 = os.path.basename(fileitem.filename) if fn4.endswith('') : open('files/' + fn4, 'wb').write(fileitem.file.read()) message4 = 'The file "' + fn4 + '" was uploaded successfully' else: message4 = 'Need to be empty extension file' fn4 = "" else: message4 = 'No file was uploaded' fileitem = form['filename5'] if fileitem.filename: fn5 = os.path.basename(fileitem.filename) if fn5.endswith('.txt') : open('files/' + fn5, 'wb').write(fileitem.file.read()) message5 = 'The file "' + fn5 + '" was uploaded successfully' else: message5 = 'Need to be a txt file' fn5 = "" else: message5 = 'No file was uploaded' ##change to files directory os.chdir(r"files") ## remove files ? pngName="" result="" haha="" dwba_1="" dwba_2="" dwba_3="" dwba_4="" dwbaPNG="" inFile="" outFile="" isDWBA=False dwbaExFile="" dwbaRootFile="" isTransferOK=False #------- if only DWBA if fn4!="" : dwba_1 = subprocess.run(["../Cleopatra/InFileCreator", fn4, "0", "180", "0.1"] , stdout=subprocess.PIPE).stdout.decode('utf-8') outFile = fn4+ ".out" cmd = "../Cleopatra/ptolemy <%s.in> %s.out" % (fn4, fn4) os.system(cmd) if os.path.exists(outFile) : dwba_2 = outFile dwba_3 = subprocess.run(["../Cleopatra/ExtractXSec", outFile, "1"], stdout=subprocess.PIPE).stdout.decode('utf-8') dwbaRootFile = fn4 + ".root" dwbaExFile = fn4 + ".Ex.txt" dwba_4 = subprocess.run(["../Cleopatra/PlotTGraphTObjArray", dwbaRootFile, "1"], stdout=subprocess.PIPE).stdout.decode('utf-8') dwbaPNG = dwba_4.splitlines().pop() isDWBA = True if fn1=="" or fn2=="": result = "imcomplete input files for kinematocs Simulation" pngName = "" haha = "" else: if isDWBA : result = subprocess.run(["../Cleopatra/Transfer", fn1, fn2, dwbaExFile, dwbaRootFile, "transfer.root", "reaction.dat", "0"], stdout=subprocess.PIPE).stdout.decode('utf-8') isTransferOK = True else: if fn3=="" : result = "missing Ex.txt" else: result = subprocess.run(["../Cleopatra/Transfer", fn1, fn2, fn3, "", "transfer.root", "reaction.dat", "0"], stdout=subprocess.PIPE).stdout.decode('utf-8') isTransferOK = True if isTransferOK : if fn5 =="": haha = subprocess.run(["../Cleopatra/PlotSimulation", "transfer.root"], stdout=subprocess.PIPE).stdout.decode('utf-8') else: haha = subprocess.run(["../Cleopatra/PlotSimulation", "transfer.root", fn5], stdout=subprocess.PIPE).stdout.decode('utf-8') pngName=haha.splitlines().pop() print ("Content-Type: text/html\r\n\r\n") print ("") print ("") print ("") print ("") if dwbaPNG != "" : print ("" % dwbaPNG) if pngName != "" : print ("" % pngName) print ("
Reaction File : %s" % message1) print ("
DetectorGeo File : %s" % message2) print ("
Ex File : %s" % message3) print ("
DWBA File : %s" % message4) print ("
Plot Config File : %s" % message5) print ("
%s " % dwba_1) print ("
%s " % dwba_2) print ("
%s " % dwba_3) print ("
%s " % dwba_4) print ("
%s " % result) print ("
%s " % haha) print ("") print ("")