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

Unified Diff: recipe_modules/file/examples/copytree.py

Issue 2918463002: [recipe_modules/file] add real file module to engine. (Closed)
Patch Set: rebase Created 3 years, 7 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/examples/copytree.py
diff --git a/recipe_modules/file/examples/copytree.py b/recipe_modules/file/examples/copytree.py
new file mode 100644
index 0000000000000000000000000000000000000000..ead18abb719823970d2176efd72bbbac964ce1ed
--- /dev/null
+++ b/recipe_modules/file/examples/copytree.py
@@ -0,0 +1,47 @@
+# Copyright 2017 The LUCI Authors. All rights reserved.
+# Use of this source code is governed under the Apache License, Version 2.0
+# that can be found in the LICENSE file.
+
+DEPS = [
+ "file",
+ "path",
+]
+
+
+def RunSteps(api):
+ file_names = ['a', 'aa', 'b', 'bb', 'c', 'cc']
+
+ dest = api.path['start_dir'].join('some dir')
+ api.file.ensure_directory('ensure "some dir"', dest)
+ for fname in file_names:
+ api.file.write_text('write %s' % fname, dest.join(fname), fname)
+
+ dest2 = api.path['start_dir'].join('some other dir')
+ api.file.rmtree('make sure dest is gone', dest2)
+ api.file.copytree('copy it', dest, dest2)
+
+ paths = api.file.listdir('list new dir', dest2, file_names)
+ assert paths == [dest2.join(n) for n in file_names], paths
+
+ paths = api.file.glob_paths('glob *a', dest2, '*a', ['a', 'aa'])
+ assert paths == [dest2.join('a'), dest2.join('aa')], paths
+
+ for pth in paths:
+ assert api.file.read_text('read %s' % pth, pth, api.path.basename(pth))
+
+ api.file.remove('rm a', dest2.join('a'))
+ paths = api.file.glob_paths('glob *a', dest2, '*a', ['aa'])
+ assert paths == [dest2.join('aa')], paths
+
+ api.file.rmglob('rm b*', dest2, 'b*')
+ paths = api.file.listdir('list new dir', dest2, ['aa', 'c', 'cc'])
+ assert paths == [dest2.join(p) for p in ['aa', 'c', 'cc']], paths
+
+ api.file.rmcontents('remove "some other dir/*"', dest2)
+ assert api.path.exists(dest2), dest2
+
+
+
+def GenTests(api):
+ yield api.test('basic')
+

Powered by Google App Engine
This is Rietveld 408576698