diff --git a/cgi-bin/pandoc.cgi b/cgi-bin/pandoc.cgi index 9ea0aee..f1e845e 100755 --- a/cgi-bin/pandoc.cgi +++ b/cgi-bin/pandoc.cgi @@ -60,11 +60,10 @@ if method == "POST": # FILE INPUT ################################### if f != None and f.file: - if from_format == None: from_format = guess_format_from_filename(f.filename) - tmp = NTF(delete=False) + tmp = NTF(suffix=".docx", delete=False) bytes = 0 while True: data = f.file.read() @@ -75,6 +74,9 @@ if method == "POST": # print "saved to '{0}'
".format(tmp.name) # print "read {0} bytes
".format(bytes) tmp.close() + os.chmod(tmp.name, 0666) + + try: print "Content-type: {0}".format(to_type['mime']) @@ -82,18 +84,35 @@ if method == "POST": print "Content-Disposition: attachment;filename=\"hype_conversion.{0}\"".format(to_type['ext']) print # p = subprocess.check_output('pandoc --from {0} --to {1} "{2}"'.format(ffrom, to, tmp.name), shell=True, stderr=subprocess.STDOUT) + + # read content of tmp docx + cmd_head = "head {}".format(tmp.name) + cmd_head_list = shlex.split( cmd_head ) + p_head = subprocess.Popen(cmd_head_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + # convert docx to html: error. No idea why + cmd_unoconv = "unoconv --stdout -f html {}".format(tmp.name) + cmd_unoconv_list = shlex.split( cmd_unoconv ) + p_unoconv = subprocess.Popen(cmd_unoconv_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + # convert docx to html: depends on most recente versions of pandoc + # cmd = "{} --from {} --to {} {}".format(PANDOC, from_format, to_format, tmp.name) + # cmd_list = shlex.split( cmd ) + # p = subprocess.Popen(cmd_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # print p - p = subprocess.Popen([PANDOC, '--from', from_format, '--to', to_format, tmp.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # p = subprocess.Popen([PANDOC, '--from', from_format, '--to', to_format, tmp.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() - print out + out, err = p_head.communicate() # p_unoconv.communicate() + #print tmp.name, from_format + print out, err except subprocess.CalledProcessError, e: print "Content-type: text/html;charset=utf-8" print print u"An error occurred, pandoc said: {0}".format(e.output).format("utf-8") - tmp.unlink(tmp.name) +# tmp.unlink(tmp.name) # remove file ################################### # FORM/TEXT INPUT @@ -149,3 +168,13 @@ if method == "POST": # # # """ + + +''' + p = subprocess.Popen([PANDOC, '--from', from_format, '--to', to_format, tmp.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + out, err = p.communicate() + print out + # print_template(data) +''' +