1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/imip_store.py Mon Sep 22 16:34:36 2014 +0200
1.3 @@ -0,0 +1,41 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +from os.path import abspath, commonprefix, exists, join
1.7 +from os import makedirs
1.8 +
1.9 +STORE_DIR = "/tmp/imip"
1.10 +
1.11 +def check_dir(base, dir):
1.12 + return commonprefix([base, abspath(dir)]) == base
1.13 +
1.14 +class FileStore:
1.15 +
1.16 + "A file store of tabular data."
1.17 +
1.18 + def __init__(self):
1.19 + self.store_dir = STORE_DIR
1.20 + if not exists(self.store_dir):
1.21 + makedirs(self.store_dir)
1.22 +
1.23 + def get_freebusy(self, calendar):
1.24 +
1.25 + "Get free/busy details from the given 'calendar'."
1.26 +
1.27 + dir = join(self.store_dir, calendar)
1.28 + if not check_dir(self.store_dir, dir):
1.29 + return None
1.30 +
1.31 + filename = join(dir, "freebusy")
1.32 + if not exists(filename):
1.33 + return None
1.34 +
1.35 + f = open(filename)
1.36 + try:
1.37 + l = []
1.38 + for line in f.readlines():
1.39 + l.append(line.strip().split("\t"))
1.40 + return l
1.41 + finally:
1.42 + f.close()
1.43 +
1.44 +# vim: tabstop=4 expandtab shiftwidth=4