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

Side by Side Diff: recipe_modules/file/api.py

Issue 2993713003: Add file.filesizes to recipe engine core modules. (Closed)
Patch Set: update expectations Created 3 years, 4 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
« no previous file with comments | « README.recipes.md ('k') | recipe_modules/file/example.disable » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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):
iannucci 2017/08/07 19:27:30 No kwargs; we're trying to stamp this out everywhe
228 """Returns list of filesizes for the given files.
229
230 Args:
231 * name (str) - The name of the step.
232 * files (list[Path]) - Paths to files.
233
234 Returns list[int], size of each file in bytes.
235 """
236 test_data = kwargs.pop('test_data', [111 * (i+1) + (i % 3 - 2) * i
237 for i, _ in enumerate(files)])
238 assert not kwargs, 'only test_data kwarg allowed'
239 for f in files:
240 self.m.path.assert_absolute(f)
241 result = self._run(
242 name, ['filesizes'] + list(files),
243 lambda: self.test_api.filesizes(test_data),
244 self.m.raw_io.output_text())
245 ret = map(int, result.stdout.strip().splitlines())
246 result.presentation.logs['filesizes'] = ['%s: \t%d' % fs
247 for fs in zip(files, ret)]
248 return ret
249
227 def rmtree(self, name, source): 250 def rmtree(self, name, source):
228 """Recursively removes a directory. 251 """Recursively removes a directory.
229 252
230 This uses a native python on Linux/Mac, and uses `rd` on Windows to avoid 253 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 254 issues w.r.t. path lengths and read-only attributes. If the directory is
232 gone already, this returns without error. 255 gone already, this returns without error.
233 256
234 Args: 257 Args:
235 * name (str) - The name of the step. 258 * name (str) - The name of the step.
236 * source (Path) - The directory to remove. 259 * source (Path) - The directory to remove.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 Raises file.Error. 295 Raises file.Error.
273 """ 296 """
274 self.m.path.assert_absolute(source) 297 self.m.path.assert_absolute(source)
275 self._run(name, ['rmglob', source, pattern]) 298 self._run(name, ['rmglob', source, pattern])
276 299
277 src = str(source) 300 src = str(source)
278 def filt(p): 301 def filt(p):
279 assert p.startswith(src), (src, p) 302 assert p.startswith(src), (src, p)
280 return fnmatch.fnmatch(p[len(src)+1:].split(os.path.sep)[0], pattern) 303 return fnmatch.fnmatch(p[len(src)+1:].split(os.path.sep)[0], pattern)
281 self.m.path.mock_remove_paths(str(source), filt) 304 self.m.path.mock_remove_paths(str(source), filt)
OLDNEW
« no previous file with comments | « README.recipes.md ('k') | recipe_modules/file/example.disable » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698