def mkstemp(suffix='', prefix='tmp', dir=None, text=False): if text: raise NotImplementedError if dir is None: dir = '' # TODO: Make suffix actually follow the rest of the filename. f, err = TempFile(dir, prefix + '-' + suffix) if err: raise OSError(err.Error()) try: fd, err = Dup(f.Fd()) if err: raise OSError(err.Error()) return fd, f.Name() finally: f.Close()
def printlabel(self, rc, ws): # Print label as specified in the row of the input Workbook # Completes Output and Archive file path names # :param rc: Row contents object defining characteristics of the test # :return: # """ try: TF = TempFile.TempFile() files = FileLocation.FileLocation(self.LabelFileDirectory, rc) LabelFileName = os.path.join(self.LabelFileDirectory, rc.Label) OutputFileName = files.outputpath + "\\" + files.left( rc.Label, len(rc.Label) - 4) + ".prn" ArchiveFileName = files.archivepath + "\\" + files.left( rc.Label, len(rc.Label) - 4) + ".prn" BMPFileName = files.BMPPath + "\\" + files.left( rc.Label, len(rc.Label) - 4) + ".bmp" if rc.Function == "M": if self.FileExists(OutputFileName): MakeBMP( self, OutputFileName, BMPFileName, rc.IPAddress ) # send the ZPL to a printer to generate the .bmp image self.sheetoutput(rc, ".bmp File Created", ws, "", "", BMPFileName) else: self.sheetoutput(rc, "ZPL File not Found", ws, OutputFileName, "", "") else: if self.FileExists(LabelFileName): if self.FileExists(self.TempOut): os.remove(self.TempOut) tfilename = TF.writetempfile( rc, self.TempOut, LabelFileName ) # Use the row contents to build the Temp file zdp = self.LaunchLDA( rc.Application, tfilename ) # print the requested label via ZebraDesigner app if self.WaitForFile(self.TempOut): #shutil.copy(self.TempOut, OutputFileName) shutil.copyfile(self.TempOut, OutputFileName) if self.WaitForFile( OutputFileName): # Determine test results result = self.CheckOutput(OutputFileName, ArchiveFileName, zdp) if MakeBMP( self, OutputFileName, BMPFileName, rc.IPAddress ): # send the ZPL to a printer to generate the .bmp image result = result + " - BMP File not created!" self.sheetoutput( rc, result, ws, files.outputpath, files.archivepath, BMPFileName) # Report test results # print(rc.Printer + ' ' + rc.Language + ' ' + rc.Label + ' ' + rc.Dpi + ' ' + result) else: self.sheetoutput(rc, "ZPL File not copied", ws, LabelFileName, "", "") else: self.sheetoutput(rc, "ZPL File not created", ws, LabelFileName, "", "") else: self.sheetoutput(rc, "Label File Not Found", ws, LabelFileName, "", "") except Exception as e: print("PrintLabel.printlabel error " + str(e)) quit(-6)