-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcheck_outset_scripts.py
More file actions
50 lines (37 loc) · 1.37 KB
/
Copy pathcheck_outset_scripts.py
File metadata and controls
50 lines (37 loc) · 1.37 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
44
45
46
47
48
49
50
#!/usr/bin/python
"""Check Outset scripts to ensure they are executable."""
import argparse
import os
from pre_commit_macadmin_hooks.util import validate_shebangs
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.")
parser.add_argument(
"--valid-shebangs",
nargs="+",
default=[],
help="Add other valid shebangs for your environment",
)
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:
if not os.access(filename, os.X_OK):
print(f"{filename}: not executable")
retval = 1
# Ensure scripts have a proper shebang
with open(filename, encoding="utf-8") as openfile:
script_content = openfile.read()
if not validate_shebangs(script_content, filename, args.valid_shebangs):
print(f"{filename}: does not start with a valid shebang")
retval = 1
return retval
if __name__ == "__main__":
exit(main())