-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcheck_plists.py
More file actions
executable file
·43 lines (32 loc) · 1.23 KB
/
Copy pathcheck_plists.py
File metadata and controls
executable file
·43 lines (32 loc) · 1.23 KB
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
41
42
43
#!/usr/bin/python
"""This hook checks XML property list (plist) files for basic syntax errors."""
import argparse
import plistlib
from xml.parsers.expat import ExpatError
def build_argument_parser() -> argparse.ArgumentParser:
"""Build and return the argument parser."""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument("filenames", nargs="*", help="Filenames to check.")
return parser
def main(argv: list[str] | None = None) -> int:
"""Main process."""
# Parse command line arguments.
argparser = build_argument_parser()
args = argparser.parse_args(argv)
retval = 0
for filename in args.filenames:
try:
with open(filename, "rb") as openfile:
_ = plistlib.load(openfile)
# Possible future addition, but disabled for now.
# if not isinstance(plist, dict):
# print(f"{filename}: top level of plist should be type dict")
# retval = 1
except (ExpatError, ValueError) as err:
print(f"{filename}: plist parsing error: {err}")
retval = 1
return retval
if __name__ == "__main__":
exit(main())