| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
from __future__ import print_function |
| 7 |
|
| 8 |
import CifFile |
| 9 |
import validate_cif |
| 10 |
import tempfile |
| 11 |
|
| 12 |
import cgi |
| 13 |
import os |
| 14 |
import cgitb; cgitb.enable() |
| 15 |
|
| 16 |
|
| 17 |
print("Content-Type: text/html\n\n") |
| 18 |
|
| 19 |
formdata = cgi.FieldStorage() |
| 20 |
|
| 21 |
|
| 22 |
dic_directory = "/usr/local/lib/cif/" |
| 23 |
input_cif = formdata["cif_file"] |
| 24 |
if input_cif.file: |
| 25 |
filename = input_cif.filename |
| 26 |
else: filename = "" |
| 27 |
is_dic = formdata.has_key("is_dic") |
| 28 |
input_dics = formdata.getlist("dic_list") |
| 29 |
|
| 30 |
|
| 31 |
tmpfile = tempfile.mkstemp()[1] |
| 32 |
jj = open(tmpfile,"w") |
| 33 |
jj.write(input_cif.file.read()) |
| 34 |
jj.close() |
| 35 |
try: |
| 36 |
cf = CifFile.ReadCif(tmpfile,scantype="flex") |
| 37 |
os.remove(tmpfile) |
| 38 |
except CifFile.StarFile.StarError: |
| 39 |
os.remove(tmpfile) |
| 40 |
import sys |
| 41 |
print("<h3>File reading error</h3>") |
| 42 |
print("<p>File %s appears to have one or more syntax errors</p>" % input_cif.filename) |
| 43 |
print("<p>The detailed error message is as follows:</p><p><pre>") |
| 44 |
etype,eval,trace = sys.exc_info() |
| 45 |
unsafe_str = str(eval) |
| 46 |
unsafe_str = unsafe_str.replace("&","&") |
| 47 |
unsafe_str = unsafe_str.replace("<","<") |
| 48 |
safe_str = unsafe_str.replace(">",">") |
| 49 |
print(safe_str) |
| 50 |
print("</pre>") |
| 51 |
except: |
| 52 |
os.remove(tmpfile) |
| 53 |
print("Unspecified error reading file %s. This is most likely a CIF syntax error.") |
| 54 |
|
| 55 |
else: |
| 56 |
diclist = map(lambda a:os.path.join(dic_directory,a),input_dics) |
| 57 |
merged_dics = CifFile.merge_dic(diclist) |
| 58 |
validate_cif.output_header(True,filename,input_dics) |
| 59 |
print(CifFile.validate_report(CifFile.Validate(cf,dic= merged_dics,isdic=is_dic),use_html=True)) |
| 60 |
validate_cif.output_footer(True) |