def export(objs, filename): """exporting to file folder""" #sayz(filename) sayz("stpZ version " + ___stpZversion___) ext = os.path.splitext(os.path.basename(filename))[1] fname = os.path.splitext(os.path.basename(filename))[0] basepath = os.path.split(filename)[0] tempdir = tempfile.gettempdir() # get the current temporary directory filepath = os.path.join(basepath, fname) + u'.stp' filepath_base = os.path.join(basepath, fname) namefpath = os.path.join(basepath, fname) outfpath = os.path.join(basepath, fname) + u'.stpZ' outfpath_stp = os.path.join(basepath, fname) + u'.stp' outfpath_base = basepath #outfpath_str = mkz_string(os.path.join(basepath,fname)) outfpath_str = os.path.join(basepath, fname) if os.path.exists(outfpath_stp): sayzw( "File cannot be compressed because a file with the same name exists '" + outfpath_stp + "'") QtGui.qApp.restoreOverrideCursor() reply = QtGui.QMessageBox.information( None, "info", "File cannot be compressed because\na file with the same name exists\n'" + outfpath_stp + "'") else: ImportGui.export(objs, outfpath_stp) if 0: #os.path.exists(namefpath): sayzw( "File cannot be compressed because a file with the same name exists '" + namefpath + "'") QtGui.qApp.restoreOverrideCursor() reply = QtGui.QMessageBox.information( None, "info", "File cannot be compressed because\na file with the same name exists\n'" + namefpath + "'") else: with builtin.open(outfpath_stp, 'rb') as f_in: file_content = f_in.read() new_f_content = file_content f_in.close() with gzip_utf8.open(outfpath_str, 'wb') as f_out: f_out.write(new_f_content) f_out.close() if os.path.exists(outfpath): os.remove(outfpath) os.rename(outfpath_str, outfpath) os.remove(outfpath_stp) else: os.rename(outfpath_str, outfpath) os.remove(outfpath_stp)
def export(objs,filename): """exporting to file folder""" #sayz(filename) sayz("stpZ version "+___stpZversion___) ext = os.path.splitext(os.path.basename(filename))[1] fname=os.path.splitext(os.path.basename(filename))[0] basepath=os.path.split(filename)[0] tempdir = tempfile.gettempdir() # get the current temporary directory filepath = os.path.join(basepath,fname) + u'.stp' filepath_base = os.path.join(basepath,fname) namefpath = os.path.join(basepath,fname) outfpath = os.path.join(basepath,fname)+u'.stpZ' outfpath_stp = os.path.join(basepath,fname)+u'.stp' outfpath_base = basepath #outfpath_str = mkz_string(os.path.join(basepath,fname)) outfpath_str = os.path.join(basepath,fname) if os.path.exists(outfpath_stp): sayzw("File cannot be compressed because a file with the same name exists '"+ outfpath_stp +"'") QtGui.QApplication.restoreOverrideCursor() reply = QtGui.QMessageBox.information(None,"info", "File cannot be compressed because\na file with the same name exists\n'"+ outfpath_stp + "'") else: ImportGui.export(objs,outfpath_stp) if 0: #os.path.exists(namefpath): sayzw("File cannot be compressed because a file with the same name exists '" + namefpath + "'") QtGui.QApplication.restoreOverrideCursor() reply = QtGui.QMessageBox.information(None,"info", "File cannot be compressed because\na file with the same name exists\n'"+ namefpath+ "'") else: with builtin.open(outfpath_stp, 'rb') as f_in: file_content = f_in.read() new_f_content = file_content f_in.close() with gzip_utf8.open(outfpath_str, 'wb') as f_out: f_out.write(new_f_content) f_out.close() if os.path.exists(outfpath): os.remove(outfpath) os.rename(outfpath_str, outfpath) os.remove(outfpath_stp) else: os.rename(outfpath_str, outfpath) os.remove(outfpath_stp)
def insert(filename,doc): sayz("stpZ version "+___stpZversion___) with gzip_utf8.open(filename, 'rb') as f: file_content = f.read() ext = os.path.splitext(os.path.basename(filename))[1] fname=os.path.splitext(os.path.basename(filename))[0] basepath=os.path.split(filename)[0] filepath = os.path.join(basepath,fname + u'.stp') tempdir = tempfile.gettempdir() # get the current temporary directory tempfilepath = os.path.join(tempdir,fname + u'.stp') with builtin.open(tempfilepath, 'w') as f: #py3 f.write(file_content) ImportGui.insert(tempfilepath, doc) #ImportGui.open(tempfilepath) try: os.remove(tempfilepath) except OSError: sayzerr("error on removing "+tempfilepath+" file") pass