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

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

Issue 2993713003: Add file.filesizes to recipe engine core modules. (Closed)
Patch Set: -kwargs. Created 3 years, 4 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
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 func=lambda opts: print('\n'.join(sorted(os.listdir(opts.source))))) 243 func=lambda opts: print('\n'.join(sorted(os.listdir(opts.source)))))
244 244
245 # Subcommand: ensure-directory 245 # Subcommand: ensure-directory
246 subparser = subparsers.add_parser('ensure-directory', 246 subparser = subparsers.add_parser('ensure-directory',
247 help='Ensures that the given path is a directory.') 247 help='Ensures that the given path is a directory.')
248 subparser.add_argument('--mode', help='The octal mode of the directory.', 248 subparser.add_argument('--mode', help='The octal mode of the directory.',
249 type=lambda s: int(s, 8)) 249 type=lambda s: int(s, 8))
250 subparser.add_argument('dest', help='The dir to ensure.') 250 subparser.add_argument('dest', help='The dir to ensure.')
251 subparser.set_defaults(func=lambda opts: _EnsureDir(opts.mode, opts.dest)) 251 subparser.set_defaults(func=lambda opts: _EnsureDir(opts.mode, opts.dest))
252 252
253 # Subcommand: filesizes
254 subparser = subparsers.add_parser('filesizes',
255 help='Prints a list for sizes in bytes (1 per line) for each given file')
256 subparser.add_argument('file', nargs='+', help='Path to a file')
257 subparser.set_defaults(
258 func=lambda opts: print('\n'.join(str(os.stat(f).st_size)
259 for f in opts.file)))
260
253 # Parse arguments. 261 # Parse arguments.
254 opts = parser.parse_args(args) 262 opts = parser.parse_args(args)
255 263
256 # Actually do the thing. 264 # Actually do the thing.
257 data = { 265 data = {
258 'ok': False, 266 'ok': False,
259 'errno_name': '', 267 'errno_name': '',
260 'message': '', 268 'message': '',
261 } 269 }
262 try: 270 try:
263 opts.func(opts) 271 opts.func(opts)
264 data['ok'] = True 272 data['ok'] = True
265 except OSError as e: 273 except OSError as e:
266 data['errno_name'] = errno.errorcode[e.errno] 274 data['errno_name'] = errno.errorcode[e.errno]
267 data['message'] = str(e) 275 data['message'] = str(e)
268 except shutil.Error as e: 276 except shutil.Error as e:
269 data['message'] = e.message 277 data['message'] = e.message
270 except Exception as e: 278 except Exception as e:
271 data['message'] = 'UNKNOWN: %s' % e 279 data['message'] = 'UNKNOWN: %s' % e
272 280
273 with opts.json_output: 281 with opts.json_output:
274 json.dump(data, opts.json_output) 282 json.dump(data, opts.json_output)
275 283
276 return 0 284 return 0
277 285
278 286
279 if __name__ == '__main__': 287 if __name__ == '__main__':
280 sys.exit(main(sys.argv[1:])) 288 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « recipe_modules/file/examples/copytree.expected/basic.json ('k') | recipe_modules/file/test_api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698