def __init__(self,collections): if not os.path.exists('saved_library'): # will change to be name of the .avc file ok print("making new save data") self.library = Library() # for now self.library.init_from_xml("test.avc") else: self.load_library('saved_library',True) #self.savedata = open('saved_library','wb') self.index = Index(self.library.get_clip_names()) self.tag_index = Index(self.library.get_tags()) self.col_index = Index(collections)
class Searcher(): def __init__(self,collections): if not os.path.exists('saved_library'): # will change to be name of the .avc file ok print("making new save data") self.library = Library() # for now self.library.init_from_xml("test.avc") else: self.load_library('saved_library',True) #self.savedata = open('saved_library','wb') self.index = Index(self.library.get_clip_names()) self.tag_index = Index(self.library.get_tags()) self.col_index = Index(collections) def load_library(self,filename,debug=False): if debug: print("reading old save data") with open(filename,'rb') as read: try: self.library = pickle.load(read) except: if debug: print('error reading',filename) read.close() os.remove(filename) self.__init__() def save_library(self,filename,debug=False): if debug: print('saving data') with open(filename,'wb') as write: pickle.dump(self.library,write) def quit(self): self.save_library('saved_library',True) def search(self,term): # let's try having 2nd value be return self.index.by_prefix(term) def search_tag(self,term): return self.tag_index.by_prefix(term) def search_col(self,term): return self.col_index.by_prefix(term) def add_tag_to_clip(self,tag,clip): clip.add_tag(tag) self.library.add_clip_to_tag(clip,tag) self.tag_index.add_word(tag) def remove_tag_from_clip(self,tag,clip): clip.remove_tag(tag) self.library.remove_clip_from_tag(clip,tag) def remove_tag_from_library(self,tag): self.tag_index.remove_word(tag) self.library.remove_tag(tag) def get_from_name(self,name): return self.library.get_clip_from_name(name) def has_name(self,name): return name in self.library.clips