OLD | NEW |
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 | 12 |
12 import appengine_wrappers | 13 import appengine_wrappers |
13 from file_system import FileNotFoundError | 14 from file_system import FileNotFoundError |
14 import url_constants | 15 import url_constants |
15 | 16 |
16 class _FakeFetcher(object): | 17 class _FakeFetcher(object): |
17 def __init__(self, base_path): | 18 def __init__(self, base_path): |
18 self._base_path = base_path | 19 self._base_path = base_path |
19 | 20 |
20 def _ReadFile(self, path, mode='rb'): | 21 def _ReadFile(self, path, mode='rb'): |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 html.append('<a>' + f + '/</a>') | 55 html.append('<a>' + f + '/</a>') |
55 else: | 56 else: |
56 html.append('<a>' + f + '</a>') | 57 html.append('<a>' + f + '</a>') |
57 html.append('</html>') | 58 html.append('</html>') |
58 return '\n'.join(html) | 59 return '\n'.join(html) |
59 except OSError as e: | 60 except OSError as e: |
60 raise FileNotFoundError('Listing %s failed: %s' (path, e)) | 61 raise FileNotFoundError('Listing %s failed: %s' (path, e)) |
61 try: | 62 try: |
62 return self._ReadFile(path) | 63 return self._ReadFile(path) |
63 except IOError as e: | 64 except IOError as e: |
64 raise FileNotFoundError('Reading %s failed: %s' (path, e)) | 65 raise FileNotFoundError('Reading %s failed: %s' % (path, e)) |
65 | 66 |
66 class FakeViewvcServer(_FakeFetcher): | 67 class FakeViewvcServer(_FakeFetcher): |
67 def __init__(self, base_path): | 68 def __init__(self, base_path): |
68 _FakeFetcher.__init__(self, base_path) | 69 _FakeFetcher.__init__(self, base_path) |
69 self._base_pattern = re.compile(r'.*chrome/common/extensions/(.*)') | 70 self._base_pattern = re.compile(r'.*chrome/common/extensions/(.*)') |
70 | 71 |
71 def fetch(self, url): | 72 def fetch(self, url): |
72 path = os.path.join(os.pardir, self._base_pattern.match(url).group(1)) | 73 path = os.path.join(os.pardir, self._base_pattern.match(url).group(1)) |
73 if self._IsDir(path): | 74 if self._IsDir(path): |
74 html = ['<table><tbody><tr>...</tr>'] | 75 html = ['<table><tbody><tr>...</tr>'] |
(...skipping 26 matching lines...) Expand all Loading... |
101 'github_file_system', | 102 'github_file_system', |
102 'apps_samples.zip'), | 103 'apps_samples.zip'), |
103 mode='rb') | 104 mode='rb') |
104 except IOError: | 105 except IOError: |
105 return None | 106 return None |
106 | 107 |
107 class FakeIssuesFetcher(_FakeFetcher): | 108 class FakeIssuesFetcher(_FakeFetcher): |
108 def fetch(self, url): | 109 def fetch(self, url): |
109 return 'Status,Summary,ID' | 110 return 'Status,Summary,ID' |
110 | 111 |
111 def ConfigureFakeFetchers(docs): | 112 def ConfigureFakeFetchers(): |
112 '''Configure the fake fetcher paths relative to the docs directory. | 113 '''Configure the fake fetcher paths relative to the docs directory. |
113 ''' | 114 ''' |
| 115 docs = '/'.join((sys.path[0], os.pardir)) |
114 appengine_wrappers.ConfigureFakeUrlFetch({ | 116 appengine_wrappers.ConfigureFakeUrlFetch({ |
115 url_constants.OMAHA_PROXY_URL: FakeOmahaProxy(docs), | 117 url_constants.OMAHA_PROXY_URL: FakeOmahaProxy(docs), |
116 '%s/.*' % url_constants.SVN_URL: FakeSubversionServer(docs), | 118 '%s/.*' % url_constants.SVN_URL: FakeSubversionServer(docs), |
117 '%s/.*' % url_constants.VIEWVC_URL: FakeViewvcServer(docs), | 119 '%s/.*' % url_constants.VIEWVC_URL: FakeViewvcServer(docs), |
118 '%s/commits/.*' % url_constants.GITHUB_URL: FakeGithubStat(docs), | 120 '%s/commits/.*' % url_constants.GITHUB_URL: FakeGithubStat(docs), |
119 '%s/zipball' % url_constants.GITHUB_URL: FakeGithubZip(docs), | 121 '%s/zipball' % url_constants.GITHUB_URL: FakeGithubZip(docs), |
120 re.escape(url_constants.OPEN_ISSUES_CSV_URL): FakeIssuesFetcher(docs), | 122 re.escape(url_constants.OPEN_ISSUES_CSV_URL): FakeIssuesFetcher(docs), |
121 re.escape(url_constants.CLOSED_ISSUES_CSV_URL): FakeIssuesFetcher(docs) | 123 re.escape(url_constants.CLOSED_ISSUES_CSV_URL): FakeIssuesFetcher(docs) |
122 }) | 124 }) |
OLD | NEW |