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

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

Issue 13470005: Refactor the devserver to make it easier to control caching (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cache static files in cron, fix path canonicalizer bug Created 7 years, 8 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/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

Powered by Google App Engine
This is Rietveld 408576698