def test_unzipping(self): self.makeZipFiles() zipstream.unzip('littlefiles.zip') self.failUnless(os.path.isfile('zipstreamdir/937')) self.cleanupUnzippedJunk() uziter=zipstream.unzipIter('littlefiles.zip') r=uziter.next() self.assertEqual(r, 999) for r in uziter: pass self.assertEqual(r, 0) # test that files don't get overwritten unless you tell it to # do so # overwrite zipstreamjunk with some different contents stuff('zipstreamjunk', 'stuff') zipstream.unzip('bigfile.zip') newmd5=newsum('zipstreamjunk') self.assertEqual(newmd5, 'c13d88cb4cb02003daedb8a84e5d272a') zipstream.unzip('bigfile.zip', overwrite=1) newmd5=newsum('zipstreamjunk') self.assertEqual(newmd5, junkmd5) self.cleanupUnzippedJunk() uziter=zipstream.unzipIterChunky('bigfile.zip', chunksize=500) r=uziter.next() # test that the number of chunks is in the right ballpark; # this could theoretically be any number but statistically it # should always be in this range approx = 35<r<45 self.failUnless(approx) for r in uziter: pass self.assertEqual(r, 0) newmd5=newsum('zipstreamjunk') self.assertEqual(newmd5, junkmd5) self.cleanupUnzippedJunk() uziter=zipstream.unzipIterChunky('bigfile_deflated.zip', chunksize=972) r=uziter.next() approx = 23<r<27 self.failUnless(approx) for r in uziter: pass self.assertEqual(r, 0) newmd5=newsum('zipstreamjunk') self.assertEqual(newmd5, junkmd5)
def _unzipIterChunkyTest(self, compression, chunksize, lower, upper): """ unzipIterChunky should unzip the given number of bytes per iteration. """ junk = ' '.join([str(random.random()) for n in xrange(1000)]) junkmd5 = md5(junk).hexdigest() tempdir = filepath.FilePath(self.mktemp()) tempdir.makedirs() zfpath = tempdir.child('bigfile.zip').path self._makebigfile(zfpath, compression, junk) uziter = zipstream.unzipIterChunky(zfpath, tempdir.path, chunksize=chunksize) r = uziter.next() # test that the number of chunks is in the right ballpark; # this could theoretically be any number but statistically it # should always be in this range approx = lower < r < upper self.failUnless(approx) for r in uziter: pass self.assertEqual(r, 0) newmd5 = md5(tempdir.child("zipstreamjunk").open().read()).hexdigest() self.assertEqual(newmd5, junkmd5)
def _unzipIterChunkyTest(self, compression, chunksize, lower, upper): """ unzipIterChunky should unzip the given number of bytes per iteration. """ junk = ' '.join([str(random.random()) for n in xrange(1000)]) junkmd5 = md5(junk).hexdigest() tempdir = filepath.FilePath(self.mktemp()) tempdir.makedirs() zfpath = tempdir.child('bigfile.zip').path self._makebigfile(zfpath, compression, junk) uziter = zipstream.unzipIterChunky(zfpath, tempdir.path, chunksize=chunksize) r = uziter.next() # test that the number of chunks is in the right ballpark; # this could theoretically be any number but statistically it # should always be in this range approx = lower < r < upper self.failUnless(approx) for r in uziter: pass self.assertEqual(r, 0) newmd5 = md5( tempdir.child("zipstreamjunk").open().read()).hexdigest() self.assertEqual(newmd5, junkmd5)
def _unzipIterChunkyTest(self, compression, chunksize, lower, upper): """ unzipIterChunky should unzip the given number of bytes per iteration. """ junk = b"" for n in range(1000): num = round(random.random(), 12) numEncoded = str(num).encode("ascii") junk += b" " + numEncoded junkmd5 = md5(junk).hexdigest() tempdir = filepath.FilePath(self.mktemp()) tempdir.makedirs() zfpath = tempdir.child("bigfile.zip").path self._makebigfile(zfpath, compression, junk) uziter = zipstream.unzipIterChunky(zfpath, tempdir.path, chunksize=chunksize) r = next(uziter) # test that the number of chunks is in the right ballpark; # this could theoretically be any number but statistically it # should always be in this range approx = lower < r < upper self.assertTrue(approx) for r in uziter: pass self.assertEqual(r, 0) with tempdir.child("zipstreamjunk").open() as f: newmd5 = md5(f.read()).hexdigest() self.assertEqual(newmd5, junkmd5)
def _unzipIterChunkyTest(self, compression, chunksize, lower, upper): """ unzipIterChunky should unzip the given number of bytes per iteration. """ junk = b'' for n in range(1000): num = round(random.random(), 12) numEncoded = str(num).encode("ascii") junk += b' '+numEncoded junkmd5 = md5(junk).hexdigest() tempdir = filepath.FilePath(self.mktemp()) tempdir.makedirs() zfpath = tempdir.child('bigfile.zip').path self._makebigfile(zfpath, compression, junk) uziter = zipstream.unzipIterChunky(zfpath, tempdir.path, chunksize=chunksize) r = next(uziter) # test that the number of chunks is in the right ballpark; # this could theoretically be any number but statistically it # should always be in this range approx = lower < r < upper self.assertTrue(approx) for r in uziter: pass self.assertEqual(r, 0) with tempdir.child("zipstreamjunk").open() as f: newmd5 = md5(f.read()).hexdigest() self.assertEqual(newmd5, junkmd5)
def test_unzipIterChunky(self): """ L{twisted.python.zipstream.unzipIterChunky} returns an iterator which must be exhausted to completely unzip the input archive. """ numfiles = 10 contents = ["This is test file %d!" % i for i in range(numfiles)] zpfilename = self.makeZipFile(contents) list(zipstream.unzipIterChunky(zpfilename, self.unzipdir.path)) self.assertEqual(set(self.unzipdir.listdir()), set(map(str, range(numfiles)))) for child in self.unzipdir.children(): num = int(child.basename()) self.assertEqual(child.getContent(), contents[num])
def test_unzipIterChunky(self): """ L{twisted.python.zipstream.unzipIterChunky} returns an iterator which must be exhausted to completely unzip the input archive. """ numfiles = 10 contents = ['This is test file %d!' % i for i in range(numfiles)] zpfilename = self.makeZipFile(contents) list(zipstream.unzipIterChunky(zpfilename, self.unzipdir.path)) self.assertEqual(set(self.unzipdir.listdir()), set(map(str, range(numfiles)))) for child in self.unzipdir.children(): num = int(child.basename()) self.assertEqual(child.getContent(), contents[num])
def test_unzipIterChunkyDirectory(self): """ The path to which a file is extracted by L{zipstream.unzipIterChunky} is determined by joining the C{directory} argument to C{unzip} with the path within the archive of the file being extracted. """ numfiles = 10 contents = ["This is test file %d!" % i for i in range(numfiles)] zpfilename = self.makeZipFile(contents, "foo") list(zipstream.unzipIterChunky(zpfilename, self.unzipdir.path)) self.assertEqual(set(self.unzipdir.child("foo").listdir()), set(map(str, range(numfiles)))) for child in self.unzipdir.child("foo").children(): num = int(child.basename()) self.assertEqual(child.getContent(), contents[num])
def test_unzipping(self): self.makeZipFiles() zipstream.unzip('littlefiles.zip') self.failUnless(os.path.isfile('zipstreamdir/937')) self.cleanupUnzippedJunk() uziter=zipstream.unzipIter('littlefiles.zip') r=uziter.next() self.assertEqual(r, 999) for r in uziter: pass self.assertEqual(r, 0) stuff('zipstreamjunk', 'stuff') zipstream.unzip('bigfile.zip') newmd5=newsum('zipstreamjunk') self.assertEqual(newmd5, 'c13d88cb4cb02003daedb8a84e5d272a') zipstream.unzip('bigfile.zip', overwrite=1) newmd5=newsum('zipstreamjunk') self.assertEqual(newmd5, junkmd5) self.cleanupUnzippedJunk() uziter=zipstream.unzipIterChunky('bigfile.zip', chunksize=500) r=uziter.next() approx = 35<r<45 self.failUnless(approx) for r in uziter: pass self.assertEqual(r, 0) newmd5=newsum('zipstreamjunk') self.assertEqual(newmd5, junkmd5) self.cleanupUnzippedJunk() uziter=zipstream.unzipIterChunky('bigfile_deflated.zip', chunksize=972) r=uziter.next() approx = 23<r<27 self.failUnless(approx) for r in uziter: pass self.assertEqual(r, 0) newmd5=newsum('zipstreamjunk') self.assertEqual(newmd5, junkmd5)
def test_unzipIterChunkyDirectory(self): """ The path to which a file is extracted by L{zipstream.unzipIterChunky} is determined by joining the C{directory} argument to C{unzip} with the path within the archive of the file being extracted. """ numfiles = 10 contents = ['This is test file %d!' % i for i in range(numfiles)] zpfilename = self.makeZipFile(contents, 'foo') list(zipstream.unzipIterChunky(zpfilename, self.unzipdir.path)) self.assertEqual(set(self.unzipdir.child('foo').listdir()), set(map(str, range(numfiles)))) for child in self.unzipdir.child('foo').children(): num = int(child.basename()) self.assertEqual(child.getContent(), contents[num])
def test_unzipIterChunkyDirectory(self): """ The path to which a file is extracted by L{zipstream.unzipIterChunky} is determined by joining the C{directory} argument to C{unzip} with the path within the archive of the file being extracted. """ numfiles = 10 contents = ["This is test file %d!" % i for i in range(numfiles)] contents = [i.encode("ascii") for i in contents] zpfilename = self.makeZipFile(contents, "foo") list(zipstream.unzipIterChunky(zpfilename, self.unzipdir.path)) fileContents = {str(num).encode("ascii") for num in range(numfiles)} self.assertEqual(set(self.unzipdir.child(b"foo").listdir()), fileContents) for child in self.unzipdir.child(b"foo").children(): num = int(child.basename()) self.assertEqual(child.getContent(), contents[num])
def test_unzipIterChunkyDirectory(self): """ The path to which a file is extracted by L{zipstream.unzipIterChunky} is determined by joining the C{directory} argument to C{unzip} with the path within the archive of the file being extracted. """ numfiles = 10 contents = ['This is test file %d!' % i for i in range(numfiles)] contents = [i.encode("ascii") for i in contents] zpfilename = self.makeZipFile(contents, 'foo') list(zipstream.unzipIterChunky(zpfilename, self.unzipdir.path)) fileContents = {str(num).encode("ascii") for num in range(numfiles)} self.assertEqual( set(self.unzipdir.child(b'foo').listdir()), fileContents) for child in self.unzipdir.child(b'foo').children(): num = int(child.basename()) self.assertEqual(child.getContent(), contents[num])
def doItTkinterly(opt): root = Tkinter.Tk() root.withdraw() root.title('One Moment.') root.protocol('WM_DELETE_WINDOW', reactor.stop) tksupport.install(root) prog = ProgressBar(root, value=0, labelColor="black", width=200) prog.pack() # callback immediately d = defer.succeed(root).addErrback(log.err) def deiconify(root): root.deiconify() return root d.addCallback(deiconify) if opt['zipfile']: uz = Progressor('Unpacking documentation...') max = zipstream.countZipFileChunks(opt['zipfile'], 4096) uz.setBar(prog, max) uz.setIterator( zipstream.unzipIterChunky(opt['zipfile'], opt['ziptargetdir'])) d.addCallback(uz.processAll) if opt['compiledir']: comp = Progressor('Compiling to pyc...') comp.setBar(prog, countPysRecursive(opt['compiledir'])) comp.setIterator(compiler(opt['compiledir'])) d.addCallback(comp.processAll) def stop(ignore): reactor.stop() root.destroy() d.addCallback(stop) reactor.run()
def doItTkinterly(opt): root=Tkinter.Tk() root.withdraw() root.title('One Moment.') root.protocol('WM_DELETE_WINDOW', reactor.stop) tksupport.install(root) prog=ProgressBar(root, value=0, labelColor="black", width=200) prog.pack() # callback immediately d=defer.succeed(root).addErrback(log.err) def deiconify(root): root.deiconify() return root d.addCallback(deiconify) if opt['zipfile']: uz=Progressor('Unpacking documentation...') max=zipstream.countZipFileChunks(opt['zipfile'], 4096) uz.setBar(prog, max) uz.setIterator(zipstream.unzipIterChunky(opt['zipfile'], opt['ziptargetdir'])) d.addCallback(uz.processAll) if opt['compiledir']: comp=Progressor('Compiling to pyc...') comp.setBar(prog, countPysRecursive(opt['compiledir'])) comp.setIterator(compiler(opt['compiledir'])) d.addCallback(comp.processAll) def stop(ignore): reactor.stop() root.destroy() d.addCallback(stop) reactor.run()