Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/path_canonicalizer.py |
| diff --git a/chrome/common/extensions/docs/server2/path_canonicalizer.py b/chrome/common/extensions/docs/server2/path_canonicalizer.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2e17d8c61df01b78ef7f5f3dc8e6086c2a41f918 |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/path_canonicalizer.py |
| @@ -0,0 +1,45 @@ |
| +# Copyright 2013 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 third_party.json_schema_compiler.model import UnixName |
| +import svn_constants |
| + |
| +class PathCanonicalizer(object): |
| + '''Transforms paths into their canonical forms. Since the dev server has had |
| + many incarnations - e.g. there didn't use to be apps/ - there may be old |
| + paths lying around the webs. We try to redirect those to where they are now. |
| + ''' |
| + def __init__(self, channel, compiled_fs_factory): |
| + self._channel = channel |
| + self._identity_fs = compiled_fs_factory.GetOrCreateIdentity() |
| + |
| + def Canonicalize(self, path): |
| + if any(path.startswith(prefix) |
| + for prefix in ('extensions/', 'apps/', 'static/')): |
| + return path |
| + |
| + if '/' in path or path == '404.html': |
| + return path |
| + |
| + public_template_path = svn_constants.PUBLIC_TEMPLATE_PATH |
| + apps_templates = self._identity_fs.GetFromFileListing( |
| + '/'.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
|
| + extensions_templates = self._identity_fs.GetFromFileListing( |
| + '/'.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.
|
| + |
| + if self._channel is None: |
| + apps_path = '/apps/%s' % path |
| + extensions_path = '/extensions/%s' % path |
| + else: |
| + apps_path = '/%s/apps/%s' % (self._channel, path) |
| + extensions_path = '/%s/extensions/%s' % (self._channel, path) |
| + |
| + unix_path = UnixName(os.path.splitext(path)[0]) |
| + 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 -
|
| + return extensions_path |
| + if unix_path in apps_templates: |
| + return app_path |
| + return extensions_path |