| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import posixpath | 7 import posixpath |
| 8 import traceback | 8 import traceback |
| 9 | 9 |
| 10 from branch_utility import BranchUtility | 10 from branch_utility import BranchUtility |
| 11 from compiled_file_system import CompiledFileSystem, SingleFile | 11 from compiled_file_system import CompiledFileSystem, SingleFile |
| 12 from extensions_paths import PUBLIC_TEMPLATES |
| 12 from file_system import FileNotFoundError | 13 from file_system import FileNotFoundError |
| 13 from third_party.json_schema_compiler.model import UnixName | 14 from third_party.json_schema_compiler.model import UnixName |
| 14 import svn_constants | 15 |
| 15 | 16 |
| 16 def _SimplifyFileName(file_name): | 17 def _SimplifyFileName(file_name): |
| 17 return (posixpath.splitext(file_name)[0] | 18 return (posixpath.splitext(file_name)[0] |
| 18 .lower() | 19 .lower() |
| 19 .replace('.', '') | 20 .replace('.', '') |
| 20 .replace('-', '') | 21 .replace('-', '') |
| 21 .replace('_', '')) | 22 .replace('_', '')) |
| 22 | 23 |
| 24 |
| 23 class PathCanonicalizer(object): | 25 class PathCanonicalizer(object): |
| 24 '''Transforms paths into their canonical forms. Since the dev server has had | 26 '''Transforms paths into their canonical forms. Since the dev server has had |
| 25 many incarnations - e.g. there didn't use to be apps/ - there may be old | 27 many incarnations - e.g. there didn't use to be apps/ - there may be old |
| 26 paths lying around the webs. We try to redirect those to where they are now. | 28 paths lying around the webs. We try to redirect those to where they are now. |
| 27 ''' | 29 ''' |
| 28 def __init__(self, compiled_fs_factory, file_system): | 30 def __init__(self, compiled_fs_factory, file_system): |
| 29 # Map of simplified API names (for typo detection) to their real paths. | 31 # Map of simplified API names (for typo detection) to their real paths. |
| 30 @SingleFile | 32 @SingleFile |
| 31 def make_public_apis(_, file_names): | 33 def make_public_apis(_, file_names): |
| 32 return dict((_SimplifyFileName(name), name) for name in file_names) | 34 return dict((_SimplifyFileName(name), name) for name in file_names) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 # check analytics and see which is more popular. | 77 # check analytics and see which is more popular. |
| 76 # - Wrong names ("apps/browserAction.html"). This really does happen, | 78 # - Wrong names ("apps/browserAction.html"). This really does happen, |
| 77 # damn it, so do the above logic but record which is the default. | 79 # damn it, so do the above logic but record which is the default. |
| 78 if path.startswith(('extensions/', 'apps/')): | 80 if path.startswith(('extensions/', 'apps/')): |
| 79 default_platform, reference_path = path.split('/', 1) | 81 default_platform, reference_path = path.split('/', 1) |
| 80 else: | 82 else: |
| 81 default_platform, reference_path = ('extensions', path) | 83 default_platform, reference_path = ('extensions', path) |
| 82 | 84 |
| 83 try: | 85 try: |
| 84 apps_public = self._public_apis.GetFromFileListing( | 86 apps_public = self._public_apis.GetFromFileListing( |
| 85 '/'.join((svn_constants.PUBLIC_TEMPLATE_PATH, 'apps'))).Get() | 87 '%s/apps' % PUBLIC_TEMPLATES).Get() |
| 86 extensions_public = self._public_apis.GetFromFileListing( | 88 extensions_public = self._public_apis.GetFromFileListing( |
| 87 '/'.join((svn_constants.PUBLIC_TEMPLATE_PATH, 'extensions'))).Get() | 89 '%s/extensions' % PUBLIC_TEMPLATES).Get() |
| 88 except FileNotFoundError: | 90 except FileNotFoundError: |
| 89 # Probably offline. | 91 # Probably offline. |
| 90 logging.warning(traceback.format_exc()) | 92 logging.warning(traceback.format_exc()) |
| 91 return ReturnType(path, False) | 93 return ReturnType(path, False) |
| 92 | 94 |
| 93 simple_reference_path = _SimplifyFileName(reference_path) | 95 simple_reference_path = _SimplifyFileName(reference_path) |
| 94 apps_path = apps_public.get(simple_reference_path) | 96 apps_path = apps_public.get(simple_reference_path) |
| 95 extensions_path = extensions_public.get(simple_reference_path) | 97 extensions_path = extensions_public.get(simple_reference_path) |
| 96 | 98 |
| 97 if apps_path is None: | 99 if apps_path is None: |
| 98 if extensions_path is None: | 100 if extensions_path is None: |
| 99 # No idea. Just return the original path. It'll probably 404. | 101 # No idea. Just return the original path. It'll probably 404. |
| 100 pass | 102 pass |
| 101 else: | 103 else: |
| 102 path = 'extensions/%s' % extensions_path | 104 path = 'extensions/%s' % extensions_path |
| 103 else: | 105 else: |
| 104 if extensions_path is None: | 106 if extensions_path is None: |
| 105 path = 'apps/%s' % apps_path | 107 path = 'apps/%s' % apps_path |
| 106 else: | 108 else: |
| 107 assert apps_path == extensions_path | 109 assert apps_path == extensions_path |
| 108 path = '%s/%s' % (default_platform, apps_path) | 110 path = '%s/%s' % (default_platform, apps_path) |
| 109 | 111 |
| 110 return ReturnType(path, False) | 112 return ReturnType(path, False) |
| OLD | NEW |