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

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

Issue 12996003: Dynamically generate a heading for Extension Docs API pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revisions, Offline/Online Access (bypassed-hooks) Created 7 years, 7 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
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 # These are fake fetchers that are used for testing and the preview server. 5 # These are fake fetchers that are used for testing and the preview server.
6 # They return canned responses for URLs. appengine_wrappers.py uses the fake 6 # They return canned responses for URLs. appengine_wrappers.py uses the fake
7 # fetchers if the App Engine imports fail. 7 # fetchers if the App Engine imports fail.
8 8
9 import os 9 import os
10 import re 10 import re
11 import sys 11 import sys
12 12
13 import appengine_wrappers 13 import appengine_wrappers
14 from file_system import FileNotFoundError 14 from file_system import FileNotFoundError
15 import svn_constants
15 import url_constants 16 import url_constants
16 17
17 class _FakeFetcher(object): 18 class _FakeFetcher(object):
18 def __init__(self, base_path): 19 def __init__(self, base_path):
19 self._base_path = base_path 20 self._base_path = base_path
20 21
21 def _ReadFile(self, path, mode='rb'): 22 def _ReadFile(self, path, mode='rb'):
22 with open(os.path.join(self._base_path, path), mode) as f: 23 with open(os.path.join(self._base_path, path), mode) as f:
23 return f.read() 24 return f.read()
24 25
25 def _ListDir(self, path): 26 def _ListDir(self, path):
26 return os.listdir(os.path.join(self._base_path, path)) 27 return os.listdir(os.path.join(self._base_path, path))
27 28
28 def _IsDir(self, path): 29 def _IsDir(self, path):
29 return os.path.isdir(os.path.join(self._base_path, path)) 30 return os.path.isdir(os.path.join(self._base_path, path))
30 31
31 def _Stat(self, path): 32 def _Stat(self, path):
32 return int(os.stat(os.path.join(self._base_path, path)).st_mtime) 33 return int(os.stat(os.path.join(self._base_path, path)).st_mtime)
33 34
34 class FakeOmahaProxy(_FakeFetcher): 35 class FakeOmahaProxy(_FakeFetcher):
35 def fetch(self, url): 36 def fetch(self, url):
36 return self._ReadFile(os.path.join('server2', 37 return self._ReadFile(os.path.join('server2',
37 'test_data', 38 'test_data',
38 'branch_utility', 39 'branch_utility',
39 'first.json')) 40 'first.json'))
40 41
42 class FakeOmahaHistory(_FakeFetcher):
43 def fetch(self, url):
44 return self._ReadFile(os.path.join('server2',
45 'test_data',
46 'chrome_version_utility',
47 'omaha_dev_win_history.json'))
48
41 class FakeSubversionServer(_FakeFetcher): 49 class FakeSubversionServer(_FakeFetcher):
42 def __init__(self, base_path): 50 def __init__(self, base_path):
43 _FakeFetcher.__init__(self, base_path) 51 _FakeFetcher.__init__(self, base_path)
44 self._base_pattern = re.compile(r'.*chrome/common/extensions/(.*)') 52 self._base_pattern = re.compile(r'.*chrome/common/extensions/(.*)')
45 53
46 def fetch(self, url): 54 def fetch(self, url):
47 url = url.rsplit('?', 1)[0] 55 url = url.rsplit('?', 1)[0]
48 path = os.path.join(os.pardir, self._base_pattern.match(url).group(1)) 56 path = os.path.join(os.pardir, self._base_pattern.match(url).group(1))
49 if self._IsDir(path): 57 if self._IsDir(path):
50 html = ['<html>Revision 000000'] 58 html = ['<html>Revision 000000']
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 class FakeIssuesFetcher(_FakeFetcher): 118 class FakeIssuesFetcher(_FakeFetcher):
111 def fetch(self, url): 119 def fetch(self, url):
112 return 'Status,Summary,ID' 120 return 'Status,Summary,ID'
113 121
114 def ConfigureFakeFetchers(): 122 def ConfigureFakeFetchers():
115 '''Configure the fake fetcher paths relative to the docs directory. 123 '''Configure the fake fetcher paths relative to the docs directory.
116 ''' 124 '''
117 docs = '/'.join((sys.path[0], os.pardir)) 125 docs = '/'.join((sys.path[0], os.pardir))
118 appengine_wrappers.ConfigureFakeUrlFetch({ 126 appengine_wrappers.ConfigureFakeUrlFetch({
119 url_constants.OMAHA_PROXY_URL: FakeOmahaProxy(docs), 127 url_constants.OMAHA_PROXY_URL: FakeOmahaProxy(docs),
128 re.escape(url_constants.OMAHA_DEV_HISTORY): FakeOmahaHistory(docs),
120 '%s/.*' % url_constants.SVN_URL: FakeSubversionServer(docs), 129 '%s/.*' % url_constants.SVN_URL: FakeSubversionServer(docs),
121 '%s/.*' % url_constants.VIEWVC_URL: FakeViewvcServer(docs), 130 '%s/.*' % url_constants.VIEWVC_URL: FakeViewvcServer(docs),
122 '%s/commits/.*' % url_constants.GITHUB_URL: FakeGithubStat(docs), 131 '%s/commits/.*' % url_constants.GITHUB_URL: FakeGithubStat(docs),
123 '%s/zipball' % url_constants.GITHUB_URL: FakeGithubZip(docs), 132 '%s/zipball' % url_constants.GITHUB_URL: FakeGithubZip(docs),
124 re.escape(url_constants.OPEN_ISSUES_CSV_URL): FakeIssuesFetcher(docs), 133 re.escape(url_constants.OPEN_ISSUES_CSV_URL): FakeIssuesFetcher(docs),
125 re.escape(url_constants.CLOSED_ISSUES_CSV_URL): FakeIssuesFetcher(docs) 134 re.escape(url_constants.CLOSED_ISSUES_CSV_URL): FakeIssuesFetcher(docs)
126 }) 135 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698