Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ansible/library/extract_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def extract_number(s):
else:
return int(ns[0])


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: two places where line breaks are removed. Double line break is a pip8 suggested format.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

def convert_date(fct, s):
dt = None
re_result = re.findall(r'^\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}\.?\d*', s)
Expand All @@ -137,9 +136,16 @@ def convert_date(fct, s):
if (dt - fct).days > 183:
dt.replace(year = dt.year - 1)
else:
re_result = re.findall(r'^\d{4}-\d{2}-\d{2}\.\d{2}:\d{2}:\d{2}\.\d{6}', s)
str_date = re_result[0]
dt = datetime.datetime.strptime(str_date, '%Y-%m-%d.%X.%f')
re_result = re.findall(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}', s)
if len(re_result) > 0:
str_date = re_result[0]
str_date = str_date.replace("T", " ")
dt = datetime.datetime.strptime(str_date, '%Y-%m-%d %X.%f')
else:
re_result = re.findall(r'^\d{4}-\d{2}-\d{2}\.\d{2}:\d{2}:\d{2}\.\d{6}', s)
if len(re_result) > 0:
str_date = re_result[0]
dt = datetime.datetime.strptime(str_date, '%Y-%m-%d.%X.%f')
locale.setlocale(locale.LC_ALL, loc)

return dt
Expand Down