def __init__(self, model): self.model = model self.fs = GoogleDocs(create_docs_client(model.ui, "gRefer"), model.config.dir_name)
class gRefer: logger = logging.getLogger(name="gRefer.gRefer") def __init__(self, model): self.model = model self.fs = GoogleDocs(create_docs_client(model.ui, "gRefer"), model.config.dir_name) def initialize(self): self.model.config.initialize_dir(self.model.namespace) self.add_bib() self.model.config.write_config() def add_bib(self): ui = self.model.ui fs = self.fs config = { #Set the input format input_format: input_types[ui.prompt_input_format(input_types)[0]], #Set the output format output_format: output_types[ui.prompt_output_format(output_types)[0]] } #Set up the Google Doc Folders to grab the references from selected_folders = ui.getFolderSelection(fs.getFolders()) for selected_folder in selected_folders: item = selected_folder.createDescriptor() config[google_folder] = item config[parents] = {} #Add to the configuration self.model.config[ui.prompt_output_filename()] = config def display_info(self): config = self.model.config for bib in config: print "%s: %s"%(os.path.basename(bib), config[bib][google_folder]['title']) folder = self.fs.getFolder(config[bib][google_folder]) parent_folders = self.__find_parents(folder) for parent in parent_folders: print "", parent print "" def __find_parents(self, folder): """ Recurses up the parental hierarchy Return a list of all parents in the parental hierarchy """ parent_map, parent_file = self.__read_parents(folder) toRet = [] for parent in parent_map: parent_folder = self.fs.getFolder(parent_map[parent]) toRet.append(parent_folder) toRet = toRet + self.__find_parents(parent_folder) return toRet def update(self): """updates the local cache""" config = self.model.config for bib in config: unique = {} bib_listing = [] #Collect all the folders in the parental hierarchy folder = self.fs.getFolder(config[bib][google_folder]) parent_folders = self.__find_parents(folder) #Get all the files from all the folders contents = folder.list() for parent_folder in parent_folders: contents = contents + parent_folder.list() #Ensure that the cached version of these files is up to date for c in contents: try: if not unique.has_key(c.getID()): c.download() print "Downloaded %s"%c.title() else: pass # File has already been updated in this update except NotModified, e: print ("Up To Date: %s" % c.title()) unique[c.getID()] = True if str(c.content_type()) not in impl.ignore_mime_types: bib_listing.append(c.getID()) #Update the bibliographies file listing config[bib][listing] = bib_listing config.write_config()