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

Unified Diff: recipe_modules/file/api.py

Issue 2993713003: Add file.filesizes to recipe engine core modules. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: recipe_modules/file/api.py
diff --git a/recipe_modules/file/api.py b/recipe_modules/file/api.py
index ca9ebb66bca268c6e2714b56352c00e7ab9a3f45..a79960f7cf3c043223662da84396e1f8de303f4d 100644
--- a/recipe_modules/file/api.py
+++ b/recipe_modules/file/api.py
@@ -224,6 +224,28 @@ class FileApi(recipe_api.RecipeApi):
name, ['ensure-directory', '--mode', oct(mode), dest])
self.m.path.mock_add_paths(dest)
+ def filesizes(self, name, *files, **kwargs):
+ """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.
+
+ Args:
+ * name (str) - The name of the step.
+ * files (Path) - One or more paths to files.
+
+ Returns list[int], size of each file in bytes.
+ """
+ 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.
+ assert not kwargs, 'only test_data kwarg allowed'
+ for f in files:
+ self.m.path.assert_absolute(f)
+ result = self._run(
+ name, ['filesizes'] + list(files),
+ lambda: self.test_api.filesizes(test_data),
+ self.m.raw_io.output_text())
+ ret = map(int, result.stdout.strip().splitlines())
+ result.presentation.logs['filesizes'] = ['%s: \t%d' % fs
+ for fs in zip(files, ret)]
+ return ret
+
def rmtree(self, name, source):
"""Recursively removes a directory.

Powered by Google App Engine
This is Rietveld 408576698