| Index: chrome/common/extensions/docs/server2/example_zipper.py
|
| diff --git a/chrome/common/extensions/docs/server2/example_zipper.py b/chrome/common/extensions/docs/server2/example_zipper.py
|
| index 84dcbe52f18397805143ecd222ceae831fbb44e8..a7e94c1cb06e8f3adfd23518765a21e61bcb28a1 100644
|
| --- a/chrome/common/extensions/docs/server2/example_zipper.py
|
| +++ b/chrome/common/extensions/docs/server2/example_zipper.py
|
| @@ -9,26 +9,33 @@ from zipfile import ZipFile
|
|
|
| import compiled_file_system as compiled_fs
|
|
|
| +# Increment this if the data model changes for ExampleZipper.
|
| +_VERSION = 1
|
| +
|
| class ExampleZipper(object):
|
| """This class creates a zip file given a samples directory.
|
| """
|
| - def __init__(self, file_system, cache_factory, base_path):
|
| - self._base_path = base_path
|
| - self._zip_cache = cache_factory.Create(self._MakeZipFile,
|
| - compiled_fs.ZIP)
|
| + def __init__(self, file_system, compiled_fs_factory, base_path):
|
| + self._base_path = base_path.rstrip('/')
|
| + self._zip_cache = compiled_fs_factory.Create(self._MakeZipFile,
|
| + ExampleZipper,
|
| + version=_VERSION)
|
| self._file_system = file_system
|
|
|
| def _MakeZipFile(self, base_dir, files):
|
| - zip_path = os.path.commonprefix(files).rsplit('/', 1)[-2]
|
| - prefix = zip_path.rsplit('/', 1)[-2]
|
| - if zip_path + '/manifest.json' not in files:
|
| + if 'manifest.json' not in files:
|
| return None
|
| zip_bytes = BytesIO()
|
| zip_file = ZipFile(zip_bytes, mode='w')
|
| try:
|
| for name, file_contents in (
|
| - self._file_system.Read(files, binary=True).Get().iteritems()):
|
| - zip_file.writestr(name[len(prefix):].strip('/'), file_contents)
|
| + self._file_system.Read(['%s%s' % (base_dir, f) for f in files],
|
| + binary=True).Get().iteritems()):
|
| + # We want e.g. basic.zip to expand to basic/manifest.json etc, not
|
| + # chrome/common/extensions/.../basic/manifest.json, so only use the
|
| + # end of the path component when writing into the zip file.
|
| + redundant_prefix = '%s/' % base_dir.rstrip('/').rsplit('/', 1)[0]
|
| + zip_file.writestr(name[len(redundant_prefix):], file_contents)
|
| finally:
|
| zip_file.close()
|
| return zip_bytes.getvalue()
|
| @@ -39,4 +46,4 @@ class ExampleZipper(object):
|
| Paths within the zip file are given relative to and including |path|.
|
| """
|
| return self._zip_cache.GetFromFileListing(
|
| - self._base_path + '/' + path)
|
| + '%s/%s' % (self._base_path, path.strip('/')))
|
|
|