#!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')
ticket = form.getvalue('ticket')
filesize = form.getvalue('filesize')
#
#print("dsa="+dsa+"\n
")
#print("archivefilename="+archivefilename+"\n
")
#print("ticket="+ticket+"\n
")
#print("filesize="+filesize+"\n
")
#
#
#exit()
# check authentication!
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)
cfg = biocase.configuration.Cfg()
from biocase.datasources import Datasource
dsaObj = Datasource(name=dsa)
wrapperurl = dsaObj.getBioCASeAccessPoint()
basePath = os.path.abspath(".." + os.sep + ".." + os.sep + "archive") + os.sep
archivePath = basePath + dsa + os.sep
archiveBin = basePath + "archive.py"
print('Content-Type: text/html\n')
#print("dsa="+dsa+"\n
")
#print("archivefilename="+archivefilename+"\n
")
#print("ticket="+ticket+"\n
")
#print("filesize="+filesize+"\n
")
#print("wrapper_url"+wrapperurl+"\n
")
#print("archivePath"+archivePath+"\n
")
proc = archivePath + archivefilename + ".proc"
if os.path.exists(proc):
i = open(info, "w");
i.write("status: fail\n")
i.write(archivefilename + " is already in process\n");
i.close()
exit()
dom = xml.dom.minidom.parse("queryTemplate.xml")
n = dom.getElementsByTagName("responseFormat")[0]
n.removeAttribute("limit")
n.setAttribute("limit", filesize)
f = open(archivePath + archivefilename + ".query.xml", "w")
dom.writexml(f)
f.close
c = open(archivePath + archivefilename + ".config.xml", "w")
c.write("\n")
c.write("\n")
c.write("" + dsa + "\n")
c.write("" + archivefilename + "\n")
c.write("" + ticket + "\n")
c.write("" + wrapperurl + "\n")
c.write("\n")
c.close()
p = subprocess.Popen([sys.executable, archiveBin, archivefilename, dsa])
#p = subprocess.Popen([sys.executable, archivePath+"archive.py", archivefilename]).pid
#os.spawnl(os.P_DETACH, sys.executable, sys.executable, archivePath+"archive.py", archivefilename)
#print("p="+str(p))
#print ("hepp")