File: regexify_banner.py

package info (click to toggle)
scap-security-guide 0.1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 110,644 kB
  • sloc: xml: 241,883; sh: 73,777; python: 32,527; makefile: 27
file content (32 lines) | stat: -rwxr-xr-x 778 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python3
import argparse
import ssg.utils


def parse_args():
    p = argparse.ArgumentParser()
    p.add_argument("--output", help="Path to output regexified banner")
    p.add_argument("input", help="Path to file with banner to regexify")

    return p.parse_args()


def main():

    args = parse_args()
    with open(args.input, "r") as file_in:
        # rstrip is used to remove newline at the end of file
        banner_text = file_in.read().rstrip()

    banner_regex = ssg.utils.banner_regexify(banner_text)
    banner_regex = ssg.utils.banner_anchor_wrap(banner_regex)

    if args.output:
        with open(args.output, "w") as file_out:
            file_out.write(banner_regex)
    else:
        print(banner_regex)


if __name__ == "__main__":
    main()