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

Unified Diff: chrome/common/extensions/docs/server2/zip_data_source.py

Issue 10689144: Extensions Docs Server: Samples zip files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/zip_data_source.py
diff --git a/chrome/common/extensions/docs/server2/zip_data_source.py b/chrome/common/extensions/docs/server2/zip_data_source.py
new file mode 100644
index 0000000000000000000000000000000000000000..3b93953ba1076ee24562d39165aa643c307e33d0
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/zip_data_source.py
@@ -0,0 +1,43 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+import os
+from io import BytesIO
+from zipfile import ZipFile
+
+from subversion_data_source import SubversionDataSource
+
+class ZipDataSource(SubversionDataSource):
not at google - send to devlin 2012/07/11 00:35:09 Why does this need to expose a data source interfa
cduvall 2012/07/11 20:56:30 Done.
+ """This class creates a zip file given a samples directory.
+ """
+ def __init__(self, cache_builder, base_path, ignore_path):
+ super(ZipDataSource, self).__init__(cache_builder, base_path, ignore_path)
+ self._zip_cache = cache_builder.build(self._MakeZipFile)
+
+ def _MakeZipFile(self, directory):
+ file_list = self._ListFilesInDirectory(directory, True)
+ common_prefix = os.path.commonprefix(file_list)
+ prefix = common_prefix.rsplit('/', 2)[0]
+ zip_bytes = BytesIO()
+ zip_file = ZipFile(zip_bytes, mode='w')
+ for filename in file_list:
+ try:
+ zip_file.writestr(
+ filename.replace(prefix, ''),
+ self._file_cache.get(self._base_path + '/' + filename))
+ except Exception as e:
+ logging.info(e)
+ zip_file.close()
+ return zip_bytes.getvalue()
+
+ def __getitem__(self, key):
+ return self.get(key)
+
+ def get(self, key):
+ base, ext = os.path.splitext(key)
+ try:
+ return self._zip_cache.get(self._base_path + '/' + base)
+ except:
+ return None

Powered by Google App Engine
This is Rietveld 408576698