Extra checks on JSON files downloaded

debug
Simon 3 years ago
parent a98a68c6f7
commit 274c438c26

@ -1389,12 +1389,16 @@ def try_download(_path, _file, _url, _stale,):
except IOError: except IOError:
result = 'ID ALIAS MAPPER: \'{}\' could not be downloaded due to an IOError'.format(_file) result = 'ID ALIAS MAPPER: \'{}\' could not be downloaded due to an IOError'.format(_file)
else: else:
try: if data and (data != b'{}'):
with open(_path+_file, 'wb') as outfile: try:
outfile.write(data) with open(_path+_file, 'wb') as outfile:
outfile.close() outfile.write(data)
except IOError: outfile.close()
result = 'ID ALIAS mapper \'{}\' file could not be written due to an IOError'.format(_file) except IOError:
result = 'ID ALIAS mapper \'{}\' file could not be written due to an IOError'.format(_file)
else:
result = 'ID ALIAS mapper \'{}\' file not written because downloaded data is empty for some reason'.format(_file)
else: else:
result = 'ID ALIAS MAPPER: \'{}\' is current, not downloaded'.format(_file) result = 'ID ALIAS MAPPER: \'{}\' is current, not downloaded'.format(_file)
@ -1417,6 +1421,11 @@ def mk_server_dict(path,filename):
# ID ALIAS CREATION # ID ALIAS CREATION
# Download # Download
def mk_aliases(_config): def mk_aliases(_config):
peer_ids = {}
subscriber_ids = {}
local_subscriber_ids = {}
talkgroup_ids = {}
server_ids = {}
if _config['ALIASES']['TRY_DOWNLOAD'] == True: if _config['ALIASES']['TRY_DOWNLOAD'] == True:
# Try updating peer aliases file # Try updating peer aliases file
result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE'], _config['ALIASES']['PEER_URL'], _config['ALIASES']['STALE_TIME']) result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE'], _config['ALIASES']['PEER_URL'], _config['ALIASES']['STALE_TIME'])
@ -1431,30 +1440,50 @@ def mk_aliases(_config):
result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE'], _config['ALIASES']['SERVER_ID_URL'], _config['ALIASES']['STALE_TIME']) result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE'], _config['ALIASES']['SERVER_ID_URL'], _config['ALIASES']['STALE_TIME'])
logger.info('(ALIAS) %s', result) logger.info('(ALIAS) %s', result)
# Make Dictionaries # Make Dictionaries
peer_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE']) try:
if peer_ids: _peer_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE'])
logger.info('(ALIAS) ID ALIAS MAPPER: peer_ids dictionary is available') except Exception as e:
logger.error('(ALIAS) ID ALIAS MAPPER: problem with data in peer_ids dictionary, not updating: %s',e)
subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SUBSCRIBER_FILE']) else:
#Add special IDs to DB peer_ids = _peer_ids
subscriber_ids[900999] = 'D-APRS' if peer_ids:
subscriber_ids[4294967295] = 'SC' logger.info('(ALIAS) ID ALIAS MAPPER: peer_ids dictionary is available')
if subscriber_ids: try:
logger.info('(ALIAS) ID ALIAS MAPPER: subscriber_ids dictionary is available') _subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SUBSCRIBER_FILE'])
except Exception as e:
logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in subscriber_ids dictionary, not updating: %s',e)
else:
subscriber_ids = _subscriber_ids
#Add special IDs to DB
subscriber_ids[900999] = 'D-APRS'
subscriber_ids[4294967295] = 'SC'
talkgroup_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['TGID_FILE']) if subscriber_ids:
if talkgroup_ids: logger.info('(ALIAS) ID ALIAS MAPPER: subscriber_ids dictionary is available')
logger.info('(ALIAS) ID ALIAS MAPPER: talkgroup_ids dictionary is available') try:
_talkgroup_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['TGID_FILE'])
local_subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['LOCAL_SUBSCRIBER_FILE']) except Exception as e:
if subscriber_ids: logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in talkgroup_ids dictionary, not updating: %s',e)
logger.info('(ALIAS) ID ALIAS MAPPER: local_subscriber_ids dictionary is available') else:
talkgroup_ids = _talkgroup_ids
server_ids = mk_server_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE']) if talkgroup_ids:
logger.info('(ALIAS) ID ALIAS MAPPER: talkgroup_ids dictionary is available')
try:
_local_subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['LOCAL_SUBSCRIBER_FILE'])
except Exception as e:
logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in local_subscriber_ids dictionary, not updating: %s',e)
else:
local_subscriber_ids = _local_subscriber_ids
if subscriber_ids:
logger.info('(ALIAS) ID ALIAS MAPPER: local_subscriber_ids dictionary is available')
try:
_server_ids = mk_server_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SERVER_ID_FILE'])
except Exception as e:
logger.info('(ALIAS) ID ALIAS MAPPER: problem with data in server_ids dictionary, not updating: %s',e)
else:
server_ids = _server_ids
if server_ids: if server_ids:
logger.info('(ALIAS) ID ALIAS MAPPER: server_ids dictionary is available') logger.info('(ALIAS) ID ALIAS MAPPER: server_ids dictionary is available')

Loading…
Cancel
Save

Powered by TurnKey Linux.