#!/usr/bin/python
import os
import sre
from obsconfig import observatory
class FileList:
def __init__(self, loc=None, projectcode=None):
self.message ="""Content-Type: text/xml
"""
self.error = None
if loc is None:
loc = observatory['rpfpath'][0]
else:
loc = int(loc)
if loc< 0 or loc >=len(observatory['rpfpath']):
self.error = "Invalid Path"
return
else:
loc = observatory['rpfpath'][loc]
if os.path.exists(loc) and os.path.isdir(loc):
rx = sre.compile("\d{4}-\d{2}-d{2}_\d{4}-M\d{3}.rpf.*")
self.files = [ f for f in os.listdir(loc) if sre.match(rx, f) ]
if projectcode is not None:
self.files = [ f for f in self.files if sre.match(projectcode,
f) ]
if len(self.files) == 0:
self.error = "No rpfits files found"
else:
self.error = "Invalid Path"
def __str__(self):
if self.error:
self.message += "