File: shellcheck-tree

package info (click to toggle)
apparmor 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 34,800 kB
  • sloc: ansic: 24,940; python: 24,595; sh: 12,524; cpp: 9,024; yacc: 2,061; makefile: 1,921; lex: 1,215; pascal: 1,145; perl: 1,033; ruby: 365; lisp: 282; exp: 250; java: 212; xml: 159
file content (38 lines) | stat: -rwxr-xr-x 1,128 bytes parent folder | download
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
#!/usr/bin/python3

import glob
import re
import subprocess
import sys
from pathlib import Path


def is_excluded(f):
    return (re.match(
        # skip test scripts and the rc.apparmor.slackware initscript
        r"^([.]git/|parser/tst/|tests/|utils/test/|parser/rc[.]apparmor[.]slackware)"
        + "|"
        # skip several files generated during libapparmor build
        + r"^libraries/libapparmor/(compile|config[.]guess|config[.]status|config[.]sub|configure|depcomp|install-sh|libtool|ltmain[.]sh|missing|test-driver|ylwrap|testsuite/test_multi[.]multi)",
        f,
    ) or Path(f).is_dir())


def mimetype(f):
    return subprocess.run(['file', '--brief', '--mime-type', f],
                          stdout=subprocess.PIPE,
                          universal_newlines=True,
                          check=True).stdout.rstrip()


def is_shell_script(f):
    return mimetype(f) == "text/x-shellscript"


shell_scripts = [
    f for f in glob.glob("**/*", recursive=True)
    if not is_excluded(f) and is_shell_script(f)
]

sys.exit(
    subprocess.run(['shellcheck'] + sys.argv[1:] + shell_scripts).returncode)