def main(): """Main entry point for the application""" # setup command line arguments parser = argparse.ArgumentParser(description='Mantid Workbench') parser.add_argument('script', nargs='?') parser.add_argument('-x', '--execute', action='store_true', help='execute the script file given as argument') parser.add_argument('-q', '--quit', action='store_true', help='execute the script file with \'-x\' given as argument and then exit') # TODO -a or --about: show about dialog and exit # TODO -d or --default-settings: start MantidPlot with the default settings # DONE -h or --help: show command line options <- free with command line parser # TODO -v or --version: print MantidPlot version and release date # TODO -r or --revision: print MantidPlot version and release date # TODO -s or --silent: start mantidplot without any setup dialogs # DONE -x or --execute: execute the script file given as argument # DONE -xq or --executeandquit: execute the script file given as argument and then exit MantidPlot # this is not a valid short command line option try: # set up bash completion as a soft dependency import argcomplete argcomplete.autocomplete(parser) except ImportError: pass # silently skip this # parse the command line options options = parser.parse_args() # TODO handle options that don't require starting the workbench e.g. --help --version # fix/validate arguments if options.script is not None: # convert into absolute path options.script = os.path.abspath(os.path.expanduser(options.script)) if not os.path.exists(options.script): # TODO should be logged print('script "{}" does not exist'.format(options.script)) options.script = None app = initialize() # the default sys check interval leads to long lags # when request scripts to be aborted setswitchinterval(SYSCHECK_INTERVAL) exit_value = 0 try: exit_value = start_workbench(app, options) except BaseException: # We count this as a crash import traceback # This is type of thing we want to capture and have reports # about. Prints to stderr as we can't really count on anything # else traceback.print_exc(file=ORIGINAL_STDERR) exit_value = -1 finally: ORIGINAL_SYS_EXIT(exit_value)