#!C:\Python25\python.exe # -*- coding: UTF-8 -*- import os, sys, Cookie, hashlib, subprocess import cgitb,cgi from xml.dom.minidom import Document import xml.dom.minidom from xml.dom.minidom import Node import xml.sax import pprint #cgitb.enable() # ***** include the biocase.lib directory in the python sys path for importing ***** execfile( os.path.abspath( os.path.join( os.path.dirname( __file__ ), os.pardir, os.pardir, 'lib', 'biocase', 'adjustpath.py' ) )) execfile( os.path.abspath( os.path.join( os.path.dirname( __file__ ), os.pardir, os.pardir, 'lib', 'biocase', 'appinit.py' ) )) from biocase.configtool.general import * import biocase.configuration archivefilename = form.getvalue('archivefilename') dsa = form.getvalue('dsa') action = form.getvalue("action") archivePath = os.path.abspath(".." + os.sep + ".." + os.sep + "archive") + os.sep + dsa + os.sep proc = archivePath + archivefilename + ".proc" faf = archivePath + archivefilename if dsa is None: execfile( os.path.abspath( os.path.join( os.path.dirname( __file__ ), 'main.cgi' ) )) sys.exit() # check authentication! authorize(form, dsa=dsa) def tail(file, n=1, bs=1024): f = open(file) f.seek(-1,2) l = 1-f.read(1).count('\n') # If file doesn't end in \n, count it anyway. B = f.tell() while n >= l and B > 0: block = min(bs, B) B -= block f.seek(B, 0) l += f.read(block).count('\n') f.seek(B, 0) l = min(l,n) # discard first (incomplete) line if l > n lines = f.readlines()[-l:] f.close() return lines print('Content-Type: text/html\n') if not os.path.exists(archivePath): os.makedirs(archivePath) if action == "showlog": lf = archivePath + archivefilename + ".log" if os.path.exists(lf): lines = tail(lf, 15) if len(lines) == 15: print ("...continued ") for line in lines: print line.rstrip() else: print("Log file not found : " + lf) if action == "isRunning": if os.path.exists(proc): print("true") else: print("false") if action == "archiveexists": if os.path.exists(faf): print("true") else: print("false") if action == "cancel": if os.path.exists(proc): p = open(proc, "w") p.write("cancel") p.close() print "Cancelation of "+archivefilename+" requested. Waiting for the program to finish..." else: print(archivefilename + " is not running.") if action == "proclist": j = "{ " l = os.listdir(archivePath) for f in l: if f.endswith(".proc"): j += '"' + f + '":"' + f[:-5] + '",' j = j[:-1] + "}" print j if action == "finishedlist": j = "{ " l = os.listdir(archivePath) for f in l: if f.endswith(".config.xml"): name = f[:-11] if not os.path.exists(archivePath + name + ".proc") and os.path.exists(archivePath + name): j += '"' + name + '":"' + name + '",' j = j[:-1] + "}" print j if action == "remove": if os.path.exists(faf): os.remove(faf) print archivefilename+" was removed." else: print(archivefilename + " does not exists.")