Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
# Main for profile-to-xslt.py
parser = _get_arg_parser()
args = parser.parse_args()
try:
# Assume valid XML, prep profile for conversion
options = scripts.ValidationOptions()
options.in_profile = args.profile
# Convert the profile
_convert_profile(options)
# If no exception was thrown, then conversion was successful.
sys.exit(codes.EXIT_SUCCESS)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except Exception:
logging.exception("Fatal error occurred")
sys.exit(codes.EXIT_FAILURE)
_validate_args(args)
# Parse the input options
options = _set_validation_options(args)
# Set the output level (e.g., quiet vs. verbose)
scripts.set_output_level(options)
# Validate input documents
results = scripts.run_validation(options)
# Print validation results
scripts.print_results(results, options)
# Determine exit status code and exit.
code = scripts.status_code(results)
sys.exit(code)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except (errors.ValidationError, IOError) as ex:
scripts.error(
"Validation error occurred: '%s'" % str(ex),
codes.EXIT_VALIDATION_ERROR
)
except Exception:
logging.exception("Fatal error occurred")
sys.exit(codes.EXIT_FAILURE)
"""
parser = _get_arg_parser()
args = parser.parse_args()
try:
# Validate the input command line arguments
_validate_args(args)
# Parse the input options
options = _set_validation_options(args)
# Set the output level (e.g., quiet vs. verbose)
scripts.set_output_level(options)
# Validate input documents
results = scripts.run_validation(options)
# Print validation results
scripts.print_results(results, options)
# Determine exit status code and exit.
code = scripts.status_code(results)
sys.exit(code)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except (errors.ValidationError, IOError) as ex:
scripts.error(
"Validation error occurred: '%s'" % str(ex),
codes.EXIT_VALIDATION_ERROR
try:
# Assume valid XML, prep profile for conversion
options = scripts.ValidationOptions()
options.in_profile = args.profile
# Convert the profile
_convert_profile(options)
# If no exception was thrown, then conversion was successful.
sys.exit(codes.EXIT_SUCCESS)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except Exception:
logging.exception("Fatal error occurred")
sys.exit(codes.EXIT_FAILURE)
# Main for profile-to-sch.py
parser = _get_arg_parser()
args = parser.parse_args()
try:
# Assume valid XML, prep profile for conversion
options = scripts.ValidationOptions()
options.in_profile = args.profile
# Convert the profile
_convert_profile(options)
# If no exception was thrown, then conversion was successful.
sys.exit(codes.EXIT_SUCCESS)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except Exception:
logging.exception("Fatal error occurred")
sys.exit(codes.EXIT_FAILURE)
options = _set_validation_options(args)
# Set the output level (e.g., quiet vs. verbose)
scripts.set_output_level(options)
# Validate input documents
results = scripts.run_validation(options)
# Print validation results
scripts.print_results(results, options)
# Determine exit status code and exit.
code = scripts.status_code(results)
sys.exit(code)
except scripts.ArgumentError as ex:
if ex.show_help:
parser.print_help()
scripts.error(ex)
except (errors.ValidationError, IOError) as ex:
scripts.error(
"Validation error occurred: '%s'" % str(ex),
codes.EXIT_VALIDATION_ERROR
)
except Exception:
logging.exception("Fatal error occurred")
sys.exit(codes.EXIT_FAILURE)
ArgumentError: If invalid or incompatible command line arguments were
passed into the application.
"""
schema_validate = True
profile_validate = False
if schema_validate and args.profile:
profile_validate = True
if all((args.lang_version, args.use_schemaloc)):
raise scripts.ArgumentError(
"Cannot set both --stix-version and --use-schemalocs"
)
if args.profile and not profile_validate:
raise scripts.ArgumentError(
"Profile specified but no validation options specified."
)
def _set_validation_options(args):
"""Populates an instance of ``ValidationOptions`` from the `args` param.
Args:
args (argparse.Namespace): The arguments parsed and returned from
ArgumentParser.parse_args().
Returns:
Instance of ``ValidationOptions``.
"""
options = scripts.ValidationOptions()
options.schema_validate = True
if options.schema_validate and args.profile:
options.profile_validate = True
# best practice options
options.best_practice_validate = args.best_practices
# input options
options.lang_version = args.lang_version
options.schema_dir = args.schema_dir
options.in_profile = args.profile
options.recursive = args.recursive
options.use_schemaloc = args.use_schemaloc
options.huge_tree = args.huge_tree