| Total Complexity | 4 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | #!/usr/bin/env python2 |
||
| 2 | |||
| 3 | import sys |
||
| 4 | import os |
||
| 5 | import os.path |
||
| 6 | import argparse |
||
| 7 | |||
| 8 | import ssg.build_remediations as remediation |
||
| 9 | import ssg.rules |
||
| 10 | import ssg.jinja |
||
| 11 | import ssg.yaml |
||
| 12 | import ssg.utils |
||
| 13 | import ssg.xml |
||
| 14 | |||
| 15 | |||
| 16 | def parse_args(): |
||
| 17 | p = argparse.ArgumentParser() |
||
| 18 | p.add_argument("--remediation_type", required=True, |
||
| 19 | help="language or type of the remediations we are combining." |
||
| 20 | "example: ansible") |
||
| 21 | p.add_argument("--build_dir", required=True, |
||
| 22 | help="where is the cmake build directory. pass value of " |
||
| 23 | "$CMAKE_BINARY_DIR.") |
||
| 24 | p.add_argument("--output", type=argparse.FileType("wb"), required=True) |
||
| 25 | p.add_argument("fixdir", metavar="FIX_DIR", |
||
| 26 | help="directory from which we will collect " |
||
| 27 | "remediations to combine.") |
||
| 28 | |||
| 29 | return p.parse_args() |
||
| 30 | |||
| 31 | |||
| 32 | def main(): |
||
| 33 | args = parse_args() |
||
| 34 | |||
| 35 | if not os.path.isdir(args.fixdir): |
||
| 36 | sys.stderr.write("Directory %s does not exist" % args.fixdir) |
||
| 37 | sys.exit(1) |
||
| 38 | |||
| 39 | fixes = dict() |
||
| 40 | for filename in os.listdir(args.fixdir): |
||
| 41 | file_path = os.path.join(args.fixdir, filename) |
||
| 42 | fix_name, _ = os.path.splitext(filename) |
||
| 43 | result = remediation.parse_from_file_without_jinja(file_path) |
||
| 44 | fixes[fix_name] = result |
||
| 45 | |||
| 46 | remediation.write_fixes_to_xml(args.remediation_type, args.build_dir, |
||
| 47 | args.output, fixes) |
||
| 48 | |||
| 49 | sys.stderr.write("Merged %d %s remediations.\n" % (len(fixes), args.remediation_type)) |
||
| 50 | |||
| 51 | sys.exit(0) |
||
| 52 | |||
| 53 | |||
| 54 | if __name__ == "__main__": |
||
| 55 | main() |
||
| 56 |