| 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..4c9ba1349fd87110854cbbe1edbccb4fe2525024
|
| --- /dev/null
|
| +++ b/recipe_modules/file/examples/copytree.py
|
| @@ -0,0 +1,49 @@
|
| +# 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)
|
| +
|
| + names = api.file.listdir('list new dir', dest2, file_names)
|
| + assert names == file_names, names
|
| +
|
| + paths = api.file.glob_paths('glob *a', dest2.join('*a'),
|
| + [dest2.join(x) for x in ('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.join('*a'), [dest2.join('aa')])
|
| + assert paths == [dest2.join('aa')], paths
|
| +
|
| + api.file.rmglob('rm b*', dest2, 'b*')
|
| + new_names = ['aa', 'c', 'cc']
|
| + names = api.file.listdir('list new dir', dest2, new_names)
|
| + assert names == new_names, names
|
| +
|
| + api.file.rmcontents('remove "some other dir/*"', dest2)
|
| + assert api.path.exists(dest2), dest2
|
| +
|
| +
|
| +
|
| +def GenTests(api):
|
| + yield api.test('basic')
|
| +
|
|
|