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

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

Issue 2672593002: raw_io module: Add text_input and text_output (Closed)
Patch Set: Add comment about no cover Created 3 years, 10 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 | « recipe_modules/raw_io/test_api.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The LUCI Authors. All rights reserved. 1 # Copyright 2016 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 from recipe_engine import recipe_api 5 from recipe_engine import recipe_api
6 6
7 class ShutilApi(recipe_api.RecipeApi): 7 class ShutilApi(recipe_api.RecipeApi):
8 def rmtree(self, path, **kwargs): 8 def rmtree(self, path, **kwargs):
9 name = kwargs.pop('name', 'rmtree %s' % path) 9 name = kwargs.pop('name', 'rmtree %s' % path)
10 self.m.python( 10 self.m.python(
(...skipping 28 matching lines...) Expand all
39 """, 39 """,
40 args=[source, dest, int(symlinks)], 40 args=[source, dest, int(symlinks)],
41 add_python_log=False, 41 add_python_log=False,
42 **kwargs 42 **kwargs
43 ) 43 )
44 44
45 def read(self, name, path, test_data=None, **kwargs): 45 def read(self, name, path, test_data=None, **kwargs):
46 """Read a file and return its contents.""" 46 """Read a file and return its contents."""
47 step_test_data = None 47 step_test_data = None
48 if test_data is not None: 48 if test_data is not None:
49 step_test_data = lambda: self.m.raw_io.test_api.output(test_data) 49 step_test_data = lambda: self.m.raw_io.test_api.output_text(test_data)
50 return self.copy(name, path, self.m.raw_io.output(), 50 return self.copy(name, path, self.m.raw_io.output_text(),
51 step_test_data=step_test_data, **kwargs).raw_io.output 51 step_test_data=step_test_data, **kwargs).raw_io.output_text
52 52
53 def write(self, name, path, data, **kwargs): 53 def write(self, name, path, data, **kwargs):
54 """Write the given data to a file.""" 54 """Write the given data to a file."""
55 return self.m.python.inline( 55 return self.m.python.inline(
56 name, 56 name,
57 """ 57 """
58 import shutil 58 import shutil
59 import sys 59 import sys
60 shutil.copy(sys.argv[1], sys.argv[2]) 60 shutil.copy(sys.argv[1], sys.argv[2])
61 """, 61 """,
62 args=[self.m.raw_io.input(data), path], 62 args=[self.m.raw_io.input_text(data), path],
63 add_python_log=False, 63 add_python_log=False,
64 **kwargs 64 **kwargs
65 ) 65 )
66 66
67 def glob(self, name, pattern, test_data=None, **kwargs): 67 def glob(self, name, pattern, test_data=None, **kwargs):
68 """Performs glob search on a directory. 68 """Performs glob search on a directory.
69 69
70 Returns list of files found. 70 Returns list of files found.
71 """ 71 """
72 step_test_data = None 72 step_test_data = None
73 if test_data is not None: 73 if test_data is not None:
74 step_test_data = ( 74 step_test_data = (
75 lambda: self.m.raw_io.test_api.output('\n'.join(map(str, test_data)))) 75 lambda: self.m.raw_io.test_api.output_text(
76 '\n'.join(map(str, test_data))))
76 step_result = self.m.python.inline( 77 step_result = self.m.python.inline(
77 name, 78 name,
78 r""" 79 r"""
79 import glob 80 import glob
80 import sys 81 import sys
81 with open(sys.argv[1], 'w') as f: 82 with open(sys.argv[1], 'w') as f:
82 f.write('\n'.join(glob.glob(sys.argv[2]))) 83 f.write('\n'.join(glob.glob(sys.argv[2])))
83 """, 84 """,
84 args=[self.m.raw_io.output(), pattern], 85 args=[self.m.raw_io.output_text(), pattern],
85 step_test_data=step_test_data, 86 step_test_data=step_test_data,
86 add_python_log=False, 87 add_python_log=False,
87 **kwargs 88 **kwargs
88 ) 89 )
89 return step_result.raw_io.output.splitlines() 90 return step_result.raw_io.output_text.splitlines()
90 91
91 def remove(self, name, path, **kwargs): 92 def remove(self, name, path, **kwargs):
92 """Remove the given file.""" 93 """Remove the given file."""
93 return self.m.python.inline( 94 return self.m.python.inline(
94 name, 95 name,
95 """ 96 """
96 import os 97 import os
97 import sys 98 import sys
98 os.remove(sys.argv[1]) 99 os.remove(sys.argv[1])
99 """, 100 """,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if not os.path.isdir(path): 132 if not os.path.isdir(path):
132 if os.path.exists(path): 133 if os.path.exists(path):
133 print "%s exists but is not a dir" % path 134 print "%s exists but is not a dir" % path
134 sys.exit(1) 135 sys.exit(1)
135 os.makedirs(path, mode) 136 os.makedirs(path, mode)
136 """, 137 """,
137 args=[path, str(mode)], 138 args=[path, str(mode)],
138 **kwargs 139 **kwargs
139 ) 140 )
140 self.m.path.mock_add_paths(path) 141 self.m.path.mock_add_paths(path)
OLDNEW
« no previous file with comments | « recipe_modules/raw_io/test_api.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698