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

Side by Side Diff: recipe_modules/file/resources/fileutil.py

Issue 2973133002: [file] fix glob_paths when NO paths match, add tests. (Closed)
Patch Set: Created 3 years, 5 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/file/examples/glob.expected/basic.json ('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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2017 The LUCI Authors. All rights reserved. 2 # Copyright 2017 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 """Utility exporting basic filesystem operations. 6 """Utility exporting basic filesystem operations.
7 7
8 This file was cut from "scripts/common/chromium_utils.py" at: 8 This file was cut from "scripts/common/chromium_utils.py" at:
9 91310531c31fa645256b4fb5d44b460c42b3e151 9 91310531c31fa645256b4fb5d44b460c42b3e151
10 """ 10 """
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if not os.path.isdir(dest): 147 if not os.path.isdir(dest):
148 if os.path.exists(dest): 148 if os.path.exists(dest):
149 raise OSError(errno.EEXIST, os.strerror(errno.EEXIST)) 149 raise OSError(errno.EEXIST, os.strerror(errno.EEXIST))
150 os.makedirs(dest, mode) 150 os.makedirs(dest, mode)
151 151
152 152
153 def _Glob(base, pattern): 153 def _Glob(base, pattern):
154 cwd = os.getcwd() 154 cwd = os.getcwd()
155 try: 155 try:
156 os.chdir(base) 156 os.chdir(base)
157 print('\n'.join(sorted(glob.glob(pattern)))) 157 hits = glob.glob(pattern)
158 if hits:
159 print('\n'.join(sorted(hits)))
158 finally: 160 finally:
159 os.chdir(cwd) 161 os.chdir(cwd)
160 162
161 163
162 def _Remove(path): 164 def _Remove(path):
163 try: 165 try:
164 os.remove(path) 166 os.remove(path)
165 except OSError as e: 167 except OSError as e:
166 if e.errno != errno.ENOENT: 168 if e.errno != errno.ENOENT:
167 raise 169 raise
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 data['message'] = 'UNKNOWN: %s' % e 271 data['message'] = 'UNKNOWN: %s' % e
270 272
271 with opts.json_output: 273 with opts.json_output:
272 json.dump(data, opts.json_output) 274 json.dump(data, opts.json_output)
273 275
274 return 0 276 return 0
275 277
276 278
277 if __name__ == '__main__': 279 if __name__ == '__main__':
278 sys.exit(main(sys.argv[1:])) 280 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « recipe_modules/file/examples/glob.expected/basic.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698