Browse Source

add rarfile support... should probably make this more modular

so that if rarfile isn't installed, it isn't an issue..

[git-p4: depot-paths = "//depot/": change = 1133]
replace/b43bf02ddeddd088c0e6b94974ca1a46562eb3db
John-Mark Gurney 17 years ago
parent
commit
0a4949deaa
2 changed files with 14 additions and 34 deletions
  1. +10
    -5
      ZipStorage.py
  2. +4
    -29
      iterrarfile.py

+ 10
- 5
ZipStorage.py View File

@@ -12,6 +12,8 @@ import iterzipfile
zipfile = iterzipfile zipfile = iterzipfile
import itertarfile import itertarfile
tarfile = itertarfile tarfile = itertarfile
import iterrarfile
rarfile = iterrarfile


import FileDIDL import FileDIDL
from DIDLLite import StorageFolder, Item, VideoItem, AudioItem, TextItem, ImageItem, Resource from DIDLLite import StorageFolder, Item, VideoItem, AudioItem, TextItem, ImageItem, Resource
@@ -227,16 +229,19 @@ def canHandle(path):
if zipfile.is_zipfile(path): if zipfile.is_zipfile(path):
return True return True


print 'rar:', rarfile.is_rarfile(path)
if rarfile.is_rarfile(path):
return True

#tar is cheaper on __init__ than zipfile #tar is cheaper on __init__ than zipfile
return tryTar(path) return tryTar(path)


def genZipFile(path): def genZipFile(path):
try:
if zipfile.is_zipfile(path):
return zipfile.ZipFile(path) return zipfile.ZipFile(path)
except:
#import traceback
#traceback.print_exc(file=log.logfile)
pass

if rarfile.is_rarfile(path):
return rarfile.RarFile(path)


try: try:
return tryTar(path) return tryTar(path)


+ 4
- 29
iterrarfile.py View File

@@ -4,34 +4,9 @@
__version__ = '$Change$' __version__ = '$Change$'
# $Id$ # $Id$


import tarfile
from tarfile import *

TAR_PLAIN = tarfile.TAR_PLAIN
TAR_GZIPPED = tarfile.TAR_GZIPPED
TAR_BZ2 = 'bz2'

__all__ = tarfile.__all__

class TarFileCompat(tarfile.TarFileCompat):
def __init__(self, file, mode="r", compression=TAR_PLAIN):
if compression != TAR_BZ2:
tarfile.TarFileCompat.__init__(self, file, mode, compression)
return

self.tarfile = TarFile.bz2open(file, mode)
if mode[0:1] == "r":
members = self.tarfile.getmembers()
for i in xrange(len(members)):
m = members[i]
m.filename = m.name
m.file_size = m.size
m.date_time = time.gmtime(m.mtime)[:6]
import rarfile
from rarfile import *


class RarFile(rarfile.RarFile):
def readiter(self, name, blksize=16384): def readiter(self, name, blksize=16384):
f = self.tarfile.extractfile(self.tarfile.getmember(name))
while True:
data = f.read(blksize)
if data == '':
break
yield data
yield self.read(name)

Loading…
Cancel
Save