expand jars and xpi's but don't want to recurse forever (bug #651796)

This commit is contained in:
Andy McKay 2011-04-21 11:27:32 -07:00
Родитель a45d5239d1
Коммит 52a53069b0
3 изменённых файлов: 18 добавлений и 11 удалений

Двоичные данные
apps/files/fixtures/files/recurse.xpi

Двоичный файл не отображается.

Просмотреть файл

@ -50,10 +50,11 @@ class TestFileHelper(test_utils.TestCase):
self.viewer.src = recurse
self.viewer.extract()
files = self.viewer.get_files()
for name in ['chrome/test-root.txt', 'chrome/test.jar',
'chrome/test.jar/test/test.text']:
nm = ['recurse/recurse.xpi/chrome/test-root.txt',
'recurse/somejar.jar/recurse/recurse.xpi/chrome/test.jar',
'recurse/somejar.jar/recurse/recurse.xpi/chrome/test.jar/test']
for name in nm:
eq_(name in files, True, 'File %r not extracted' % name)
eq_(files['chrome/test.jar/test']['directory'], True)
def test_cleanup(self):
self.viewer.extract()

Просмотреть файл

@ -164,22 +164,28 @@ def extract_xpi(xpi, path, expand=False):
"""
If expand is given, will look inside the expanded file
and find anything in the whitelist and try and expand it as well.
Currently only does one iteration of this.
It will do up to 10 iterations, after that you are on your own.
It will replace the expanded file with a directory and the expanded
contents. If you have 'foo.jar', that contains 'some-image.jpg', then
it will create a folder, foo.jar, with an image inside.
"""
expand_whitelist = ['.jar']
expand_whitelist = ['.jar', '.xpi']
tempdir = extract_zip(xpi)
if expand:
for root, dirs, files in os.walk(tempdir):
for name in files:
if os.path.splitext(name)[1] in expand_whitelist:
src = os.path.join(root, name)
dest = extract_zip(src, remove=True)
copy_over(dest, src)
for x in xrange(0, 10):
flag = False
for root, dirs, files in os.walk(tempdir):
for name in files:
if os.path.splitext(name)[1] in expand_whitelist:
src = os.path.join(root, name)
if not os.path.isdir(src):
dest = extract_zip(src, remove=True)
copy_over(dest, src)
flag = True
if not flag:
break
copy_over(tempdir, path)