| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 """Make a symlink and optionally touch a file (to handle dependencies).""" | |
| 6 import errno | |
| 7 import optparse | |
| 8 import os.path | |
| 9 import shutil | |
| 10 import sys | |
| 11 def Main(argv): | |
| 12 parser = optparse.OptionParser() | |
| 13 parser.add_option('-f', '--force', action='store_true') | |
| 14 parser.add_option('--touch') | |
| 15 options, args = parser.parse_args(argv[1:]) | |
| 16 if len(args) < 2: | |
| 17 parser.error('at least two arguments required.') | |
| 18 target = args[-1] | |
| 19 sources = args[:-1] | |
| 20 for s in sources: | |
| 21 t = os.path.join(target, os.path.basename(s)) | |
| 22 if len(sources) == 1 and not os.path.isdir(target): | |
| 23 t = target | |
| 24 try: | |
| 25 os.symlink(s, t) | |
| 26 except OSError, e: | |
| 27 if e.errno == errno.EEXIST and options.force: | |
| 28 if os.path.isdir(t): | |
| 29 shutil.rmtree(t, ignore_errors=True) | |
| 30 else: | |
| 31 os.remove(t) | |
| 32 os.symlink(s, t) | |
| 33 else: | |
| 34 raise | |
| 35 if options.touch: | |
| 36 with open(options.touch, 'w') as f: | |
| 37 pass | |
| 38 if __name__ == '__main__': | |
| 39 sys.exit(Main(sys.argv)) | |
| OLD | NEW |