def arg_check(): '''Check and convert the command line argument(s). ''' #-- 1 -- # [ arg_list := the command line arguments ] arg_list = sys.argv[1:] #-- 2 -- # [ if (len(arg_list)==1) and arg_list[0] is a valid # date-time string -> # dt := that date-time as a datetime.datetime instance # else if (len(arg_list)==2) and (arg_list[0] is a valid # date) and (arg_list[1] is a valid time) -> # dt := a datetime.datetime representing that date # and time # else -> # sys.stderr +:= error message # stop execution ] if len(arg_list) == 1: try: dt = sdr.parse_datetime(arg_list[0]) except SyntaxError, detail: usage('Invalid date-time: {detail}'.format(detail=detail))
# else -> # sys.stderr +:= error message # stop execution ] try: lon = sdr.parse_lon(raw_lon) except SyntaxError, detail: usage('Invalid longitude: {detail}'.format(detail=detail)) #-- 5 -- # [ if raw_dt is a valid date-time string -> # dt := that date-time as a datetime.datetime instance # else -> # sys.stderr +:= error message # stop execution ] try: dt = sdr.parse_datetime(raw_dt) except SyntaxError, detail: usage('Invalid timestamp: {detail}'.format(detail=detail)) #-- 6 -- lat_lon = sdr.lat_lon(lat, lon) return (ra_dec, lat_lon, dt) #--- usage def usage(*L): '''Print a usage message and stop. [ L is a list of strings -> sys.stderr +:= (usage message) + (elements of L, concatenated) stop execution ]