libsaria: Load saved library on startup

I want to load the library and create a tree representing the entire
library on startup.
This commit is contained in:
Bryan Schumaker 2011-05-21 15:27:58 -04:00
parent 45600e8a2d
commit c74f9680b2
2 changed files with 15 additions and 2 deletions

View File

@ -9,6 +9,9 @@ add_path = library.add_path
get_attrs = library.get_attrs
list_ids = tree.list_ids
library.load()
tree.make_tree()
def update_lib():
update.update()
tree.make_tree()

View File

@ -8,11 +8,21 @@ lock_library = library_lock.acquire
unlock_library = library_lock.release
# Map directory -> dict()
lib_dict = dict()
lib_dict = None
LIB_FILE = "library"
def load():
global lib_dict
saved_lib = storage.load_obj(LIB_FILE, dict)
if saved_lib.__class__ != dict:
saved_lib = dict()
lock_library()
lib_dict = saved_lib
unlock_library()
# NOTE: You should already be holding the lock when you call this
def save():
storage.save_obj("library", lib_dict)
storage.save_obj(LIB_FILE, lib_dict)
def add_path(path):
lock_library()