source: branches/parallel/monitor/cgi-bin/filelist.py@ 2028

Last change on this file since 2028 was 1295, checked in by mar637, 18 years ago

merge form Release2.1.1 branch

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
1#!/usr/bin/python
2import os
3import sre
4from obsconfig import observatory
5
6class FileList:
7
8 def __init__(self, loc=None, projectcode=None):
9 self.message ="""Content-Type: text/xml
10
11<?xml version="1.0" encoding="ISO-8859-1"?>"""
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 rx = sre.compile("\d{4}-\d{2}-d{2}_\d{4}-M\d{3}.rpf.*")
24 self.files = [ f for f in os.listdir(loc) if sre.match(rx, f) ]
25 if projectcode is not None:
26 self.files = [ f for f in self.files if sre.match(projectcode,
27 f) ]
28 if len(self.files) == 0:
29 self.error = "No rpfits files found"
30 else:
31 self.error = "Invalid Path"
32
33
34 def __str__(self):
35 if self.error:
36 self.message += "<Error>\n"
37 self.message += self.error
38 self.message += "</Error>\n"
39 else:
40 self.message += "<Listing>\n"
41 for s in self.files:
42 self.message += "<File>" + s + "</File>\n"
43 self.message += "</Listing>\n"
44 return self.message
45if __name__ == "__main__":
46 import cgi
47 form = cgi.FieldStorage()
48 pfilter = None
49 if form.has_key('project'):
50 pfilter = form.getfirst("project", None)
51 if form.has_key('path'):
52 pathindex = form.getfirst("path",0)
53 print FileList(pathindex, pfilter)
54 else:
55 print FileList()
Note: See TracBrowser for help on using the repository browser.