| #!/usr/bin/env python3 |
| # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """An alternate implementation of readlink that supports the non-standard -f. |
| |
| Note that this implementation of -f implies -m, but that shouldn't matter as |
| readlink isn't used to find missing directories, only canonicalize paths. |
| """ |
| |
| import os |
| import sys |
| |
| import libdot |
| |
| |
| def get_parser(): |
| """Get a command line parser.""" |
| parser = libdot.ArgumentParser(description=__doc__) |
| parser.add_argument('-f', '--canonicalize', action='store_true', |
| help='Canonicalize the paths.') |
| parser.add_argument('paths', nargs='+', |
| help='Paths to process.') |
| return parser |
| |
| |
| def main(argv): |
| """The main func!""" |
| parser = get_parser() |
| opts = parser.parse_args(argv) |
| for path in opts.paths: |
| print(os.path.realpath(path)) |
| |
| |
| if __name__ == '__main__': |
| sys.exit(main(sys.argv[1:])) |