Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/common/extensions/docs/server2/example_zipper.py

Issue 26538009: Docserver: make file_system a property of Create (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: niggles Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from io import BytesIO 5 from io import BytesIO
6 from zipfile import ZipFile 6 from zipfile import ZipFile
7 7
8 class ExampleZipper(object): 8 class ExampleZipper(object):
9 '''This class creates a zip file given a samples directory. 9 '''This class creates a zip file given a samples directory.
10 ''' 10 '''
11 def __init__(self, compiled_fs_factory, file_system, base_path): 11 def __init__(self, compiled_fs_factory, file_system, base_path):
12 self._base_path = base_path.rstrip('/') 12 self._base_path = base_path.rstrip('/')
13 self._file_system = file_system 13 self._file_system = file_system
14 self._zip_cache = compiled_fs_factory.Create(self._MakeZipFile, 14 self._zip_cache = compiled_fs_factory.Create(file_system,
15 self._MakeZipFile,
15 ExampleZipper) 16 ExampleZipper)
16 17
17 def _MakeZipFile(self, base_dir, files): 18 def _MakeZipFile(self, base_dir, files):
18 if 'manifest.json' not in files: 19 if 'manifest.json' not in files:
19 return None 20 return None
20 zip_bytes = BytesIO() 21 zip_bytes = BytesIO()
21 zip_file = ZipFile(zip_bytes, mode='w') 22 zip_file = ZipFile(zip_bytes, mode='w')
22 try: 23 try:
23 for file_name in files: 24 for file_name in files:
24 file_path = '%s%s' % (base_dir, file_name) 25 file_path = '%s%s' % (base_dir, file_name)
(...skipping 11 matching lines...) Expand all
36 zip_file.close() 37 zip_file.close()
37 return zip_bytes.getvalue() 38 return zip_bytes.getvalue()
38 39
39 def Create(self, path): 40 def Create(self, path):
40 ''' Creates a new zip file from the recursive contents of |path| 41 ''' Creates a new zip file from the recursive contents of |path|
41 as returned by |_zip_cache|. 42 as returned by |_zip_cache|.
42 Paths within the zip file are given relative to and including |path|. 43 Paths within the zip file are given relative to and including |path|.
43 ''' 44 '''
44 return self._zip_cache.GetFromFileListing( 45 return self._zip_cache.GetFromFileListing(
45 '%s/%s' % (self._base_path, path.strip('/'))).Get() 46 '%s/%s' % (self._base_path, path.strip('/'))).Get()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/cron_servlet.py ('k') | chrome/common/extensions/docs/server2/example_zipper_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698