2022-01-16 08:24:05 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2016-01-15 07:25:46 +08:00
|
|
|
import argparse
|
|
|
|
import os.path
|
2024-10-12 07:30:07 +08:00
|
|
|
from collections.abc import Sequence
|
2016-01-15 07:25:46 +08:00
|
|
|
|
|
|
|
|
2022-01-16 08:24:05 +08:00
|
|
|
def main(argv: Sequence[str] | None = None) -> int:
|
2016-01-15 07:25:46 +08:00
|
|
|
parser = argparse.ArgumentParser(description='Checks for broken symlinks.')
|
|
|
|
parser.add_argument('filenames', nargs='*', help='Filenames to check')
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
|
|
|
|
retv = 0
|
|
|
|
|
|
|
|
for filename in args.filenames:
|
2016-01-15 23:41:58 +08:00
|
|
|
if (
|
|
|
|
os.path.islink(filename) and
|
|
|
|
not os.path.exists(filename)
|
2016-02-04 03:12:51 +08:00
|
|
|
): # pragma: no cover (symlink support required)
|
2020-02-06 03:10:42 +08:00
|
|
|
print(f'{filename}: Broken symlink')
|
2016-01-15 07:25:46 +08:00
|
|
|
retv = 1
|
|
|
|
|
|
|
|
return retv
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-10-24 01:23:50 +08:00
|
|
|
raise SystemExit(main())
|