def fetch_multi(self, data_obj, db_token="db:", silent=False, intend_read=True): r"""Handle various sorts of file pointers/data if `data_obj` is an array, return a deep copy of it is a string: if it begins with "db:" -- string after db is a db key otherwise assume it is a file and try to open it """ if isinstance(data_obj, str): if data_obj[0:len(db_token)] == db_token: db_key = data_obj[len(db_token):] filename = self.fetch(db_key, intend_read=intend_read, silent=silent) else: filename = data_obj prefix = "non-db filename " ft.path_properties(filename, intend_read=intend_read, is_file=True, prefix=prefix, silent=silent) ret_data = algebra.make_vect(algebra.load(filename)) else: ret_data = copy.deepcopy(data_obj) return ret_data
def fetch_multi(self, data_obj, db_token="db:", silent=False, intend_read=False): r"""Handle various sorts of file pointers/data if `data_obj` is an array, return a deep copy of it is a string: if it begins with "db:" -- string after db is a db key otherwise assume it is a file and try to open it """ if isinstance(data_obj, str): if data_obj[0:len(db_token)] == db_token: db_key = data_obj[len(db_token):] filename = self.fetch(db_key, intend_read=intend_read, silent=silent) else: filename = data_obj prefix = "non-db filename " ft.path_properties(filename, intend_read=intend_read, is_file=True, prefix=prefix, silent=silent) ret_data = algebra.make_vect(algebra.load(filename)) else: ret_data = copy.deepcopy(data_obj) return ret_data
def fetch(self, db_key, pick=None, intend_read=False, intend_write=False, purpose="", silent=False, tack_on=None): r"""The access function for this database class: Fetch the data for a requested key in the db. `pick` takes one index from a file list if the database entry is a file list, return a tuple of the index indices and a dictionary (the list orders the dictionary) if `intend_write` then die if the path does not exist or not writable if `intend_read` then die if the path does not exist `purpose` inputs a purpose for this file for logging `silent` does not print anything upon fetch unless error """ # if not given pick explicitly, try to extract it from the given key # "key_to_db:pick_entry" if not pick: db_key = db_key.split(":") if len(db_key) == 2: main_db = db_key[0] pick = db_key[1] else: main_db = db_key[0] pick = None db_key = main_db dbentry = self._pathdict[db_key] prefix = "%s (%s) " % (purpose, db_key) if 'file' in dbentry: pathout = copy.deepcopy(dbentry['file']) if tack_on: pathout = tack_on_subdir(pathout, tack_on) ft.path_properties(pathout, intend_write=intend_write, intend_read=intend_read, is_file=True, prefix=prefix, silent=silent) if 'path' in dbentry: pathout = copy.deepcopy(dbentry['path']) if tack_on: pathout = tack_on_subdir(pathout, tack_on) ft.path_properties(pathout, intend_write=intend_write, intend_read=intend_read, is_file=False, prefix=prefix, silent=silent) if 'filelist' in dbentry: pathout = (copy.deepcopy(dbentry['listindex']), \ copy.deepcopy(dbentry['filelist'])) if tack_on: for item in pathout[0]: pathout[1][item] = tack_on_subdir(pathout[1][item], tack_on) if pick: pathout = pathout[1][pick] ft.path_properties(pathout, intend_write=intend_write, intend_read=intend_read, is_file=True, prefix=prefix, silent=silent) else: for item in pathout[0]: filepath = pathout[1][item] ft.path_properties(filepath, intend_write=intend_write, intend_read=intend_read, is_file=True, file_index=item, prefix=prefix, silent=silent) return pathout