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

Side by Side Diff: chrome/common/extensions/docs/server2/path_canonicalizer.py

Issue 26538009: Docserver: make file_system a property of Create (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: niggles Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 file_system import FileNotFoundError 11 from file_system import FileNotFoundError
12 from third_party.json_schema_compiler.model import UnixName 12 from third_party.json_schema_compiler.model import UnixName
13 import svn_constants 13 import svn_constants
14 14
15 def _SimplifyFileName(file_name): 15 def _SimplifyFileName(file_name):
16 return (posixpath.splitext(file_name)[0] 16 return (posixpath.splitext(file_name)[0]
17 .lower() 17 .lower()
18 .replace('.', '') 18 .replace('.', '')
19 .replace('-', '') 19 .replace('-', '')
20 .replace('_', '')) 20 .replace('_', ''))
21 21
22 class PathCanonicalizer(object): 22 class PathCanonicalizer(object):
23 '''Transforms paths into their canonical forms. Since the dev server has had 23 '''Transforms paths into their canonical forms. Since the dev server has had
24 many incarnations - e.g. there didn't use to be apps/ - there may be old 24 many incarnations - e.g. there didn't use to be apps/ - there may be old
25 paths lying around the webs. We try to redirect those to where they are now. 25 paths lying around the webs. We try to redirect those to where they are now.
26 ''' 26 '''
27 def __init__(self, compiled_fs_factory): 27 def __init__(self, compiled_fs_factory, file_system):
28 # Map of simplified API names (for typo detection) to their real paths. 28 # Map of simplified API names (for typo detection) to their real paths.
29 def make_public_apis(_, file_names): 29 def make_public_apis(_, file_names):
30 return dict((_SimplifyFileName(name), name) for name in file_names) 30 return dict((_SimplifyFileName(name), name) for name in file_names)
31 self._public_apis = compiled_fs_factory.Create(make_public_apis, 31 self._public_apis = compiled_fs_factory.Create(file_system,
32 make_public_apis,
32 PathCanonicalizer) 33 PathCanonicalizer)
33 34
34 def Canonicalize(self, path): 35 def Canonicalize(self, path):
35 '''Returns the canonical path for |path|, and whether that path is a 36 '''Returns the canonical path for |path|, and whether that path is a
36 permanent canonicalisation (e.g. when we redirect from a channel to a 37 permanent canonicalisation (e.g. when we redirect from a channel to a
37 channel-less URL) or temporary (e.g. when we redirect from an apps-only API 38 channel-less URL) or temporary (e.g. when we redirect from an apps-only API
38 to an extensions one - we may at some point enable it for extensions). 39 to an extensions one - we may at some point enable it for extensions).
39 ''' 40 '''
40 class ReturnType(object): 41 class ReturnType(object):
41 def __init__(self, path, permanent): 42 def __init__(self, path, permanent):
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 else: 99 else:
99 path = 'extensions/%s' % extensions_path 100 path = 'extensions/%s' % extensions_path
100 else: 101 else:
101 if extensions_path is None: 102 if extensions_path is None:
102 path = 'apps/%s' % apps_path 103 path = 'apps/%s' % apps_path
103 else: 104 else:
104 assert apps_path == extensions_path 105 assert apps_path == extensions_path
105 path = '%s/%s' % (default_platform, apps_path) 106 path = '%s/%s' % (default_platform, apps_path)
106 107
107 return ReturnType(path, False) 108 return ReturnType(path, False)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/patch_servlet_test.py ('k') | chrome/common/extensions/docs/server2/redirector.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698