Merge branch 'stable' into devel
[tails.git] / bin / bandit-tree
blob878094e765eb8fefbdc77760b3ed37e3ef3e86b7
1 #!/usr/bin/python3
3 import glob
4 import re
5 import subprocess
6 import sys
7 from pathlib import Path
10 def is_excluded(f: str) -> bool:
11     return re.match(r"^([.]git|config/chroot_local-includes/usr/share/doc/tails/website|submodules|tmp|wiki/src)/",
12                     f) is not None or Path(f).is_dir()
15 def mimetype(f: str) -> str:
16     return subprocess.run(['file', '--brief', '--mime-type', f],
17                           stdout=subprocess.PIPE,
18                           universal_newlines=True,
19                           check=True).stdout.rstrip()
22 def is_python_file(f: str) -> bool:
23     return f.endswith('.py') or mimetype(f) == "text/x-script.python"
26 python_files = [
27     f for f in glob.glob("**/*", recursive=True)
28     if not is_excluded(f) and is_python_file(f)
31 sys.exit(
32     subprocess.run(['bandit'] + sys.argv[1:] + python_files).returncode)