| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import fnmatch | 6 import fnmatch |
| 7 import glob | 7 import glob |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import posixpath | 10 import posixpath |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 options, files = parser.parse_args(args) | 126 options, files = parser.parse_args(args) |
| 127 if len(files) < 2: | 127 if len(files) < 2: |
| 128 parser.error('ERROR: expecting SOURCE(s) and DEST.') | 128 parser.error('ERROR: expecting SOURCE(s) and DEST.') |
| 129 | 129 |
| 130 srcs = files[:-1] | 130 srcs = files[:-1] |
| 131 dst = files[-1] | 131 dst = files[-1] |
| 132 | 132 |
| 133 src_list = [] | 133 src_list = [] |
| 134 for src in srcs: | 134 for src in srcs: |
| 135 files = glob.glob(src) | 135 files = glob.glob(src) |
| 136 if len(files) == 0: | 136 if not files: |
| 137 raise OSError('cp: no such file or directory: ' + src) | 137 raise OSError('cp: no such file or directory: ' + src) |
| 138 if files: | 138 if files: |
| 139 src_list.extend(files) | 139 src_list.extend(files) |
| 140 | 140 |
| 141 for src in src_list: | 141 for src in src_list: |
| 142 # If the destination is a directory, then append the basename of the src | 142 # If the destination is a directory, then append the basename of the src |
| 143 # to the destination. | 143 # to the destination. |
| 144 if os.path.isdir(dst): | 144 if os.path.isdir(dst): |
| 145 CopyPath(options, src, os.path.join(dst, os.path.basename(src))) | 145 CopyPath(options, src, os.path.join(dst, os.path.basename(src))) |
| 146 else: | 146 else: |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 '-f', '--force', dest='force', action='store_true', | 252 '-f', '--force', dest='force', action='store_true', |
| 253 default=False, | 253 default=False, |
| 254 help='force, do not error it files does not exist.') | 254 help='force, do not error it files does not exist.') |
| 255 options, files = parser.parse_args(args) | 255 options, files = parser.parse_args(args) |
| 256 if len(files) < 1: | 256 if len(files) < 1: |
| 257 parser.error('ERROR: expecting FILE...') | 257 parser.error('ERROR: expecting FILE...') |
| 258 | 258 |
| 259 try: | 259 try: |
| 260 for pattern in files: | 260 for pattern in files: |
| 261 dst_files = glob.glob(pattern) | 261 dst_files = glob.glob(pattern) |
| 262 # Ignore non existing files when using force | 262 if not dst_files: |
| 263 if len(dst_files) == 0 and options.force: | 263 # Ignore non existing files when using force |
| 264 print "rm: Skipping " + pattern | 264 if options.force: |
| 265 continue | 265 continue |
| 266 elif len(dst_files) == 0: | |
| 267 raise OSError('rm: no such file or directory: ' + pattern) | 266 raise OSError('rm: no such file or directory: ' + pattern) |
| 268 | 267 |
| 269 for dst in dst_files: | 268 for dst in dst_files: |
| 270 if options.verbose: | 269 if options.verbose: |
| 271 print 'rm ' + dst | 270 print 'rm ' + dst |
| 272 | 271 |
| 273 if os.path.isfile(dst) or os.path.islink(dst): | 272 if os.path.isfile(dst) or os.path.islink(dst): |
| 274 for i in range(5): | 273 for i in range(5): |
| 275 try: | 274 try: |
| 276 # Check every time, since it may have been deleted after the | 275 # Check every time, since it may have been deleted after the |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 options, files = parser.parse_args(args) | 355 options, files = parser.parse_args(args) |
| 357 if len(files) < 2: | 356 if len(files) < 2: |
| 358 parser.error('ERROR: expecting ZIPFILE and LIST.') | 357 parser.error('ERROR: expecting ZIPFILE and LIST.') |
| 359 | 358 |
| 360 dest_zip = files[0] | 359 dest_zip = files[0] |
| 361 src_args = files[1:] | 360 src_args = files[1:] |
| 362 | 361 |
| 363 src_files = [] | 362 src_files = [] |
| 364 for src_arg in src_args: | 363 for src_arg in src_args: |
| 365 globbed_src_args = glob.glob(src_arg) | 364 globbed_src_args = glob.glob(src_arg) |
| 366 if len(globbed_src_args) == 0: | 365 if not globbed_src_args: |
| 367 if not options.quiet: | 366 if not options.quiet: |
| 368 print 'zip warning: name not matched: %s' % (src_arg,) | 367 print 'zip warning: name not matched: %s' % (src_arg,) |
| 369 | 368 |
| 370 for src_file in globbed_src_args: | 369 for src_file in globbed_src_args: |
| 371 src_file = os.path.normpath(src_file) | 370 src_file = os.path.normpath(src_file) |
| 372 src_files.append(src_file) | 371 src_files.append(src_file) |
| 373 if options.recursive and os.path.isdir(src_file): | 372 if options.recursive and os.path.isdir(src_file): |
| 374 for root, dirs, files in os.walk(src_file): | 373 for root, dirs, files in os.walk(src_file): |
| 375 for dirname in dirs: | 374 for dirname in dirs: |
| 376 src_files.append(os.path.join(root, dirname)) | 375 src_files.append(os.path.join(root, dirname)) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 return 1 | 522 return 1 |
| 524 func = FuncMap.get(args[0]) | 523 func = FuncMap.get(args[0]) |
| 525 if not func: | 524 if not func: |
| 526 print 'Do not recognize command: ' + args[0] | 525 print 'Do not recognize command: ' + args[0] |
| 527 print 'Available commands: %s' % ' '.join(FuncMap) | 526 print 'Available commands: %s' % ' '.join(FuncMap) |
| 528 return 1 | 527 return 1 |
| 529 return func(args[1:]) | 528 return func(args[1:]) |
| 530 | 529 |
| 531 if __name__ == '__main__': | 530 if __name__ == '__main__': |
| 532 sys.exit(main(sys.argv[1:])) | 531 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |