def write_data_file(file_path=None, data={}, f=False): '''Write data to file # kwargs: file_path: the file path to write to data: the data to write f (bool): force write mode, if false, will ask for confirmation when overwriting existing files ''' # Ask for confirmation on existing file if not f and os.path.exists(file_path): # to do pass # write file status = False try: # Open file in write mode data_file = open(file_path, "w") try: data_file.write(header_text) data_file.write("\n{}\n".format(data_start_tag)) data_file.write(convert_data_to_text(data)) data_file.write("\n{}\n".format(data_end_tag)) status = True finally: data_file.close() except IOError: # Show error warning msg = "Failed to write to file:\n'{}'".format(file_path) QtGui.QMessageBox.warning(get_maya_window(), "Warning", msg) return status
def read_data_file(file_path): '''Read data from file ''' msg = "file path '{}' not found".format(file_path) assert os.path.exists(file_path), msg msg = "{} does not seem to be a file".format(file_path) assert os.path.isfile(file_path), msg # Read file try: data_file = open(file_path, "r") try: text_data = data_file.read() finally: data_file.close() except IOError: # Show error warning msg = "Failed to read from file:\n'{}'".format(file_path) QtGui.QMessageBox.warning(get_maya_window(), "Warning", ) # Get data segment regex_res = re.search(r"(?<=%s)(.*?)(?=%s)" % (data_start_tag, data_end_tag), text_data, re.DOTALL) msg = "file '{}' appear to be invalid and is missing the data delimiters" assert regex_res, msg.format(file_path) return eval(regex_res.group())
def write_data_file(file_path=None, data=dict(), f=False): '''Write data to file # kwargs: file_path: the file path to write to data: the data to write f (bool): force write mode, if false, will ask for confirmation when overwriting existing files ''' # Ask for confirmation on existing file if not f and os.path.exists(file_path): pass # to do # write file status = False try: # Open file in write mode data_file = open(file_path, "w") try: data_file.write(header_text) data_file.write('\n%s\n' % data_start_tag) data_file.write(convert_data_to_text(data)) data_file.write('\n%s\n' % data_end_tag) status = True finally: data_file.close() except IOError: # Show error warning QtGui.QMessageBox.warning(get_maya_window(), 'Warning', 'Failed to write to file:\n"%s"' % file_path) return status
def read_data_file(file_path): '''Read data from file ''' assert os.path.exists(file_path), 'file path "%s" not found' % file_path assert os.path.isfile( file_path), '"%s does not seem to be a file"' % file_path # Read file try: data_file = open(file_path, "r") try: text_data = data_file.read() finally: data_file.close() except IOError: # Show error warning QtGui.QMessageBox.warning( get_maya_window(), 'Warning', 'Failed to read from file:\n"%s"' % file_path) # Get data segment regex_res = re.search( r'(?<=%s)(.*?)(?=%s)' % (data_start_tag, data_end_tag), text_data, re.DOTALL) assert regex_res, 'file "%s" appear to be invalid and is missing the data delimiters' % file_path return eval(regex_res.group())
def read_data_file(file_path): '''Read data from file ''' msg = "file path '{}' not found".format(file_path) assert os.path.exists(file_path), msg msg = "{} does not seem to be a file".format(file_path) assert os.path.isfile(file_path), msg # Read file try: data_file = open(file_path, "r") try: text_data = data_file.read() finally: data_file.close() except IOError: # Show error warning msg = "Failed to read from file:\n'{}'".format(file_path) QtGui.QMessageBox.warning( get_maya_window(), "Warning", ) # Get data segment regex_res = re.search( r"(?<=%s)(.*?)(?=%s)" % (data_start_tag, data_end_tag), text_data, re.DOTALL) msg = "file '{}' appear to be invalid and is missing the data delimiters" assert regex_res, msg.format(file_path) return eval(regex_res.group())
def read_data_file(file_path): """Read data from file """ assert os.path.exists(file_path), 'file path "%s" not found' % file_path assert os.path.isfile(file_path), '"%s does not seem to be a file"' % file_path # Read file try: data_file = open(file_path, "r") try: text_data = data_file.read() finally: data_file.close() except IOError: # Show error warning QtGui.QMessageBox.warning(get_maya_window(), "Warning", 'Failed to read from file:\n"%s"' % file_path) # Get data segment regex_res = re.search(r"(?<=%s)(.*?)(?=%s)" % (data_start_tag, data_end_tag), text_data, re.DOTALL) assert regex_res, 'file "%s" appear to be invalid and is missing the data delimiters' % file_path return eval(regex_res.group())