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

@ -141,29 +141,37 @@ def process(proc_data):
[ [
{ {
"file": string, "file": string,
"link_to" string, "link_to" string,
"size": integer, "size": integer,
"blocks": integer, "blocks": integer,
"io_blocks": integer, "io_blocks": integer,
"type": string, "type": string,
"device": string, "device": string,
"inode": integer, "inode": integer,
"links": integer, "links": integer,
"access": string, "access": string,
"flags": string, "flags": string,
"uid": integer, "uid": integer,
"user": string, "user": string,
"gid": integer, "gid": integer,
"group": string, "group": string,
"access_time": string, # - = null "access_time": string, # - = null
"modify_time": string, # - = null "access_time_epoch": integer, # naive timestamp
"change_time": string, # - = null "access_time_epoch_utc": integer, # timezone-aware timestamp
"birth_time": string, # - = null "modify_time": string, # - = null
"unix_device": integer, "modify_time_epoch": integer, # naive timestamp
"rdev": integer, "modify_time_epoch_utc": integer, # timezone-aware timestamp
"block_size": integer, "change_time": string, # - = null
"unix_flags": string "change_time_epoch": integer, # naive timestamp
"change_time_epoch_utc": integer, # timezone-aware timestamp
"birth_time": string, # - = null
"birth_time_epoch": integer, # naive timestamp
"birth_time_epoch_utc": integer, # timezone-aware timestamp
"unix_device": integer,
"rdev": integer,
"block_size": integer,
"unix_flags": string
} }
] ]
""" """
@ -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