Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Argument parser before actual argument parser to let the user overwrite the config path
preargparser = argparse.ArgumentParser(add_help=False)
preargparser.add_argument("-c", "--config", dest="configfile", default=None)
preargs, _ = preargparser.parse_known_args()
try:
if preargs.configfile:
# check if the given config file exists
# abort if not, because the user wants to use a specific file and not the default config
if os.path.exists(preargs.configfile):
Config.load_configuration(preargs.configfile)
else:
error_exit("Could find config file")
else:
# check if the config file exists and load it
if os.path.exists(DEFAULT_CONFIG_FILE):
Config.load_configuration(DEFAULT_CONFIG_FILE)
except configparser.MissingSectionHeaderError as e:
error_exit(e.message)
parser = argparse.ArgumentParser(description="Create a video contact sheet",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("filenames", nargs="+")
parser.add_argument(
"-o", "--output",
help="save to output file",
dest="output_path")
# adding --config to the main parser to display it when the user asks for help
# the value is not important anymore
parser.add_argument(
"-c", "--config",
help="Config file to load defaults from",
default=DEFAULT_CONFIG_FILE
def main():
"""Program entry point
"""
# Argument parser before actual argument parser to let the user overwrite the config path
preargparser = argparse.ArgumentParser(add_help=False)
preargparser.add_argument("-c", "--config", dest="configfile", default=None)
preargs, _ = preargparser.parse_known_args()
try:
if preargs.configfile:
# check if the given config file exists
# abort if not, because the user wants to use a specific file and not the default config
if os.path.exists(preargs.configfile):
Config.load_configuration(preargs.configfile)
else:
error_exit("Could find config file")
else:
# check if the config file exists and load it
if os.path.exists(DEFAULT_CONFIG_FILE):
Config.load_configuration(DEFAULT_CONFIG_FILE)
except configparser.MissingSectionHeaderError as e:
error_exit(e.message)
parser = argparse.ArgumentParser(description="Create a video contact sheet",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("filenames", nargs="+")
parser.add_argument(
"-o", "--output",
help="save to output file",
dest="output_path")