Add options and options parser

- Add --version option
- Add --help option
- Add --no-cache option
This commit is contained in:
linarphy 2023-05-16 13:38:02 +02:00
parent 484a75ac0f
commit 20be3e07ad
No known key found for this signature in database
GPG key ID: 3D4AAAC3AD16E79C

42
ETA.py
View file

@ -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' )