source: branches/Release2.0/monitor/cgi-bin/filelist.py@ 2793

Last change on this file since 2793 was 739, checked in by mar637, 19 years ago

split obsconfig from asapconfig and had to update the import

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.4 KB
Line 
1#!/usr/bin/python
2import os
3from obsconfig import observatory
4
5class FileList:
6
7 def __init__(self, loc=None):
8 self.message ="""Content-Type: text/xml
9
10<?xml version="1.0" encoding="ISO-8859-1"?>"""
11
12 self.error = None
13 if loc is None:
14 loc = observatory['rpfpath'][0]
15 else:
16 loc = int(loc)
17 if loc< 0 or loc >=len(observatory['rpfpath']):
18 self.error = "Invalid Path"
19 return
20 else:
21 loc = observatory['rpfpath'][loc]
22 if os.path.exists(loc) and os.path.isdir(loc):
23 self.files = filter(lambda x: x.lower().endswith("rpf"), os.listdir(loc))
24 if len(self.files) == 0:
25 self.error = "No rpfits files found"
26 else:
27 self.error = "Invalid Path"
28
29
30 def __str__(self):
31 if self.error:
32 self.message += "<Error>\n"
33 self.message += self.error
34 self.message += "</Error>\n"
35 else:
36 self.message += "<Listing>\n"
37 for s in self.files:
38 self.message += "<File>" + s + "</File>\n"
39 self.message += "</Listing>\n"
40 return self.message
41if __name__ == "__main__":
42 import cgi
43 form = cgi.FieldStorage()
44 if form.has_key('path'):
45 pathindex = form.getfirst("path",0)
46 print FileList(pathindex)
47 else:
48 print FileList()
Note: See TracBrowser for help on using the repository browser.