#!/usr/bin/env python3 # Copyright 2015, Tresys Technology, LLC # # SPDX-License-Identifier: GPL-2.0-only # import sys import argparse import logging import warnings import setools import setoolsgui parser = argparse.ArgumentParser(description="Graphical SELinux policy analysis tool.") parser.add_argument("--version", action="version", version=setools.__version__) parser.add_argument("policy", nargs="?", help="Path to the SELinux policy to analyze.") parser.add_argument("-v", "--verbose", action="store_true", help="Print extra informational messages") parser.add_argument("--debug", action="store_true", dest="debug", help="Enable debugging.") args = parser.parse_args() logging.basicConfig(level=logging.DEBUG, filename="/dev/null") console_handler = logging.StreamHandler() if args.debug: console_handler.setLevel(logging.DEBUG) console_handler.setFormatter( logging.Formatter('%(asctime)s|%(levelname)s|%(name)s|%(message)s')) if not sys.warnoptions: warnings.simplefilter("default") elif args.verbose: console_handler.setLevel(logging.INFO) console_handler.setFormatter(logging.Formatter('%(message)s')) if not sys.warnoptions: warnings.simplefilter("default") else: console_handler.setLevel(logging.WARNING) console_handler.setFormatter(logging.Formatter('%(message)s')) if not sys.warnoptions: warnings.simplefilter("ignore") logging.getLogger().addHandler(console_handler) try: sys.exit(setoolsgui.run_apol(args.policy)) except AssertionError: # Always provide a traceback for assertion errors raise except Exception as err: if args.debug: raise else: print(err) sys.exit(1)