def writeLists(self): def f(s): return os.path.abspath(os.path.realpath(s)) d = dict( imagePathList1=[f(i) for i in self.imagePathList1], imagePathList2=[f(i) for i in self.imagePathList2], droppedPathList1=[f(i) for i in self.droppedList1], droppedPathList2=[f(i) for i in self.droppedList2], ) filePath = os.path.abspath(self.cm.getDumpFileName()) try: if not os.path.exists(filePath): pUtils.quickFileWrite(filePath, d, 'json') else: msgBox = QMessageBox(self) msgBox.setText('File:\n %s\nalready exists' % filePath) msgBox.setInformativeText('Do you want to overwrite it?') msgBox.setIcon(QMessageBox.Warning) msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Cancel) ret = msgBox.exec_() if ret == QMessageBox.Yes: pUtils.quickFileWrite(filePath, d, 'json') except Exception: msgBox = QMessageBox(self) msgBox.setText('Unable to write file:\n %s' % filePath) msgBox.setInformativeText( 'Please make sure you have right access and space left') msgBox.setIcon(QMessageBox.Critical) msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec_()
def test_fileOperations_1(self): testDirFullPath = tempfile.mkdtemp('','unitTest_pUtils_') self.assertEqual(os.path.exists(testDirFullPath),True) string = 'print \'Hello World!\'' pUtils.quickFileWrite(os.path.join(testDirFullPath,'hw.py'),string) data = pUtils.quickFileRead(os.path.join(testDirFullPath,'hw.py')) self.assertEqual(string,data) self.assertEqual(pUtils.getFileSha1(os.path.join(testDirFullPath,'hw.py')),'a849bee4b303051f907d64b6c461ee6c699c3e79') pUtils.pSlice(os.path.join(testDirFullPath,'hw.py'),testDirFullPath,1) self.assertEqual(len(pUtils.filterListByRegex(os.listdir(testDirFullPath),r'hw\.py\.[0-9]+')),21) os.remove(os.path.join(testDirFullPath,'hw.py')) self.assertEqual(os.path.exists(os.path.join(testDirFullPath,'hw.py')),False) pUtils.pUnSlice(os.path.join(testDirFullPath,'hw.py.0'),os.path.join(testDirFullPath,'hw.py')) self.assertEqual(os.path.exists(os.path.join(testDirFullPath,'hw.py')),True) self.assertEqual(pUtils.quickFileRead(os.path.join(testDirFullPath,'hw.py')),string) pUtils.createZipFile(testDirFullPath,['hw.py'],os.path.join(testDirFullPath,'aFile.zip')) self.assertEqual(os.path.exists(os.path.join(testDirFullPath,'aFile.zip')),True) os.remove(os.path.join(testDirFullPath,'hw.py')) self.assertEqual(os.path.exists(os.path.join(testDirFullPath,'hw.py')),False) pUtils.unzipFile(os.path.join(testDirFullPath,'aFile.zip'),testDirFullPath) self.assertEqual(os.path.exists(os.path.join(testDirFullPath,'hw.py')),True) self.assertEqual(pUtils.quickFileRead(os.path.join(testDirFullPath,'hw.py')),string) pUtils.emptyDirectory(testDirFullPath) self.assertEqual(len(os.listdir(testDirFullPath)),0) pUtils.createDirectory(os.path.join(testDirFullPath,'ttt','ttt2')) self.assertEqual(os.path.exists(os.path.join(testDirFullPath,'ttt','ttt2')),True) pUtils.removeDirectory(testDirFullPath) self.assertEqual(os.path.exists(testDirFullPath),False)
def genMenuConfigFile(self, filePath, configName, configPath): if os.path.exists(filePath): return 1 configMenuData = { 'defaultConfigName': configName, 'configFilePathDict': { configName: configPath } } pUtils.quickFileWrite(filePath, configMenuData, 'json') return 0
def dump(self, filePath): data = { 'configData': self.configData, 'metadata': { 'configStartPath': self.configStartPath, 'configMenuPath': self.configMenuPath, 'configFilePathFromMenu': self.configFilePathFromMenu, 'configFilePath': self.configFilePath } } pUtils.quickFileWrite(filePath, data, 'json')
def pprint(s, color=None, endLine=True): s = str(s) if endLine: s += '\n' if PPRINT_LOG_FILE: pUtils.quickFileWrite(PPRINT_LOG_FILE, s, 'at') if color: s = colorString(s, color) sys.stdout.write(s) sys.stdout.flush()
def createManifest(manifestFileName, inDirectoryFullPath): fileNameList = os.listdir(inDirectoryFullPath) d = {} dc = {} d["checksumDict"] = dc for fileName in fileNameList: if fileName == manifestFileName: continue fileFullPath = os.path.join(inDirectoryFullPath, fileName) t = pUtils.getFileSha1(fileFullPath) dc[fileName] = t d["meta-data"] = {} d["meta-data"]["timeStamp_utc"] = pUtils.getTimeStamp() d["meta-data"]["name"] = os.path.basename(inDirectoryFullPath) fileFullPath = os.path.join(inDirectoryFullPath, manifestFileName) pUtils.quickFileWrite(fileFullPath, json.dumps(d)) return {"retCode": 0, "errMsg": None}
def setConfigStart(self, filePath): if not os.path.exists(filePath): pprint('Error: ', color=COLOR.RED, endLine=False) pprint('File:') pprint(' ' + filePath, color=COLOR.TEAL) pprint('Does not exists.') return 1 if os.path.exists(self.configStartPath): pprint('Warning: ', color=COLOR.RED, endLine=False) pprint('File:') pprint(' ' + self.configStartPath, color=COLOR.TEAL) pprint('Will be overwritten.') promptString = 'Proceed (y/n)? ' if input(promptString) != 'y': pprint('Aborted action') return 2 pUtils.quickFileWrite(self.configStartPath, os.path.abspath(os.path.realpath(filePath))) pprint('DONE', color=COLOR.TEAL) return 0
def saveFullConfig(self, filePath): if os.path.exists(filePath): return 1 defaultSettingFuncList = [ 'getPropDx', 'getPropHollowColor', 'getLoadingIndicatorDirection', 'getDumpFileName', 'getPropFillColor', 'getLoadingIndicatorClass', 'getPropShape', 'getNullColor', 'getDeltaImageColorDict', 'getPropDy', 'getMarkerColor', 'getLoadingIndicatorRefreshRate', ] for funcName in defaultSettingFuncList: func = getattr(self, funcName) func() pUtils.quickFileWrite(filePath, self.configData, 'json') return 0
def save(self, filePath): header = str.encode('rgba8888 ' + str(self.width) + ' ' + str(self.height) + chr(0x0A)) pUtils.quickFileWrite(filePath, header + self.data, 'wb')
def writeTestRunDataFiles(self): """ | Writes all the test run data to drive. Args: None Returns: None """ path = os.path.join(self.testRunFolder,'db') pUtils.quickFileWrite(os.path.join(path,'TestRun.csv'), ','.join([str(item) for item in self.testRunSummary])) pUtils.quickFileWrite(os.path.join(path,'TestMeasurement.csv'), '\n'.join([','.join([str(item) for item in entry]) for entry in self.testMeasurementList])) pUtils.quickFileWrite(os.path.join(path,'StringDictionary.json'), json.dumps(self.stringDictionary)) pUtils.quickFileWrite(os.path.join(path,'DoubleDictionary.json'), json.dumps(self.numericDictionary)) pUtils.quickFileWrite(os.path.join(path,'FileDictionary.json'), json.dumps(self.fileDictionary)) pUtils.quickFileWrite(os.path.join(path,'DependencyDictionary.json'), json.dumps(self.dependencyDict))
self.cycleTestResult = False self.allTestResult = False self.isException = True s = ( '\n*** From the main "try" ***'+ '\nSequencer, (j,i)='+str(self.j)+','+str(self.i)+ '\nlastTestEntered='+self.lastTestEntered+ '\nexceptionMessage='+e.message+ '\ntraceback='+ traceback.format_exc()+ '\n*******************************' ) self.logAll(s,1) print ss pUtils.quickFileWrite(self.crashLogFullPath,ss,'at') finally: self.stringDictionary = {} self.numericDictionary = {} self.filePointerDictionary = {} ### End all threads from Communicator instances ### for commName,comm in self.commDict.iteritems(): if commName=='default': continue print 'Signaling END to Communicator:'+commName comm.signalEndPollingThread() for commName,comm in self.commDict.iteritems(): if commName=='default': continue