1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-21 00:19:42 +02:00

simplify None data scenario

This commit is contained in:
Kelly Brazil
2021-03-29 15:32:04 -07:00
parent d8d600cc36
commit 65c3a12e54
2 changed files with 35 additions and 24 deletions

View File

@ -157,9 +157,17 @@ def process(proc_data):
"gid": integer, "gid": integer,
"group": string, "group": string,
"access_time": string, # - = null "access_time": string, # - = null
"access_time_epoch": integer, # naive timestamp
"access_time_epoch_utc": integer, # timezone-aware timestamp
"modify_time": string, # - = null "modify_time": string, # - = null
"modify_time_epoch": integer, # naive timestamp
"modify_time_epoch_utc": integer, # timezone-aware timestamp
"change_time": string, # - = null "change_time": string, # - = null
"change_time_epoch": integer, # naive timestamp
"change_time_epoch_utc": integer, # timezone-aware timestamp
"birth_time": string, # - = null "birth_time": string, # - = null
"birth_time_epoch": integer, # naive timestamp
"birth_time_epoch_utc": integer, # timezone-aware timestamp
"unix_device": integer, "unix_device": integer,
"rdev": integer, "rdev": integer,
"block_size": integer, "block_size": integer,
@ -177,13 +185,15 @@ def process(proc_data):
except (ValueError): except (ValueError):
entry[key] = None entry[key] = None
# turn - into null for time fields # turn - into null for time fields and add calculated timestamp fields
for entry in proc_data: for entry in proc_data:
null_list = ['access_time', 'modify_time', 'change_time', 'birth_time'] null_list = ['access_time', 'modify_time', 'change_time', 'birth_time']
for key in null_list: for key in null_list:
if key in entry: if key in entry:
if entry[key] == '-': if entry[key] == '-':
entry[key] = None entry[key] = None
entry[key + '_epoch'] = jc.utils.parse_datetime_to_timestamp(entry[key])['timestamp_naive']
entry[key + '_epoch_utc'] = jc.utils.parse_datetime_to_timestamp(entry[key])['timestamp_utc']
return proc_data return proc_data

View File

@ -109,6 +109,7 @@ def parse_datetime_to_timestamp(data):
If the conversion completely fails, all fields will be None. If the conversion completely fails, all fields will be None.
""" """
data = data or ''
normalized_datetime = '' normalized_datetime = ''
utc_tz = False utc_tz = False
dt = None dt = None