annotate weblogolib/_cgi.py @ 14:778f03497adb

Uploaded
author davidmurphy
date Fri, 24 Feb 2012 11:37:26 -0500
parents c55bdc2fb9fa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
1 #!/usr/bin/env python
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
2
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
3 # Copyright (c) 2003-2004 The Regents of the University of California.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
4 # Copyright (c) 2005 Gavin E. Crooks
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
5 # Copyright (c) 2006, The Regents of the University of California, through
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
6 # Lawrence Berkeley National Laboratory (subject to receipt of any required
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
7 # approvals from the U.S. Dept. of Energy). All rights reserved.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
8
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
9 # This software is distributed under the new BSD Open Source License.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
10 # <http://www.opensource.org/licenses/bsd-license.html>
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
11 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
12 # Redistribution and use in source and binary forms, with or without
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
13 # modification, are permitted provided that the following conditions are met:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
14 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
15 # (1) Redistributions of source code must retain the above copyright notice,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
16 # this list of conditions and the following disclaimer.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
17 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
18 # (2) Redistributions in binary form must reproduce the above copyright
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
19 # notice, this list of conditions and the following disclaimer in the
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
20 # documentation and or other materials provided with the distribution.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
21 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
22 # (3) Neither the name of the University of California, Lawrence Berkeley
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
23 # National Laboratory, U.S. Dept. of Energy nor the names of its contributors
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
24 # may be used to endorse or promote products derived from this software
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
25 # without specific prior written permission.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
26 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
27 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
28 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
29 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
30 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
31 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
32 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
33 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
34 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
35 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
36 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
37 # POSSIBILITY OF SUCH DAMAGE.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
38
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
39 import sys
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
40 import cgi as cgilib
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
41 import cgitb; cgitb.enable()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
42
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
43 #print "Content-Type: text/html\n\n"
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
44 #print "HELLO WORLD"
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
45 #print __name__
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
46
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
47 from StringIO import StringIO
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
48 from color import *
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
49 from colorscheme import ColorScheme, ColorGroup
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
50
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
51 import weblogolib
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
52 from corebio.utils import *
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
53 from corebio._future import Template
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
54
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
55
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
56 # TODO: Check units
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
57
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
58 # TODO: In WebLogo2: why slash create.cgi? I think this was a workaround
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
59 # for some browser quirk
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
60 #<form method="post" action="/create.cgi" enctype="multipart/form-data">
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
61
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
62 def resource_string(resource, basefilename) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
63 import os
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
64 fn = os.path.join(os.path.dirname(basefilename), resource)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
65 return open( fn ).read()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
66
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
67 mime_type = {
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
68 'eps': 'application/postscript',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
69 'pdf': 'application/pdf',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
70 'png': 'image/png',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
71 'png_print': 'image/png',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
72 'txt' : 'text/plain',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
73 'jpeg' : 'image/jpeg',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
74 }
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
75
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
76 extension = {
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
77 'eps': 'eps',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
78 'pdf': 'pdf',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
79 'png': 'png',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
80 'png_print': 'png',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
81 'txt' : 'txt',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
82 'jpeg' : 'png'
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
83 }
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
84
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
85
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
86 alphabets = {
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
87 'alphabet_auto': None,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
88 'alphabet_protein': weblogolib.unambiguous_protein_alphabet,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
89 'alphabet_rna': weblogolib.unambiguous_rna_alphabet,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
90 'alphabet_dna': weblogolib.unambiguous_dna_alphabet}
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
91
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
92 color_schemes = {}
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
93 for k in weblogolib.std_color_schemes.keys():
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
94 color_schemes[ 'color_'+k.replace(' ', '_')] = weblogolib.std_color_schemes[k]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
95
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
96
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
97 composition = {'comp_none' : 'none',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
98 'comp_auto' : 'auto',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
99 'comp_equiprobable':'equiprobable',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
100 'comp_CG': 'percentCG',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
101 'comp_Celegans' : 'C. elegans',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
102 'comp_Dmelanogaster' : 'D. melanogaster',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
103 'comp_Ecoli' : 'E. coli',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
104 'comp_Hsapiens': 'H. sapiens',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
105 'comp_Mmusculus' : 'M. musculus',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
106 'comp_Scerevisiae': 'S. cerevisiae'
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
107 }
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
108
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
109 class Field(object) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
110 """ A representation of an HTML form field."""
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
111 def __init__(self, name, default=None, conversion= None, options=None, errmsg="Illegal value.") :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
112 self.name = name
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
113 self.default = default
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
114 self.value = default
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
115 self.conversion = conversion
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
116 self.options = options
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
117 self.errmsg = errmsg
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
118
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
119 def get_value(self) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
120 if self.options :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
121 if not self.value in self.options :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
122 raise ValueError, (self.name, self.errmsg)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
123
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
124 if self.conversion :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
125 try :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
126 return self.conversion(self.value)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
127 except ValueError, e :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
128 raise ValueError, (self.name, self.errmsg)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
129 else:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
130 return self.value
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
131
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
132
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
133 def string_or_none(value) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
134 if value is None or value == 'auto':
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
135 return None
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
136 return str(value)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
137
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
138 def truth(value) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
139 if value== "true" : return True
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
140 return bool(value)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
141
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
142 def int_or_none(value) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
143 if value =='' or value is None or value == 'auto':
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
144 return None
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
145 return int(value)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
146
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
147 def float_or_none(value) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
148 if value =='' or value is None or value == 'auto':
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
149 return None
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
150 return float(value)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
151
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
152
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
153 def main(htdocs_directory = None) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
154
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
155 logooptions = weblogolib.LogoOptions()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
156
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
157 # A list of form fields.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
158 # The default for checkbox values must be False (irrespective of
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
159 # the default in logooptions) since a checked checkbox returns 'true'
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
160 # but an unchecked checkbox returns nothing.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
161 controls = [
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
162 Field( 'sequences', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
163 Field( 'format', 'png', weblogolib.formatters.get ,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
164 options=['png_print', 'png', 'jpeg', 'eps', 'pdf', 'txt'] ,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
165 errmsg="Unknown format option."),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
166 Field( 'stacks_per_line', logooptions.stacks_per_line , int,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
167 errmsg='Invalid number of stacks per line.'),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
168 Field( 'size','medium', weblogolib.std_sizes.get,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
169 options=['small', 'medium', 'large'], errmsg='Invalid logo size.'),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
170 Field( 'alphabet','alphabet_auto', alphabets.get,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
171 options=['alphabet_auto', 'alphabet_protein', 'alphabet_dna',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
172 'alphabet_rna'],
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
173 errmsg="Unknown sequence type."),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
174 Field( 'unit_name', 'bits',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
175 options=[ 'probability', 'bits', 'nats', 'kT', 'kJ/mol',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
176 'kcal/mol']),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
177 Field( 'first_index', 1, int_or_none),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
178 Field( 'logo_start', '', int_or_none),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
179 Field( 'logo_end', '', int_or_none),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
180 Field( 'composition', 'comp_auto', composition.get,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
181 options=['comp_none','comp_auto','comp_equiprobable','comp_CG',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
182 'comp_Celegans','comp_Dmelanogaster','comp_Ecoli',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
183 'comp_Hsapiens','comp_Mmusculus','comp_Scerevisiae'],
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
184 errmsg= "Illegal sequence composition."),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
185 Field( 'percentCG', '', float_or_none, errmsg="Invalid CG percentage."),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
186 Field( 'show_errorbars', False , truth),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
187 Field( 'altype', False , truth),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
188 Field( 'logo_title', logooptions.logo_title ),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
189 Field( 'logo_label', logooptions.logo_label ),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
190 Field( 'show_xaxis', False, truth),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
191 Field( 'xaxis_label', logooptions.xaxis_label ),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
192 Field( 'show_yaxis', False, truth),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
193 Field( 'yaxis_label', logooptions.yaxis_label, string_or_none ),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
194 Field( 'yaxis_scale', logooptions.yaxis_scale , float_or_none,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
195 errmsg="The yaxis scale must be a positive number." ),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
196 Field( 'yaxis_tic_interval', logooptions.yaxis_tic_interval ,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
197 float_or_none),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
198 Field( 'show_ends', False, truth),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
199 Field( 'show_fineprint', False , truth),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
200 Field( 'color_scheme', 'color_auto', color_schemes.get,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
201 options=color_schemes.keys() ,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
202 errmsg = 'Unknown color scheme'),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
203 Field( 'color0', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
204 Field( 'symbols0', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
205 Field( 'desc0', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
206 Field( 'color1', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
207 Field( 'symbols1', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
208 Field( 'desc1', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
209 Field( 'color2', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
210 Field( 'symbols2', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
211 Field( 'desc2', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
212 Field( 'color3', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
213 Field( 'symbols3', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
214 Field( 'desc3', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
215 Field( 'color4', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
216 Field( 'symbols4', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
217 Field( 'desc4', ''),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
218 Field( 'ignore_lower_case', False, truth),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
219 Field( 'altype', False, truth),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
220 Field( 'scale_width', False, truth),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
221 ]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
222
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
223 form = {}
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
224 for c in controls :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
225 form[c.name] = c
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
226
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
227
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
228 form_values = cgilib.FieldStorage()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
229
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
230 # Send default form?
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
231 if len(form_values) ==0 or form_values.has_key("cmd_reset"):
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
232 # Load default truth values now.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
233 form['show_errorbars'].value = logooptions.show_errorbars
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
234 form['show_xaxis'].value = logooptions.show_xaxis
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
235 form['show_yaxis'].value = logooptions.show_yaxis
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
236 form['show_ends'].value = logooptions.show_ends
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
237 form['show_fineprint'].value = logooptions.show_fineprint
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
238 form['scale_width'].value = logooptions.scale_width
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
239 form['altype'].value = logooptions.altype
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
240
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
241 send_form(controls, htdocs_directory = htdocs_directory)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
242 return
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
243
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
244 # Get form content
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
245 for c in controls :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
246 c.value = form_values.getfirst( c.name, c.default)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
247
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
248
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
249 options_from_form = ['format', 'stacks_per_line', 'size',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
250 'alphabet', 'unit_name', 'first_index', 'logo_start','logo_end',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
251 'composition',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
252 'show_errorbars', 'logo_title', 'logo_label', 'show_xaxis',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
253 'xaxis_label',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
254 'show_yaxis', 'yaxis_label', 'yaxis_scale', 'yaxis_tic_interval',
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
255 'show_ends', 'show_fineprint', 'scale_width','altype']
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
256
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
257 errors = []
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
258 for optname in options_from_form :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
259 try :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
260 value = form[optname].get_value()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
261 if value!=None : setattr(logooptions, optname, value)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
262 except ValueError, err :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
263 errors.append(err.args)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
264
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
265 #check if using codons or not.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
266 if logooptions.altype!=True:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
267 weblogolib.altype = ""
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
268 print >> sys.stderr,logooptions.altype
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
269 print >> sys.stderr, "--nn-"
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
270
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
271 # Construct custom color scheme
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
272 custom = ColorScheme()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
273 for i in range(0,5) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
274 color = form["color%d"%i].get_value()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
275 symbols = form["symbols%d"%i].get_value()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
276 desc = form["desc%d"%i].get_value()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
277
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
278 if color :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
279 try :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
280 custom.groups.append(weblogolib.ColorGroup(symbols, color, desc))
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
281 except ValueError, e :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
282 errors.append( ('color%d'%i, "Invalid color: %s" % color) )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
283
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
284 if form["color_scheme"].value == 'color_custom' :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
285 logooptions.color_scheme = custom
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
286 else :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
287 try :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
288 logooptions.color_scheme = form["color_scheme"].get_value()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
289 except ValueError, err :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
290 errors.append(err.args)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
291
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
292 sequences = None
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
293
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
294 # FIXME: Ugly fix: Must check that sequence_file key exists
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
295 # FIXME: Sending malformed or missing form keys should not cause a crash
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
296 # sequences_file = form["sequences_file"]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
297 if form_values.has_key("sequences_file") :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
298 sequences = form_values.getvalue("sequences_file")
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
299 assert type(sequences) == str
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
300
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
301 if not sequences or len(sequences) ==0:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
302 sequences = form["sequences"].get_value()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
303
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
304 if not sequences or len(sequences) ==0:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
305 errors.append( ("sequences", "Please enter a multiple-sequence alignment in the box above, or select a file to upload."))
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
306
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
307
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
308
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
309 # If we have uncovered errors or we want the chance to edit the logo
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
310 # ("cmd_edit" command from examples page) then we return the form now.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
311 # We do not proceed to the time consuming logo creation step unless
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
312 # required by a 'create' or 'validate' command, and no errors have been
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
313 # found yet.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
314 if form_values.has_key("cmd_edit") or errors :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
315 send_form(controls, errors, htdocs_directory)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
316 return
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
317
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
318
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
319
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
320
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
321 # We write the logo into a local buffer so that we can catch and
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
322 # handle any errors. Once the "Content-Type:" header has been sent
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
323 # we can't send any useful feedback
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
324 logo = StringIO()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
325 try :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
326 comp = form["composition"].get_value()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
327 percentCG = form["percentCG"].get_value()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
328 ignore_lower_case = form_values.has_key("ignore_lower_case")
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
329 seqs = weblogolib.read_seq_data(StringIO( sequences),
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
330 alphabet=logooptions.alphabet,
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
331 ignore_lower_case=ignore_lower_case
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
332 )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
333 if comp=='percentCG': comp = str(percentCG/100)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
334 prior = weblogolib.parse_prior(comp, seqs.alphabet)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
335 data = weblogolib.LogoData.from_seqs(seqs, prior)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
336 logoformat = weblogolib.LogoFormat(data, logooptions)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
337 format = form["format"].value
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
338 weblogolib.formatters[format](data, logoformat, logo)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
339 except ValueError, err :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
340 errors.append( err.args )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
341 except IOError, err :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
342 errors.append( err.args)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
343 except RuntimeError, err :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
344 errors.append( err.args )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
345
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
346 if form_values.has_key("cmd_validate") or errors :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
347 send_form(controls, errors, htdocs_directory)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
348 return
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
349
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
350
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
351 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
352 # RETURN LOGO OVER HTTP
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
353 #
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
354
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
355 print "Content-Type:", mime_type[format]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
356 # Content-Disposition: inline Open logo in browser window
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
357 # Content-Disposition: attachment Download logo
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
358 if form_values.has_key("download") :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
359 print 'Content-Disposition: attachment; ' \
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
360 'filename="logo.%s"' % extension[format]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
361 else :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
362 print 'Content-Disposition: inline; ' \
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
363 'filename="logo.%s"' % extension[format]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
364
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
365
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
366 # Seperate header from data
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
367 print
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
368
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
369 # Finally, and at last, send the logo.
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
370 print logo.getvalue()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
371
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
372
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
373 def send_form(controls, errors=[], htdocs_directory=None) :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
374 if htdocs_directory is None :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
375 htdocs_directory = os.path.join(
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
376 os.path.dirname(__file__, "htdocs") )
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
377
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
378 subsitutions = {}
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
379 subsitutions["version"] = weblogolib.release_description
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
380
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
381 for c in controls :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
382 if c.options :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
383 for opt in c.options :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
384 subsitutions[opt.replace('/','_')] = ''
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
385 subsitutions[c.value.replace('/','_')] = 'selected'
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
386 else :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
387 value = c.value
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
388 if value == None : value = 'auto'
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
389 if value=='true':
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
390 subsitutions[c.name] = 'checked'
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
391 elif type(value)==bool :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
392 if value :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
393 subsitutions[c.name] = 'checked'
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
394 else :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
395 subsitutions[c.name] = ''
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
396 else :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
397 subsitutions[c.name] = str(value)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
398 subsitutions[c.name+'_err'] = ''
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
399
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
400 if errors :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
401 print >>sys.stderr, errors
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
402 error_message = []
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
403 for e in errors :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
404 if type(e) is str :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
405 msg = e
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
406 elif len(e)==2:
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
407 subsitutions[e[0]+"_err"] = "class='error'"
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
408 msg = e[1]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
409 else :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
410 msg = e[0]
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
411
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
412
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
413 error_message += "ERROR: "
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
414 error_message += msg
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
415 error_message += ' <br />'
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
416
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
417 error_message += \
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
418 "<input style='float:right; font-size:small' type='submit' name='cmd_validate' value='Clear Error' /> "
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
419 subsitutions["error_message"] = ''.join(error_message)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
420 else :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
421 subsitutions["error_message"] = ""
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
422
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
423
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
424 template = resource_string("create_html_template.html", htdocs_directory)
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
425 html = Template(template).safe_substitute(subsitutions) #FIXME
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
426
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
427 print "Content-Type: text/html\n\n"
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
428 print html
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
429
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
430 # DEBUG
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
431 # keys = subsitutions.keys()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
432 # keys.sort()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
433 # for k in keys :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
434 # print k,"=", subsitutions[k], " <br />"
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
435
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
436 #for k in controls :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
437 # print k.name,"=", k.get_value(), " <br />"
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
438
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
439
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
440
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
441 if __name__=="__main__" :
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
442 main()
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
443
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
444
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
445
c55bdc2fb9fa Uploaded
davidmurphy
parents:
diff changeset
446