From 17a49ba8b76c2cb078b2f678c35238e2823c846e Mon Sep 17 00:00:00 2001 From: Svend Sorensen Date: Mon, 31 Jan 2005 01:30:09 +0000 Subject: [PATCH] Added web interface to package. --- extras/cueconvert.cgi | 108 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 extras/cueconvert.cgi diff --git a/extras/cueconvert.cgi b/extras/cueconvert.cgi new file mode 100644 index 0000000..9352816 --- /dev/null +++ b/extras/cueconvert.cgi @@ -0,0 +1,108 @@ +#!/usr/bin/env python + +# cueconvert.cgi - use HTML form to drive cueconvert +# ./cueconvert should be the cueconvert binary, or a link to it + +import os +import cgi +# error reporting +#import cgitb; cgitb.enable() + +def print_form(iformat, oformat, text, errors): + # input format radio buttons + # one "" and one "checked" + iformat_cue = "" + iformat_toc = "" + # output format radio buttons + oformat_cue = "" + oformat_toc = "" + + if iformat == "cue": + iformat_cue = "checked" + else: + iformat_toc = "checked" + + if oformat == "cue": + oformat_cue = "checked" + else: + oformat_toc = "checked" + + # print HTML form + print "Content-type: text/html" + print + print """ + + + cueconvert + + +

cueconvert

+
+

+ Cue Sheet/TOC File
+ +

+

+ Input Format + cue + toc +

+

+ Output Format + cue + toc +

+ +
+
%s
+
+

cueconvert is part of the cuetools project.

+ + + """ % (cgi.escape(text), iformat_cue, iformat_toc, oformat_cue, oformat_toc, cgi.escape(errors)) + +def convert(iformat, oformat, text): + """convert - convert a cue or toc file + + returns converted text, and any error messages""" + + command = "./cueconvert" + + # append flags to command + if iformat == "cue": + command += " -i cue" + elif iformat == "toc": + command += " -i toc" + + if oformat == "cue": + command += " -o cue" + elif oformat == "toc": + command += " -o toc" + + ifile, ofile, efile = os.popen3(command) + ifile.write(text) + ifile.close() + text = ofile.read() + errors = efile.read() + ofile.close() + efile.close() + + return text, errors + +if __name__ == '__main__': + iformat = "cue" # input format + oformat = "toc" # output format + text = "" # input file content + errors = "" # cueconvert error messages + + form = cgi.FieldStorage() + if form: + iformat = form.getfirst("iformat") + oformat = form.getfirst("oformat") + text = form.getfirst("text", "") + + text, errors = convert(iformat, oformat, text) + # switch input and output formats for next pass + iformat, oformat = oformat, iformat + + print_form(iformat, oformat, text, errors)