]> scripts.mit.edu Git - wizard.git/blob - wizard/sset.py
Rename cache to serialized set.
[wizard.git] / wizard / sset.py
1 import os.path
2
3 class ISerializedSet(object):
4     def put(self, name):
5         raise NotImplementedError
6
7 class SerializedSet(ISerializedSet):
8     def __init__(self, file):
9         self.set = set()
10         if os.path.isfile(file):
11             for line in open(file, "r"):
12                 self.set.add(line.rstrip())
13         self.file = open(file, "a")
14     def __contains__(self, name):
15         return name in self.set
16     def add(self, name):
17         self.set.add(name)
18         self.file.write(name + "\n")
19         self.file.flush()
20
21 class DummySerializedSet(ISerializedSet):
22     """Dummy object that doesn't actually cache anything and
23     claims that everything needs to be done"""
24     def __contains__(self, name):
25         return False
26     def add(self, name):
27         pass