Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
def packetize(**kwargs):

    tmpZipFileName = "tmpZip.zip"
    tmpZipFileFullPath = os.path.join(kwargs["outDirectoryFullPath"], tmpZipFileName)

    pUtils.createDirectory(kwargs["outDirectoryFullPath"])

    fileNameList = os.listdir(kwargs["inDirectoryFullPath"])
    pUtils.createZipFile(kwargs["inDirectoryFullPath"], fileNameList, tmpZipFileFullPath)

    t = pUtils.pSlice(tmpZipFileFullPath, kwargs["outDirectoryFullPath"], kwargs["sliceSize"])
    if t["retCode"] != 0:
        return {"retCode": 1, "errMsg": "Unable to slice file", "debug": t}

    os.remove(tmpZipFileFullPath)

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