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 import posixpath | 5 import posixpath |
6 import traceback | 6 import traceback |
7 | 7 |
8 from future import Gettable, Future | 8 from future import Gettable, Future |
9 from path_util import AssertIsDirectory, AssertIsValid, SplitParent, ToDirectory | 9 from path_util import ( |
| 10 AssertIsDirectory, AssertIsValid, IsDirectory, IsValid, SplitParent, |
| 11 ToDirectory) |
10 | 12 |
11 | 13 |
12 class _BaseFileSystemException(Exception): | 14 class _BaseFileSystemException(Exception): |
13 def __init__(self, message): | 15 def __init__(self, message): |
14 Exception.__init__(self, message) | 16 Exception.__init__(self, message) |
15 | 17 |
16 @classmethod | 18 @classmethod |
17 def RaiseInFuture(cls, message): | 19 def RaiseInFuture(cls, message): |
18 stack = traceback.format_stack() | 20 stack = traceback.format_stack() |
19 def boom(): raise cls('%s. Creation stack:\n%s' % (message, ''.join(stack))) | 21 def boom(): raise cls('%s. Creation stack:\n%s' % (message, ''.join(stack))) |
(...skipping 12 matching lines...) Expand all Loading... |
32 network timeout. | 34 network timeout. |
33 ''' | 35 ''' |
34 def __init__(self, filename): | 36 def __init__(self, filename): |
35 _BaseFileSystemException.__init__(self, filename) | 37 _BaseFileSystemException.__init__(self, filename) |
36 | 38 |
37 | 39 |
38 class StatInfo(object): | 40 class StatInfo(object): |
39 '''The result of calling Stat on a FileSystem. | 41 '''The result of calling Stat on a FileSystem. |
40 ''' | 42 ''' |
41 def __init__(self, version, child_versions=None): | 43 def __init__(self, version, child_versions=None): |
| 44 if child_versions: |
| 45 assert all(IsValid(path) for path in child_versions.iterkeys()), \ |
| 46 child_versions |
42 self.version = version | 47 self.version = version |
43 self.child_versions = child_versions | 48 self.child_versions = child_versions |
44 | 49 |
45 def __eq__(self, other): | 50 def __eq__(self, other): |
46 return (isinstance(other, StatInfo) and | 51 return (isinstance(other, StatInfo) and |
47 self.version == other.version and | 52 self.version == other.version and |
48 self.child_versions == other.child_versions) | 53 self.child_versions == other.child_versions) |
49 | 54 |
50 def __ne__(self, other): | 55 def __ne__(self, other): |
51 return not (self == other) | 56 return not (self == other) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 For any other failure, raises a FileSystemError. | 150 For any other failure, raises a FileSystemError. |
146 ''' | 151 ''' |
147 AssertIsDirectory(root) | 152 AssertIsDirectory(root) |
148 basepath = root | 153 basepath = root |
149 | 154 |
150 def walk(root): | 155 def walk(root): |
151 AssertIsDirectory(root) | 156 AssertIsDirectory(root) |
152 dirs, files = [], [] | 157 dirs, files = [], [] |
153 | 158 |
154 for f in self.ReadSingle(root).Get(): | 159 for f in self.ReadSingle(root).Get(): |
155 if f.endswith('/'): | 160 if IsDirectory(f): |
156 dirs.append(f) | 161 dirs.append(f) |
157 else: | 162 else: |
158 files.append(f) | 163 files.append(f) |
159 | 164 |
160 yield root[len(basepath):].rstrip('/'), dirs, files | 165 yield root[len(basepath):].rstrip('/'), dirs, files |
161 | 166 |
162 for d in dirs: | 167 for d in dirs: |
163 for walkinfo in walk(root + d): | 168 for walkinfo in walk(root + d): |
164 yield walkinfo | 169 yield walkinfo |
165 | 170 |
166 for walkinfo in walk(root): | 171 for walkinfo in walk(root): |
167 yield walkinfo | 172 yield walkinfo |
168 | 173 |
169 def __repr__(self): | 174 def __repr__(self): |
170 return '<%s>' % type(self).__name__ | 175 return '<%s>' % type(self).__name__ |
171 | 176 |
172 def __str__(self): | 177 def __str__(self): |
173 return repr(self) | 178 return repr(self) |
OLD | NEW |