OLD | NEW |
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 posixpath | 5 import posixpath |
6 from urlparse import urlsplit | 6 from urlparse import urlsplit |
7 | 7 |
8 from file_system import FileNotFoundError | 8 from file_system import FileNotFoundError |
9 from future import Future | 9 from future import All |
10 from path_util import Segment, Join, SplitParent | 10 from path_util import Segment, Join, SplitParent |
11 | 11 |
12 class Redirector(object): | 12 class Redirector(object): |
13 def __init__(self, compiled_fs_factory, file_system): | 13 def __init__(self, compiled_fs_factory, file_system): |
14 self._file_system = file_system | 14 self._file_system = file_system |
15 self._cache = compiled_fs_factory.ForJson(file_system) | 15 self._cache = compiled_fs_factory.ForJson(file_system) |
16 | 16 |
17 def Redirect(self, host, path): | 17 def Redirect(self, host, path): |
18 ''' Check if a path should be redirected, first according to host | 18 ''' Check if a path should be redirected, first according to host |
19 redirection rules, then from rules in redirects.json files. | 19 redirection rules, then from rules in redirects.json files. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 path.pop(0) | 101 path.pop(0) |
102 | 102 |
103 return 'https://developer.chrome.com/' + posixpath.join(*path) | 103 return 'https://developer.chrome.com/' + posixpath.join(*path) |
104 | 104 |
105 def Cron(self): | 105 def Cron(self): |
106 ''' Load files during a cron run. | 106 ''' Load files during a cron run. |
107 ''' | 107 ''' |
108 futures = [] | 108 futures = [] |
109 for root, dirs, files in self._file_system.Walk(''): | 109 for root, dirs, files in self._file_system.Walk(''): |
110 if 'redirects.json' in files: | 110 if 'redirects.json' in files: |
111 futures.append( | 111 futures.append(self._cache.GetFromFile(Join(root, 'redirects.json'))) |
112 self._cache.GetFromFile(posixpath.join(root, 'redirects.json'))) | 112 return All(futures) |
113 return Future(callback=lambda: [f.Get() for f in futures]) | |
OLD | NEW |