Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2017 The LUCI Authors. All rights reserved. | 1 # Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """File manipulation (read/write/delete/glob) methods.""" | 5 """File manipulation (read/write/delete/glob) methods.""" |
| 6 | 6 |
| 7 from recipe_engine import recipe_api | 7 from recipe_engine import recipe_api |
| 8 | 8 |
| 9 | 9 |
| 10 import os | 10 import os |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 does not ensure the mode if the directory already exists (if you need | 217 does not ensure the mode if the directory already exists (if you need |
| 218 that behaviour, file a bug). | 218 that behaviour, file a bug). |
| 219 | 219 |
| 220 Raises file.Error if the path exists but is not a directory. | 220 Raises file.Error if the path exists but is not a directory. |
| 221 """ | 221 """ |
| 222 self.m.path.assert_absolute(dest) | 222 self.m.path.assert_absolute(dest) |
| 223 self._run( | 223 self._run( |
| 224 name, ['ensure-directory', '--mode', oct(mode), dest]) | 224 name, ['ensure-directory', '--mode', oct(mode), dest]) |
| 225 self.m.path.mock_add_paths(dest) | 225 self.m.path.mock_add_paths(dest) |
| 226 | 226 |
| 227 def filesizes(self, name, *files, **kwargs): | |
| 228 """Returns list of filesizes for a given files. | |
|
Michael Achenbach
2017/08/07 07:37:40
s/a/the
tandrii(chromium)
2017/08/07 10:59:49
Done.
| |
| 229 | |
| 230 Args: | |
| 231 * name (str) - The name of the step. | |
| 232 * files (Path) - One or more paths to files. | |
| 233 | |
| 234 Returns list[int], size of each file in bytes. | |
| 235 """ | |
| 236 test_data = kwargs.pop('test_data', ()) | |
|
Michael Achenbach
2017/08/07 07:37:39
How about some better fake data when no test data
tandrii(chromium)
2017/08/07 10:59:49
Done.
| |
| 237 assert not kwargs, 'only test_data kwarg allowed' | |
| 238 for f in files: | |
| 239 self.m.path.assert_absolute(f) | |
| 240 result = self._run( | |
| 241 name, ['filesizes'] + list(files), | |
| 242 lambda: self.test_api.filesizes(test_data), | |
| 243 self.m.raw_io.output_text()) | |
| 244 ret = map(int, result.stdout.strip().splitlines()) | |
| 245 result.presentation.logs['filesizes'] = ['%s: \t%d' % fs | |
| 246 for fs in zip(files, ret)] | |
| 247 return ret | |
| 248 | |
| 227 def rmtree(self, name, source): | 249 def rmtree(self, name, source): |
| 228 """Recursively removes a directory. | 250 """Recursively removes a directory. |
| 229 | 251 |
| 230 This uses a native python on Linux/Mac, and uses `rd` on Windows to avoid | 252 This uses a native python on Linux/Mac, and uses `rd` on Windows to avoid |
| 231 issues w.r.t. path lengths and read-only attributes. If the directory is | 253 issues w.r.t. path lengths and read-only attributes. If the directory is |
| 232 gone already, this returns without error. | 254 gone already, this returns without error. |
| 233 | 255 |
| 234 Args: | 256 Args: |
| 235 * name (str) - The name of the step. | 257 * name (str) - The name of the step. |
| 236 * source (Path) - The directory to remove. | 258 * source (Path) - The directory to remove. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 Raises file.Error. | 294 Raises file.Error. |
| 273 """ | 295 """ |
| 274 self.m.path.assert_absolute(source) | 296 self.m.path.assert_absolute(source) |
| 275 self._run(name, ['rmglob', source, pattern]) | 297 self._run(name, ['rmglob', source, pattern]) |
| 276 | 298 |
| 277 src = str(source) | 299 src = str(source) |
| 278 def filt(p): | 300 def filt(p): |
| 279 assert p.startswith(src), (src, p) | 301 assert p.startswith(src), (src, p) |
| 280 return fnmatch.fnmatch(p[len(src)+1:].split(os.path.sep)[0], pattern) | 302 return fnmatch.fnmatch(p[len(src)+1:].split(os.path.sep)[0], pattern) |
| 281 self.m.path.mock_remove_paths(str(source), filt) | 303 self.m.path.mock_remove_paths(str(source), filt) |
| OLD | NEW |