| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 """Make a symlink and optionally touch a file (to handle dependencies). | 6 """Make a symlink and optionally touch a file (to handle dependencies). |
| 7 | 7 |
| 8 Usage: | 8 Usage: |
| 9 symlink.py [options] sources... target | 9 symlink.py [options] sources... target |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 if len(args) < 2: | 29 if len(args) < 2: |
| 30 parser.error('at least two arguments required.') | 30 parser.error('at least two arguments required.') |
| 31 | 31 |
| 32 target = args[-1] | 32 target = args[-1] |
| 33 sources = args[:-1] | 33 sources = args[:-1] |
| 34 for s in sources: | 34 for s in sources: |
| 35 t = os.path.join(target, os.path.basename(s)) | 35 t = os.path.join(target, os.path.basename(s)) |
| 36 if len(sources) == 1 and not os.path.isdir(target): | 36 if len(sources) == 1 and not os.path.isdir(target): |
| 37 t = target | 37 t = target |
| 38 t = os.path.expanduser(t) | 38 t = os.path.expanduser(t) |
| 39 if os.path.realpath(t) == s: | 39 if os.path.realpath(t) == s and not options.force: |
| 40 continue | 40 continue |
| 41 try: | 41 try: |
| 42 os.symlink(s, t) | 42 os.symlink(s, t) |
| 43 except OSError, e: | 43 except OSError, e: |
| 44 if e.errno == errno.EEXIST and options.force: | 44 if e.errno == errno.EEXIST and options.force: |
| 45 if os.path.isdir(t): | 45 if os.path.isdir(t): |
| 46 shutil.rmtree(t, ignore_errors=True) | 46 shutil.rmtree(t, ignore_errors=True) |
| 47 else: | 47 else: |
| 48 os.remove(t) | 48 os.remove(t) |
| 49 os.symlink(s, t) | 49 os.symlink(s, t) |
| 50 else: | 50 else: |
| 51 raise | 51 raise |
| 52 | 52 |
| 53 | 53 |
| 54 if options.touch: | 54 if options.touch: |
| 55 with open(options.touch, 'w') as f: | 55 with open(options.touch, 'w') as f: |
| 56 pass | 56 pass |
| 57 | 57 |
| 58 | 58 |
| 59 if __name__ == '__main__': | 59 if __name__ == '__main__': |
| 60 sys.exit(Main(sys.argv)) | 60 sys.exit(Main(sys.argv)) |
| OLD | NEW |