source: trunk/monitor/cgi-bin/asapmon.py@ 709

Last change on this file since 709 was 703, checked in by mar637, 19 years ago

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1#!/usr/bin/python
2import sys,os
3import cgi
4# enable cgi debugging
5import cgitb; cgitb.enable()
6
7from simpletal import simpleTAL, simpleTALES
8
9#absolute home
10htmlbase = "/var/www/asaptest/"
11cgibase = "/cgi-bin/asapmon"
12absbase = "/asapmon"
13
14from asapconfig import *
15logsink = LogSink()
16sys.stdout = logsink
17sys.stderr = logsink
18import asap
19sys.stdout = sys.__stdout__
20sys.stderr = sys.__stderr__
21
22def resetstd():
23 sys.stdout = sys.__stdout__
24 sys.stderr = sys.__stderr__
25
26
27class myForm:
28 def __init__(self):
29 self.fields = {}
30 self.form = cgi.FieldStorage()
31 self.context = simpleTALES.Context(allowPythonPath=1)
32 self.logsink = WritableObject()
33
34 def decodePath(self,pi,fi):
35 pi = int(pi)
36 fi = int(fi)
37 p = rpfpath[pi]
38 from filelist import FileList
39 fl = FileList(pi)
40 if fl.error:
41 return None
42 f = fl.files[fi]
43 return p+"/"+f
44
45 def plotForm(self):
46 pathidx = self.form.getfirst("dlist",None)
47 fnameidx = self.form.getfirst("list",None)
48 self.fields['cdir'] = pathidx
49 self.fields['cfile'] = fnameidx
50 from filelist import FileList
51 fl = FileList(pathidx)
52 self.fields['files'] = fl.files
53 file=self.decodePath(pathidx,fnameidx)
54 try:
55 s = asap.scantable(file)
56 s.set_unit(self.form.getfirst("unit","channel"))
57 s.set_freqframe(self.form.getfirst("frame","LSRK"))
58 s.set_doppler(self.form.getfirst("doppler","RADIO"))
59
60 if self.form.has_key("quotient"):
61 q = s.auto_quotient()
62 del s
63 s=q
64 if self.form.has_key('baseline'):
65 if self.form.has_key('polyorder'):
66 s.auto_poly_baseline(order=int(self.form.getfirst("polyorder",0)))
67 if s.nif() > 1:
68 asap.plotter.set_mode("t","i")
69 else:
70 asap.plotter.set_mode("t","p")
71 asap.plotter.plot(s)
72
73 imname = htmlbase+"tmp/plot.png"
74 asap.plotter.save(imname,dpi=80)
75 self.fields['imagename'] = absbase+"/tmp/plot.png"
76 except RuntimeError:
77 return
78
79
80 def buildContext (self, title):
81 self.context.addGlobal("fields", self.fields)
82 self.context.addGlobal("title", title)
83
84 def expandTemplate (self, templateName):
85 sys.stdout.write ("Content-Type: text/html\n")
86 sys.stdout.write ("\n")
87 # Expand the template and print it out
88 templateFile = open(templateName, 'r')
89 template = simpleTAL.compileHTMLTemplate(templateFile)
90 templateFile.close()
91 # Expand the template as HTML using this context
92 template.expand(self.context, sys.stdout)
93 sys.exit(0)
94
95 def main(self):
96 self.fields['directories'] = rpfpath
97 self.fields['cdir'] = len(rpfpath)-1
98 from filelist import FileList
99 files = []
100 fl = FileList(len(rpfpath)-1)
101 if not fl.error:
102 self.fields['files'] = fl.files
103 self.fields['cfile'] = len(fl.files)-1
104 self.fields['restfreqs'] = [110.0,86.0]
105 self.fields['border'] = range(10)
106 self.fields['imagename'] = ""
107 sys.stdout = self.logsink
108 sys.stderr = self.logsink
109 title = "ASAP %s Online Monitor" % (observatory)
110 if ( not self.form.has_key("plot")):
111 self.buildContext(title)
112 resetstd()
113 self.expandTemplate(htmlbase+"asapmon.html.template")
114 else: # run
115 self.plotForm()
116 self.buildContext(title)
117 resetstd()
118 self.expandTemplate(htmlbase+"asapmon.html.template")
119
120
121f = myForm()
122f.main()
Note: See TracBrowser for help on using the repository browser.