diff options
author | ryuslash | 2010-04-19 09:16:04 +0200 |
---|---|---|
committer | ryuslash | 2010-04-19 09:16:04 +0200 |
commit | af529bcd4e214c13b7810eeba4d425c4a1129b58 (patch) | |
tree | 3d17d70dd9e67e9173a97267002bfdb364aacfd8 /backend.py | |
parent | 2db5555609b4ab157ea836f9611c6faa80508cf3 (diff) | |
download | 4grab-af529bcd4e214c13b7810eeba4d425c4a1129b58.tar.gz 4grab-af529bcd4e214c13b7810eeba4d425c4a1129b58.zip |
Not checking and kirbybase
Using kirbybase to store downloaded images
A nasty bug that always returned the wrong result when checking whether an image had already been downloaded has been fixed
Diffstat (limited to 'backend.py')
-rw-r--r-- | backend.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/backend.py b/backend.py new file mode 100644 index 0000000..8dffb3e --- /dev/null +++ b/backend.py @@ -0,0 +1,60 @@ +import os +import modules.kirbybase +from util import confdir,raw_input_with_default +import config + +class _Backend(object): + """ A class that communicates with the datastore """ + def __init__(self): + self.table = os.path.join(confdir, "images.tbl") + self.store = modules.kirbybase.KirbyBase() + self.__collection = "" + self.__new_collection = [] + + self.load() + + def create_store_if_needed(self): + if not os.path.exists(self.table): + return self.store.create(self.table, ["filename:String"]) + return True + + def add(self, filename): + self.__new_collection.append(filename) + + def check(self, filename): + collected = filename in self.__collection + downloaded = filename in self.__new_collection + + if not downloaded: + self.add(filename) + + if collected or downloaded: + return True + + return False + + def save(self): + os.remove(self.table) + self.create_store_if_needed() + for f in self.__new_collection: + self.store.insert(self.table, [f]) + + def load(self): + if os.path.exists(self.table): + self.__collection = self.store.select(self.table, ['recno'], ['*'], ['filename'], returnType="report") + +_backend = None +def Backend(): + global _backend + + if _backend == None: + _backend = _Backend() + return _backend + +if __name__ == "__main__": + backend = Backend() + config._optioncreator = raw_input_with_default + cfg = config.Configuration() + + for f in os.listdir(cfg.get_archive_location()): + backend.add(f) |