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

Side by Side Diff: scripts/slave/recipe_modules/path/api.py

Issue 302763003: First version of the PGO recipe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Address Robbie's comments. Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import functools 5 import functools
6 import os 6 import os
7 import tempfile 7 import tempfile
8 8
9 from slave import recipe_api 9 from slave import recipe_api
10 from slave import recipe_config_types 10 from slave import recipe_config_types
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 def listdir(self, name, path, step_test_data=None): 175 def listdir(self, name, path, step_test_data=None):
176 """Wrapper for os.listdir.""" 176 """Wrapper for os.listdir."""
177 yield self.m.python.inline('listdir %s' % name, 177 yield self.m.python.inline('listdir %s' % name,
178 """ 178 """
179 import json, os, sys 179 import json, os, sys
180 if os.path.exists(sys.argv[1]) and os.path.isdir(sys.argv[1]): 180 if os.path.exists(sys.argv[1]) and os.path.isdir(sys.argv[1]):
181 with open(sys.argv[2], 'w') as f: 181 with open(sys.argv[2], 'w') as f:
182 json.dump(os.listdir(sys.argv[1]), f) 182 json.dump(os.listdir(sys.argv[1]), f)
183 """, 183 """,
184 args=[path, self.m.json.output()], 184 args=[path, self.m.json.output()],
185 step_test_data=(step_test_data or 185 step_test_data=(step_test_data or
186 self.test_api.listdir(['file 1', 'file 2'])), 186 self.test_api.listdir(['file 1', 'file 2'])),
187 ) 187 )
188 188
189 def makedirs(self, name, path, mode=0777): 189 def makedirs(self, name, path, mode=0777):
190 """ 190 """
191 Like os.makedirs, except that if the directory exists, then there is no 191 Like os.makedirs, except that if the directory exists, then there is no
192 error. 192 error.
193 """ 193 """
194 self.assert_absolute(path) 194 self.assert_absolute(path)
195 yield self.m.python.inline( 195 yield self.m.python.inline(
(...skipping 20 matching lines...) Expand all
216 """ 216 """
217 import os, sys 217 import os, sys
218 from common import chromium_utils 218 from common import chromium_utils
219 219
220 if os.path.exists(sys.argv[1]): 220 if os.path.exists(sys.argv[1]):
221 chromium_utils.RemoveDirectory(sys.argv[1]) 221 chromium_utils.RemoveDirectory(sys.argv[1])
222 """, 222 """,
223 args=[path], 223 args=[path],
224 ) 224 )
225 225
226 def rmcontents(self, name, path): 226 def rmcontents(self, name, path, file_filter=None):
227 """ 227 """
228 Similar to rmtree, but removes only contents not the directory. 228 Similar to rmtree, but removes only contents not the directory.
229 229
230 This is useful e.g. when removing contents of current working directory. 230 This is useful e.g. when removing contents of current working directory.
231 Deleting current working directory makes all further getcwd calls fail 231 Deleting current working directory makes all further getcwd calls fail
232 until chdir is called. chdir would be tricky in recipes, so we provide 232 until chdir is called. chdir would be tricky in recipes, so we provide
233 a call that doesn't delete the directory itself. 233 a call that doesn't delete the directory itself.
234
235 An optional filter can be passed to the function to only remove the files
236 that match it.
iannucci 2014/06/19 21:37:17 specify that this should be a glob pattern appende
Sébastien Marchand 2014/07/03 19:13:17 I've removed this.
234 """ 237 """
235 self.assert_absolute(path) 238 self.assert_absolute(path)
236 return self.m.python.inline( 239 return self.m.python.inline(
237 'rmcontents ' + name, 240 'rmcontents ' + name,
238 """ 241 """
239 import os, sys 242 import glob, os, sys
240 from common import chromium_utils 243 from common import chromium_utils
241 244
242 for p in [os.path.join(sys.argv[1], x) for x in os.listdir(sys.argv[1])]: 245 file_list = []
246
247 if len(sys.argv) > 2:
248 file_list = [os.path.join(sys.argv[1], x) for x in glob.glob(
249 sys.argv[1] + sys.argv[2])]
250 else:
251 file_list = [os.path.join(sys.argv[1], x) for x in os.listdir(
252 sys.argv[1])]
253
254 for p in file_list:
243 if os.path.isdir(p): 255 if os.path.isdir(p):
244 chromium_utils.RemoveDirectory(p) 256 chromium_utils.RemoveDirectory(p)
245 else: 257 else:
246 os.unlink(p) 258 os.unlink(p)
247 """, 259 """,
248 args=[path], 260 args=[path, file_filter],
249 ) 261 )
250 262
251 def rmwildcard(self, pattern, path, **kwargs): 263 def rmwildcard(self, pattern, path, **kwargs):
252 """ 264 """
253 Removes all files in the subtree of path matching the glob pattern. 265 Removes all files in the subtree of path matching the glob pattern.
254 """ 266 """
255 self.assert_absolute(path) 267 self.assert_absolute(path)
256 return self.m.python.inline( 268 return self.m.python.inline(
257 'rmwildcard %s in %s' % (pattern, path), 269 'rmwildcard %s in %s' % (pattern, path),
258 """ 270 """
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 if name in self.OK_ATTRS: 318 if name in self.OK_ATTRS:
307 return getattr(self._path_mod, name) 319 return getattr(self._path_mod, name)
308 if name in self.FILTER_METHODS: 320 if name in self.FILTER_METHODS:
309 return string_filter(getattr(self._path_mod, name)) 321 return string_filter(getattr(self._path_mod, name))
310 raise AttributeError("'%s' object has no attribute '%s'" % 322 raise AttributeError("'%s' object has no attribute '%s'" %
311 (self._path_mod, name)) # pragma: no cover 323 (self._path_mod, name)) # pragma: no cover
312 324
313 def __dir__(self): # pragma: no cover 325 def __dir__(self): # pragma: no cover
314 # Used for helping out show_me_the_modules.py 326 # Used for helping out show_me_the_modules.py
315 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS) 327 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698