Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import logging | |
| 6 import os | |
| 7 from third_party.json_schema_compiler.model import UnixName | |
| 8 import svn_constants | |
| 9 | |
| 10 class PathCanonicalizer(object): | |
| 11 '''Transforms paths into their canonical forms. Since the dev server has had | |
| 12 many incarnations - e.g. there didn't use to be apps/ - there may be old | |
| 13 paths lying around the webs. We try to redirect those to where they are now. | |
| 14 ''' | |
| 15 def __init__(self, channel, compiled_fs_factory): | |
| 16 self._channel = channel | |
| 17 self._identity_fs = compiled_fs_factory.GetOrCreateIdentity() | |
| 18 | |
| 19 def Canonicalize(self, path): | |
| 20 if any(path.startswith(prefix) | |
| 21 for prefix in ('extensions/', 'apps/', 'static/')): | |
| 22 return path | |
| 23 | |
| 24 if '/' in path or path == '404.html': | |
| 25 return path | |
| 26 | |
| 27 public_template_path = svn_constants.PUBLIC_TEMPLATE_PATH | |
| 28 apps_templates = self._identity_fs.GetFromFileListing( | |
| 29 '/'.join((public_template_path, 'apps'))) | |
|
cduvall
2013/04/08 07:09:24
extra parens?
not at google - send to devlin
2013/04/08 12:21:21
Yeah, python (well, string.join) being annoying. N
| |
| 30 extensions_templates = self._identity_fs.GetFromFileListing( | |
| 31 '/'.join((public_template_path, 'extensions'))) | |
|
cduvall
2013/04/08 07:09:24
same
not at google - send to devlin
2013/04/08 12:21:21
Likewise.
| |
| 32 | |
| 33 if self._channel is None: | |
| 34 apps_path = '/apps/%s' % path | |
| 35 extensions_path = '/extensions/%s' % path | |
| 36 else: | |
| 37 apps_path = '/%s/apps/%s' % (self._channel, path) | |
| 38 extensions_path = '/%s/extensions/%s' % (self._channel, path) | |
| 39 | |
| 40 unix_path = UnixName(os.path.splitext(path)[0]) | |
| 41 if unix_path in extensions_templates: | |
|
cduvall
2013/04/08 07:09:24
should these be checking '%s.html' % unix_path ? O
not at google - send to devlin
2013/04/08 12:21:21
It has an os.path.splitext which strips the html -
| |
| 42 return extensions_path | |
| 43 if unix_path in apps_templates: | |
| 44 return app_path | |
| 45 return extensions_path | |
| OLD | NEW |