File indexing completed on 2026-11-26 09:23:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 import argparse
0010 import logging
0011 import os
0012 import sys
0013 from datetime import datetime
0014
0015
0016
0017
0018
0019 """ Parent parser that contains logging options """
0020
0021
0022 def add_logging_options(parser):
0023 parser.add_argument(
0024 "-v",
0025 "--info",
0026 action="store_const",
0027 dest="loglevel",
0028 const=logging.INFO,
0029 help=("increase log level (INFO)"),
0030 )
0031 parser.add_argument(
0032 "-vv",
0033 "--debug",
0034 action="store_const",
0035 dest="loglevel",
0036 const=logging.DEBUG,
0037 help=("increase log level (DEBUG)"),
0038 )
0039
0040 return parser
0041
0042
0043 """ Parse logging options from commandline and set up logging service"""
0044
0045
0046 def parse_logging_options(args, prog_name=sys.argv[0]):
0047
0048 log_level = logging.WARNING
0049 if args.loglevel:
0050 log_level = args.loglevel
0051
0052
0053 logging.basicConfig(
0054 format=("%(levelname)s (%(module)s): %(message)s"), level=log_level
0055 )
0056
0057 logging.info(
0058 "\ndetray - "
0059 + str(datetime.now().strftime("%d/%m/%Y %H:%M"))
0060 + ': Running detector type generator "'
0061 + os.path.basename(prog_name)
0062 + '"\n'
0063 )
0064
0065
0066 """ Parent parser that contains IO options """
0067
0068
0069 def add_io_options(parser):
0070 parser.add_argument(
0071 "output_file",
0072 nargs="?",
0073 help="Exact output filename for codegen (disables formatting)",
0074 )
0075
0076 parser.add_argument(
0077 "-o",
0078 "--output",
0079 help=("Metadata output directory"),
0080 type=str,
0081 )
0082 parser.add_argument(
0083 "-f",
0084 "--format",
0085 help=("Format the header file"),
0086 default=True,
0087 action=argparse.BooleanOptionalAction,
0088 )
0089
0090 return parser
0091
0092
0093 """ Parse IO options from commandline"""
0094
0095
0096 def parse_io_options(args):
0097 if args.output_file:
0098 if args.output:
0099 raise ValueError(
0100 "Specify an output filename or --output directory, not both"
0101 )
0102 args.format = False
0103
0104 if args.output and not os.path.isdir(args.output):
0105 print(f"Output directory does not exist! ({args.output})")
0106 sys.exit(1)