You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

114 lines
2.5 KiB

  1. #!/usr/bin/env python
  2. # cueconvert.cgi - use HTML form to drive cueconvert
  3. import os
  4. import cgi
  5. # error reporting
  6. #import cgitb; cgitb.enable()
  7. # cueconvert path
  8. CUECONVERT = "./cueconvert"
  9. def print_form(iformat, oformat, text, errors):
  10. # input format radio buttons
  11. # one "" and one "checked"
  12. iformat_cue = ""
  13. iformat_toc = ""
  14. # output format radio buttons
  15. oformat_cue = ""
  16. oformat_toc = ""
  17. if iformat == "cue":
  18. iformat_cue = "checked"
  19. else:
  20. iformat_toc = "checked"
  21. if oformat == "cue":
  22. oformat_cue = "checked"
  23. else:
  24. oformat_toc = "checked"
  25. # print HTML form
  26. print "Content-type: text/html"
  27. print
  28. print """
  29. <html>
  30. <head>
  31. <title>cueconvert</title>
  32. </head>
  33. <body>
  34. <h1>cueconvert</h1>
  35. <form action="cueconvert.cgi" method="post">
  36. <p>
  37. Cue Sheet/TOC File<br />
  38. <textarea name="text" cols="80" rows="12">%s</textarea>
  39. </p>
  40. <p>
  41. Input Format
  42. <input type="radio" name="iformat" value="cue" %s>cue</input>
  43. <input type="radio" name="iformat" value="toc" %s>toc</input>
  44. </p>
  45. <p>
  46. Output Format
  47. <input type="radio" name="oformat" value="cue" %s>cue</input>
  48. <input type="radio" name="oformat" value="toc" %s>toc</input>
  49. </p>
  50. <input type="submit" value="Submit">
  51. </form>
  52. <pre>%s</pre>
  53. <hr />
  54. <p>cueconvert is part of the <a href="http://cuetools.berlios.de">cuetools</a> project.</p>
  55. </body>
  56. </html>
  57. """ % (cgi.escape(text), iformat_cue, iformat_toc, oformat_cue, oformat_toc, cgi.escape(errors))
  58. def convert(iformat, oformat, text):
  59. """convert - convert a cue or toc file
  60. returns converted text, and any error messages"""
  61. command = CUECONVERT
  62. # append flags to command
  63. if iformat == "cue":
  64. command += " -i cue"
  65. elif iformat == "toc":
  66. command += " -i toc"
  67. if oformat == "cue":
  68. command += " -o cue"
  69. elif oformat == "toc":
  70. command += " -o toc"
  71. ifile, ofile, efile = os.popen3(command)
  72. ifile.write(text)
  73. ifile.close()
  74. text = ofile.read()
  75. errors = efile.read()
  76. ofile.close()
  77. efile.close()
  78. return text, errors
  79. def main():
  80. iformat = "cue" # input format
  81. oformat = "toc" # output format
  82. text = "" # input file content
  83. errors = "" # cueconvert error messages
  84. form = cgi.FieldStorage()
  85. if form:
  86. iformat = form.getfirst("iformat")
  87. oformat = form.getfirst("oformat")
  88. text = form.getfirst("text", "")
  89. text, errors = convert(iformat, oformat, text)
  90. # switch input and output formats for next pass
  91. iformat, oformat = oformat, iformat
  92. print_form(iformat, oformat, text, errors)
  93. if __name__ == '__main__':
  94. main()