2010-04-19 09:16:04 +02:00
|
|
|
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):
|
2010-04-22 22:24:38 +02:00
|
|
|
if os.path.exists(self.table):
|
|
|
|
os.remove(self.table)
|
|
|
|
|
2010-04-19 09:16:04 +02:00
|
|
|
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)
|