Ben Pastene | 0d77b188 | 2020-06-10 23:31:04 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2019 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 | """Prints the target paths of the given symlinks. |
| 6 | |
| 7 | Prints out each target in the order that the links were passed in. |
| 8 | """ |
| 9 | |
| 10 | import os |
| 11 | import sys |
| 12 | |
| 13 | |
| 14 | def main(): |
| 15 | for link_name in sys.argv[1:]: |
| 16 | if not os.path.islink(link_name): |
| 17 | sys.stderr.write("%s is not a link" % link_name) |
| 18 | return 1 |
| 19 | target = os.readlink(link_name) |
| 20 | if not os.path.isabs(target): |
| 21 | target = os.path.join(os.path.dirname(link_name), target) |
| 22 | print(os.path.realpath(target)) |
| 23 | return 0 |
| 24 | |
| 25 | |
| 26 | if __name__ == '__main__': |
| 27 | sys.exit(main()) |