1 #!/usr/bin/env python 2 3 from os.path import abspath, commonprefix, exists, join 4 from os import makedirs 5 6 STORE_DIR = "/tmp/imip" 7 8 def check_dir(base, dir): 9 return commonprefix([base, abspath(dir)]) == base 10 11 class FileStore: 12 13 "A file store of tabular data." 14 15 def __init__(self): 16 self.store_dir = STORE_DIR 17 if not exists(self.store_dir): 18 makedirs(self.store_dir) 19 20 def get_freebusy(self, calendar): 21 22 "Get free/busy details from the given 'calendar'." 23 24 dir = join(self.store_dir, calendar) 25 if not check_dir(self.store_dir, dir): 26 return None 27 28 filename = join(dir, "freebusy") 29 if not exists(filename): 30 return None 31 32 f = open(filename) 33 try: 34 l = [] 35 for line in f.readlines(): 36 l.append(line.strip().split("\t")) 37 return l 38 finally: 39 f.close() 40 41 # vim: tabstop=4 expandtab shiftwidth=4