コード例 #1
0
ファイル: unitTest_pUtils.py プロジェクト: GawpAzrag/pUtils
    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)
コード例 #2
0
ファイル: MTPdbSync.py プロジェクト: pablo-miselu/MTP
def unpacketize(**kwargs):

    fileNameList = os.listdir(kwargs["inDirectoryFullPath"])
    t = [item for item in fileNameList if item.split(".")[-1] == "0"]

    if len(t) != 1:
        return {"retCode": 1, "errMsg": "Unable to determine packet zero"}

    packetZeroFileName = t[0]
    packetZeroFullPath = os.path.join(kwargs["inDirectoryFullPath"], packetZeroFileName)
    tmpZipFileName = "tmpZip.zip"
    tmpZipFileFullPath = os.path.join(kwargs["outDirectoryFullPath"], tmpZipFileName)

    pUtils.createDirectory(kwargs["outDirectoryFullPath"])

    t = pUtils.pUnSlice(packetZeroFullPath, tmpZipFileFullPath)
    if t["retCode"] != 0:
        return {"retCode": 2, "errMsg": "Unable to unslice", "debug": t}

    t = pUtils.unzipFile(tmpZipFileFullPath, kwargs["outDirectoryFullPath"])
    if t != 0:
        return {"retCode": 3, "errMsg": "Unable to unzip", "debug": t}

    os.remove(tmpZipFileFullPath)

    manifestFileFullPath = os.path.join(kwargs["outDirectoryFullPath"], MANIFEST_FILE_NAME)
    t = verify(manifestFileFullPath=manifestFileFullPath)
    if t["retCode"] != 0:
        return {"retCode": 4, "errMsg": "Checksum verification failed!", "debug": t}

    return {"retCode": 0, "errMsg": None}