mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add timestamp format hints for better performance
This commit is contained in:
@ -83,7 +83,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '2.2'
|
||||
version = '2.3'
|
||||
description = '`date` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -168,7 +168,7 @@ def parse(data, raw=False, quiet=False):
|
||||
dt = None
|
||||
dt_utc = None
|
||||
|
||||
timestamp = jc.utils.timestamp(data)
|
||||
timestamp = jc.utils.timestamp(data, format_hint=(1000, 6000, 7000))
|
||||
if timestamp.naive:
|
||||
dt = datetime.fromtimestamp(timestamp.naive)
|
||||
if timestamp.utc:
|
||||
|
@ -327,7 +327,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '2.2'
|
||||
version = '2.3'
|
||||
description = '`dig` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -384,7 +384,7 @@ def _process(proc_data):
|
||||
auth['ttl'] = jc.utils.convert_to_int(auth['ttl'])
|
||||
|
||||
if 'when' in entry:
|
||||
ts = jc.utils.timestamp(entry['when'])
|
||||
ts = jc.utils.timestamp(entry['when'], format_hint=(1000, 7000))
|
||||
entry['when_epoch'] = ts.naive
|
||||
entry['when_epoch_utc'] = ts.utc
|
||||
|
||||
|
@ -126,7 +126,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.4'
|
||||
version = '1.5'
|
||||
description = '`dir` command parser'
|
||||
author = 'Rasheed Elsaleh'
|
||||
author_email = 'rasheed@rebelliondefense.com'
|
||||
@ -152,7 +152,7 @@ def _process(proc_data):
|
||||
# add timestamps
|
||||
if 'date' in entry and 'time' in entry:
|
||||
dt = entry['date'] + ' ' + entry['time']
|
||||
timestamp = jc.utils.timestamp(dt)
|
||||
timestamp = jc.utils.timestamp(dt, format_hint=(1600,))
|
||||
entry['epoch'] = timestamp.naive
|
||||
|
||||
# add ints
|
||||
|
@ -122,7 +122,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.10'
|
||||
version = '1.11'
|
||||
description = '`ls` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -154,7 +154,7 @@ def _process(proc_data):
|
||||
if 'date' in entry:
|
||||
# to speed up processing only try to convert the date if it's not the default format
|
||||
if not re.match(r'[a-zA-Z]{3}\s{1,2}\d{1,2}\s{1,2}[0-9:]{4,5}', entry['date']):
|
||||
ts = jc.utils.timestamp(entry['date'])
|
||||
ts = jc.utils.timestamp(entry['date'], format_hint=(7200,))
|
||||
entry['epoch'] = ts.naive
|
||||
entry['epoch_utc'] = ts.utc
|
||||
|
||||
|
@ -118,7 +118,7 @@ def _process(proc_data):
|
||||
if 'date' in proc_data:
|
||||
# to speed up processing only try to convert the date if it's not the default format
|
||||
if not re.match(r'[a-zA-Z]{3}\s{1,2}\d{1,2}\s{1,2}[0-9:]{4,5}', proc_data['date']):
|
||||
ts = jc.utils.timestamp(proc_data['date'])
|
||||
ts = jc.utils.timestamp(proc_data['date'], format_hint=(7200,))
|
||||
proc_data['epoch'] = ts.naive
|
||||
proc_data['epoch_utc'] = ts.utc
|
||||
|
||||
|
@ -166,7 +166,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.4'
|
||||
version = '1.5'
|
||||
description = '`rpm -qi` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -197,12 +197,12 @@ def _process(proc_data):
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
if 'build_date' in entry:
|
||||
timestamp = jc.utils.timestamp(entry['build_date'])
|
||||
timestamp = jc.utils.timestamp(entry['build_date'], format_hint=(3000,))
|
||||
entry['build_epoch'] = timestamp.naive
|
||||
entry['build_epoch_utc'] = timestamp.utc
|
||||
|
||||
if 'install_date' in entry:
|
||||
timestamp = jc.utils.timestamp(entry['install_date'])
|
||||
timestamp = jc.utils.timestamp(entry['install_date'], format_hint=(3000,))
|
||||
entry['install_date_epoch'] = timestamp.naive
|
||||
entry['install_date_epoch_utc'] = timestamp.utc
|
||||
|
||||
|
@ -185,7 +185,7 @@ def _process(proc_data: List[Dict]) -> List[Dict]:
|
||||
if 'date' in entry and 'time' in entry:
|
||||
date = entry['date'].replace('/', '-')
|
||||
date_time = f'{date} {entry["time"]}'
|
||||
ts = jc.utils.timestamp(date_time)
|
||||
ts = jc.utils.timestamp(date_time, format_hint=(7250,))
|
||||
entry['epoch'] = ts.naive
|
||||
|
||||
return proc_data
|
||||
|
@ -134,7 +134,7 @@ def _process(proc_data: Dict) -> Dict:
|
||||
if 'date' in proc_data and 'time' in proc_data:
|
||||
date = proc_data['date'].replace('/', '-')
|
||||
date_time = f'{date} {proc_data["time"]}'
|
||||
ts = jc.utils.timestamp(date_time)
|
||||
ts = jc.utils.timestamp(date_time, format_hint=(7250,))
|
||||
proc_data['epoch'] = ts.naive
|
||||
|
||||
return proc_data
|
||||
|
@ -176,7 +176,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.10'
|
||||
version = '1.11'
|
||||
description = '`stat` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -213,7 +213,7 @@ def _process(proc_data):
|
||||
if key in entry:
|
||||
if entry[key] == '-':
|
||||
entry[key] = None
|
||||
ts = jc.utils.timestamp(entry[key])
|
||||
ts = jc.utils.timestamp(entry[key], format_hint=(7100, 7200))
|
||||
entry[key + '_epoch'] = ts.naive
|
||||
entry[key + '_epoch_utc'] = ts.utc
|
||||
|
||||
|
@ -126,7 +126,7 @@ def _process(proc_data):
|
||||
if key in proc_data:
|
||||
if proc_data[key] == '-':
|
||||
proc_data[key] = None
|
||||
ts = jc.utils.timestamp(proc_data[key])
|
||||
ts = jc.utils.timestamp(proc_data[key], format_hint=(7100, 7200))
|
||||
proc_data[key + '_epoch'] = ts.naive
|
||||
proc_data[key + '_epoch_utc'] = ts.utc
|
||||
|
||||
|
@ -217,7 +217,7 @@ import jc.utils
|
||||
|
||||
class info:
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = "1.1"
|
||||
version = "1.2"
|
||||
description = "`systeminfo` command parser"
|
||||
author = "Jon Smith"
|
||||
author_email = "jon@rebelliondefense.com"
|
||||
@ -279,8 +279,10 @@ def _process(proc_data):
|
||||
# to: (UTC-0800)
|
||||
tz_fields = tz.split()
|
||||
tz = " " + tz_fields[0].replace(":", "")
|
||||
proc_data[key + '_epoch'] = jc.utils.timestamp(f"{proc_data.get(key)}{tz}").naive
|
||||
proc_data[key + '_epoch_utc'] = jc.utils.timestamp(f"{proc_data.get(key)}{tz}").utc
|
||||
ts_formats = (1700, 1705, 1710)
|
||||
ts = jc.utils.timestamp(f"{proc_data.get(key)}{tz}", format_hint=ts_formats)
|
||||
proc_data[key + '_epoch'] = ts.naive
|
||||
proc_data[key + '_epoch_utc'] = ts.utc
|
||||
|
||||
hyperv_key = "hyperv_requirements"
|
||||
hyperv_subkey_list = [
|
||||
|
@ -69,7 +69,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.5'
|
||||
version = '1.6'
|
||||
description = '`timedatectl status` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -99,7 +99,7 @@ def _process(proc_data):
|
||||
proc_data[key] = jc.utils.convert_to_bool(proc_data[key])
|
||||
|
||||
if 'universal_time' in proc_data:
|
||||
ts = jc.utils.timestamp(proc_data['universal_time'])
|
||||
ts = jc.utils.timestamp(proc_data['universal_time'], format_hint=(7300,))
|
||||
proc_data['epoch_utc'] = ts.utc
|
||||
|
||||
return proc_data
|
||||
|
@ -203,7 +203,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.3'
|
||||
version = '1.4'
|
||||
description = '`upower` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -234,7 +234,8 @@ def _process(proc_data):
|
||||
entry['updated_seconds_ago'] = jc.utils.convert_to_int(updated_list[-3])
|
||||
|
||||
if entry['updated']:
|
||||
ts = jc.utils.timestamp(entry['updated'])
|
||||
hints = (1000, 2000, 3000, 4000, 5000, 8000, 8100)
|
||||
ts = jc.utils.timestamp(entry['updated'], format_hint=hints)
|
||||
entry['updated_epoch'] = ts.naive
|
||||
entry['updated_epoch_utc'] = ts.utc
|
||||
|
||||
|
@ -131,7 +131,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.1'
|
||||
version = '1.2'
|
||||
description = '`vmstat` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -169,7 +169,8 @@ def _process(proc_data):
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
if entry['timestamp']:
|
||||
ts = jc.utils.timestamp(f'{entry["timestamp"]} {entry["timezone"]}')
|
||||
fmt_hint = (7250, 7255)
|
||||
ts = jc.utils.timestamp(f'{entry["timestamp"]} {entry["timezone"]}', format_hint=fmt_hint)
|
||||
entry['epoch'] = ts.naive
|
||||
entry['epoch_utc'] = ts.utc
|
||||
|
||||
|
@ -145,7 +145,8 @@ def _process(proc_data):
|
||||
proc_data[key] = jc.utils.convert_to_int(proc_data[key])
|
||||
|
||||
if proc_data['timestamp']:
|
||||
ts = jc.utils.timestamp(f'{proc_data["timestamp"]} {proc_data["timezone"]}')
|
||||
fmt_hint = (7250, 7255)
|
||||
ts = jc.utils.timestamp(f'{proc_data["timestamp"]} {proc_data["timezone"]}', format_hint=fmt_hint)
|
||||
proc_data['epoch'] = ts.naive
|
||||
proc_data['epoch_utc'] = ts.utc
|
||||
|
||||
|
@ -141,7 +141,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.5'
|
||||
version = '1.6'
|
||||
description = '`who` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -171,7 +171,7 @@ def _process(proc_data):
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
if 'time' in entry:
|
||||
ts = jc.utils.timestamp(entry['time'])
|
||||
ts = jc.utils.timestamp(entry['time'], format_hint=(1500,))
|
||||
entry['epoch'] = ts.naive
|
||||
|
||||
return proc_data
|
||||
|
Reference in New Issue
Block a user