|
|
@ -60,11 +60,10 @@ if method == "POST":
|
|
|
|
# FILE INPUT
|
|
|
|
# FILE INPUT
|
|
|
|
###################################
|
|
|
|
###################################
|
|
|
|
if f != None and f.file:
|
|
|
|
if f != None and f.file:
|
|
|
|
|
|
|
|
|
|
|
|
if from_format == None:
|
|
|
|
if from_format == None:
|
|
|
|
from_format = guess_format_from_filename(f.filename)
|
|
|
|
from_format = guess_format_from_filename(f.filename)
|
|
|
|
|
|
|
|
|
|
|
|
tmp = NTF(delete=False)
|
|
|
|
tmp = NTF(suffix=".docx", delete=False)
|
|
|
|
bytes = 0
|
|
|
|
bytes = 0
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
data = f.file.read()
|
|
|
|
data = f.file.read()
|
|
|
@ -75,6 +74,9 @@ if method == "POST":
|
|
|
|
# print "saved to '{0}'<br>".format(tmp.name)
|
|
|
|
# print "saved to '{0}'<br>".format(tmp.name)
|
|
|
|
# print "read {0} bytes<br>".format(bytes)
|
|
|
|
# print "read {0} bytes<br>".format(bytes)
|
|
|
|
tmp.close()
|
|
|
|
tmp.close()
|
|
|
|
|
|
|
|
os.chmod(tmp.name, 0666)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
|
|
print "Content-type: {0}".format(to_type['mime'])
|
|
|
|
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 "Content-Disposition: attachment;filename=\"hype_conversion.{0}\"".format(to_type['ext'])
|
|
|
|
print
|
|
|
|
print
|
|
|
|
# p = subprocess.check_output('pandoc --from {0} --to {1} "{2}"'.format(ffrom, to, tmp.name), shell=True, stderr=subprocess.STDOUT)
|
|
|
|
# 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
|
|
|
|
# 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()
|
|
|
|
out, err = p_head.communicate() # p_unoconv.communicate()
|
|
|
|
print out
|
|
|
|
#print tmp.name, from_format
|
|
|
|
|
|
|
|
print out, err
|
|
|
|
|
|
|
|
|
|
|
|
except subprocess.CalledProcessError, e:
|
|
|
|
except subprocess.CalledProcessError, e:
|
|
|
|
print "Content-type: text/html;charset=utf-8"
|
|
|
|
print "Content-type: text/html;charset=utf-8"
|
|
|
|
print
|
|
|
|
print
|
|
|
|
print u"<span style='font-family:monospace'>An error occurred, pandoc said: {0}</span>".format(e.output).format("utf-8")
|
|
|
|
print u"<span style='font-family:monospace'>An error occurred, pandoc said: {0}</span>".format(e.output).format("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
tmp.unlink(tmp.name)
|
|
|
|
# tmp.unlink(tmp.name) # remove file
|
|
|
|
|
|
|
|
|
|
|
|
###################################
|
|
|
|
###################################
|
|
|
|
# FORM/TEXT INPUT
|
|
|
|
# FORM/TEXT INPUT
|
|
|
@ -149,3 +168,13 @@ if method == "POST":
|
|
|
|
# </form>
|
|
|
|
# </form>
|
|
|
|
# </body></html>
|
|
|
|
# </body></html>
|
|
|
|
# """
|
|
|
|
# """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|