-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathreadlink
executable file
·40 lines (30 loc) · 1010 Bytes
/
readlink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# Copyright 2018 The ChromiumOS Authors
# 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:]))