File: cueconvert.cgi

package info (click to toggle)
cuetools 1.4.1-0.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 304 kB
  • sloc: ansic: 1,625; yacc: 506; lex: 201; sh: 167; python: 81; makefile: 27
file content (113 lines) | stat: -rw-r--r-- 2,518 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python

# cueconvert.cgi - use HTML form to drive cueconvert

import os
import cgi
# error reporting
#import cgitb; cgitb.enable()

# cueconvert path
CUECONVERT = "./cueconvert"

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 """
<html>
<head>
	<title>cueconvert</title>
</head>
<body>
	<h1>cueconvert</h1>
	<form action="cueconvert.cgi" method="post">
		<p>
			Cue Sheet/TOC File<br />
			<textarea name="text" cols="80" rows="12">%s</textarea>
		</p>
		<p>
			Input Format
			<input type="radio" name="iformat" value="cue" %s>cue</input>
			<input type="radio" name="iformat" value="toc" %s>toc</input>
		</p>
		<p>
			Output Format
			<input type="radio" name="oformat" value="cue" %s>cue</input>
			<input type="radio" name="oformat" value="toc" %s>toc</input>
		</p>
		<input type="submit" value="Submit">
	</form>
	<pre>%s</pre>
	<hr />
	<p>cueconvert is part of the <a href="http://cuetools.berlios.de">cuetools</a> project.</p>
</body>
</html>
	""" % (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

def 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)

if __name__ == '__main__':
	main()