From 20be3e07ad525d0c39873be4a9fa2944798e338a Mon Sep 17 00:00:00 2001 From: linarphy Date: Tue, 16 May 2023 13:38:02 +0200 Subject: [PATCH] Add options and options parser - Add --version option - Add --help option - Add --no-cache option --- ETA.py | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/ETA.py b/ETA.py index 33b747a..53f7862 100644 --- a/ETA.py +++ b/ETA.py @@ -8,11 +8,47 @@ from scipy.signal import convolve as sp_convolve from scipy.signal import find_peaks from scipy.ndimage import rotate -cache = True +cache , filename = True , None if len( sys.argv ) < 2: - raise Exception( 'this command must have a filename of an ETA fits as an argument' ) + raise Exception( 'ETA.py: type \'ETA.py -h\' for more information' ) -data = utils.load( sys.argv[1] ) +for arg in sys.argv[ 1 : ]: + if arg[0] == '-': + if len( arg ) < 2: + raise Exception( 'ETA.py: unknown argument, type \'ETA.py -h\' for more information' ) + if arg[1] != '-': + if arg == '-h': + arg = '--help' + elif arg == '-v': + arg = '--version' + elif arg == '-n': + arg == '--no-cachge' + else: + raise Exception( 'ETA.py: unknown argument "' + arg + '", type \'ETA.py -h\' for more information' ) + if arg[1] == '-': # not elif because arg can change after last if + if arg == '--help': + print( 'ETA.py [options...] filename\ + \n -h --help show this help and quit\ + \n -v --version show version number and quit\ + \n -n --no-cache do not use cache and rewrite it\ + \n\ + \nParse a naroo ETA fits' ) + exit() + elif arg == '--version': + print( '0.1' ) + exit() + elif arg == '--no-cache': + cache = False + else: + raise Exception( 'ETA.py: unknown argument "' + arg + '", type \'ETA.py -h\' for more information' ) + else: + raise Exception( 'ETA.py: this exception should never be raised' ) + else: + filename = arg +if filename == None: + raise Exception( 'ETA.py: filename should be given' ) + +data = utils.load( filename ) cache_file = pathlib.Path( 'asset/points_' + sys.argv[1].split( '/' )[-1][:-5] + '.pag' )