OLD | NEW |
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 import hashlib | 5 import hashlib |
6 import json | 6 import json |
7 import logging | 7 import logging |
8 import re | 8 import re |
9 | 9 |
10 from compiled_file_system import CompiledFileSystem | 10 from compiled_file_system import CompiledFileSystem |
(...skipping 11 matching lines...) Expand all Loading... |
22 """A factory to create SamplesDataSource instances bound to individual | 22 """A factory to create SamplesDataSource instances bound to individual |
23 Requests. | 23 Requests. |
24 """ | 24 """ |
25 def __init__(self, | 25 def __init__(self, |
26 channel, | 26 channel, |
27 extensions_file_system, | 27 extensions_file_system, |
28 apps_file_system, | 28 apps_file_system, |
29 ref_resolver_factory, | 29 ref_resolver_factory, |
30 object_store_creator_factory, | 30 object_store_creator_factory, |
31 extension_samples_path): | 31 extension_samples_path): |
32 self._svn_file_system = extensions_file_system | 32 self._extensions_file_system = extensions_file_system |
33 self._github_file_system = apps_file_system | 33 self._github_file_system = apps_file_system |
34 self._static_path = '/%s/static' % channel | 34 self._static_path = '/%s/static' % channel |
35 self._ref_resolver = ref_resolver_factory.Create() | 35 self._ref_resolver = ref_resolver_factory.Create() |
36 self._extension_samples_path = extension_samples_path | 36 self._extension_samples_path = extension_samples_path |
37 def create_compiled_fs(fs, fn, category): | 37 def create_compiled_fs(fs, fn, category): |
38 return CompiledFileSystem.Factory( | 38 return CompiledFileSystem.Factory( |
39 fs, | 39 fs, |
40 object_store_creator_factory).Create(fn, | 40 object_store_creator_factory).Create(fn, |
41 SamplesDataSource, | 41 SamplesDataSource, |
42 category=category) | 42 category=category) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 else: | 97 else: |
98 for path, json_ in locales_json: | 98 for path, json_ in locales_json: |
99 l10n_data['locales'][path[len(locales_path):].split('/')[0]] = json_ | 99 l10n_data['locales'][path[len(locales_path):].split('/')[0]] = json_ |
100 return l10n_data | 100 return l10n_data |
101 | 101 |
102 def _MakeSamplesList(self, base_dir, files, is_apps=False): | 102 def _MakeSamplesList(self, base_dir, files, is_apps=False): |
103 # HACK(kalman): The code here (for legacy reasons) assumes that |files| is | 103 # HACK(kalman): The code here (for legacy reasons) assumes that |files| is |
104 # prefixed by |base_dir|, so make it true. | 104 # prefixed by |base_dir|, so make it true. |
105 files = ['%s%s' % (base_dir, f) for f in files] | 105 files = ['%s%s' % (base_dir, f) for f in files] |
106 file_system = (self._github_file_system if is_apps else | 106 file_system = (self._github_file_system if is_apps else |
107 self._svn_file_system) | 107 self._extensions_file_system) |
108 samples_list = [] | 108 samples_list = [] |
109 for filename in sorted(files): | 109 for filename in sorted(files): |
110 if filename.rsplit('/')[-1] != 'manifest.json': | 110 if filename.rsplit('/')[-1] != 'manifest.json': |
111 continue | 111 continue |
112 # This is a little hacky, but it makes a sample page. | 112 # This is a little hacky, but it makes a sample page. |
113 sample_path = filename.rsplit('/', 1)[-2] | 113 sample_path = filename.rsplit('/', 1)[-2] |
114 sample_files = [path for path in files | 114 sample_files = [path for path in files |
115 if path.startswith(sample_path + '/')] | 115 if path.startswith(sample_path + '/')] |
116 js_files = [path for path in sample_files if path.endswith('.js')] | 116 js_files = [path for path in sample_files if path.endswith('.js')] |
117 try: | 117 try: |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 return_list.append(sample_data) | 249 return_list.append(sample_data) |
250 else: | 250 else: |
251 return_list.append(dict_) | 251 return_list.append(dict_) |
252 return return_list | 252 return return_list |
253 | 253 |
254 def get(self, key): | 254 def get(self, key): |
255 return { | 255 return { |
256 'apps': lambda: self._CreateSamplesDict('apps'), | 256 'apps': lambda: self._CreateSamplesDict('apps'), |
257 'extensions': lambda: self._CreateSamplesDict('extensions') | 257 'extensions': lambda: self._CreateSamplesDict('extensions') |
258 }.get(key, lambda: {})() | 258 }.get(key, lambda: {})() |
OLD | NEW |