get_symlink_targets.py (691B)
1 #!/usr/bin/env python3 2 # Copyright 2019 The Chromium Authors 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())