def _setTableFilepath(request, table, file_name, verify=True, fullpath=False): """ Sets the file path in the session key :param request: request for the session :param Table table: Table object :param str file_name: name of file without extension :param bool verify: check for a valid filepath :param bool fullpath: name is a full path :return str: Table filepath """ if fullpath: table_filepath = file_name else: table_filepath = _createTableFilepath(file_name) if verify: if not os.path.isfile(table_filepath): raise InternalError("Could not find Table file %s" % table_filepath) request.session[TABLE_FILE_KEY] = table_filepath if table is None: import pdb; pdb.set_trace() if ut.getFileExtension(table_filepath) != settings.SCISHEETS_EXT: import pdb; pdb.set_trace() return table_filepath
def readObjectFromFile(filepath, verify=False): """ Get the object from the file :param str filepath: full path to file :param bool verify: checks the file path if the object has a getFilepath method :return object: :raises ValueError: Checks that the file path is set Notes: Handles legacy of accessing PCL files, which is mostly in tests. """ if ut.getFileExtension(filepath).lower() == 'pcl': adj_filepath = ut.changeFileExtension(filepath, settings.SCISHEETS_EXT) else: adj_filepath = filepath with open(adj_filepath, "r") as fh: json_str = fh.read() new_object = deserialize(json_str) if 'getFilepath' in dir(new_object): if verify and new_object.getFilepath() != adj_filepath: if new_object.getFilepath() == filepath: new_object.setFilepath(adj_filepath) else: raise ValueError("File path is incorrect or missing.") return new_object
def getSerializationDict(self, class_variable): """ :param str class_variable: key to use for the class name :return dict: dictionary encoding the Table object and its columns """ serialization_dict = {} serialization_dict[class_variable] = str(self.__class__) filepath = self.getFilepath() if self.getFilepath() is not None: if ut.getFileExtension(self.getFilepath()) != settings.SCISHEETS_EXT: filepath = ut.changeFileExtension(self.getFilepath(), settings.SCISHEETS_EXT) more_dict = { "_name": self.getName(is_global_name=False), "_prologue_formula": self.getPrologue().getFormula(), "_epilogue_formula": self.getEpilogue().getFormula(), "_is_evaluate_formulas": self.getIsEvaluateFormulas(), "_filepath": filepath, } serialization_dict.update(more_dict) _children = [] for child in self.getChildren(): if not Table.isNameColumn(child): _children.append(child.getSerializationDict(class_variable)) serialization_dict["_children"] = _children return serialization_dict
def _listTableFiles(): """ Output: returns response that contains the list of table files in data """ file_list = [ut.stripFileExtension(ff) for ff in os.listdir(settings.SCISHEETS_USER_TBLDIR) if ut.getFileExtension(ff) == settings.SCISHEETS_EXT and ff[0] != "_"] file_list.sort() return _makeAjaxResponse(file_list, True)