Skip to content

Commit

Permalink
Print events timestamps in local time zone
Browse files Browse the repository at this point in the history
  • Loading branch information
alekna committed Sep 10, 2018
1 parent 8348102 commit af12144
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'tabulate>=0.7.5',
'setuptools',
'pytz',
'tzlocal',
]

tests_require = [
Expand Down
2 changes: 1 addition & 1 deletion stacks/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.4.0'
__version__ = '0.4.1'
__licence__ = 'MIT'
__url__ = 'https://stacks.tools'
__maintainer__ = 'Vaidas Jablonskis'
Expand Down
11 changes: 9 additions & 2 deletions stacks/cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import hashlib
import boto
import pytz
import tzlocal

from os import path
from jinja2 import meta
Expand Down Expand Up @@ -302,9 +303,10 @@ def print_events(conn, stack_name, follow, lines=100, from_dt=datetime.fromtimes
events, next_token = get_events(conn, stack_name, next_token)
status = get_stack_status(conn, stack_name)
if follow:
events_display = [(ev.timestamp, ev.resource_status, ev.resource_type,
normalize_events_timestamps(events)
events_display = [(ev.timestamp.astimezone(tzlocal.get_localzone()), ev.resource_status, ev.resource_type,
ev.logical_resource_id, ev.resource_status_reason) for ev in events
if ev.event_id not in seen_ids and ev.timestamp.replace(tzinfo=pytz.UTC) >= from_dt]
if ev.event_id not in seen_ids and ev.timestamp >= from_dt]
if len(events_display) > 0:
print(tabulate(events_display, tablefmt='plain'), flush=True)
seen_ids |= set([event.event_id for event in events])
Expand Down Expand Up @@ -350,3 +352,8 @@ def stack_exists(conn, stack_name):
if status == 'DELETE_COMPLETE' or status is None:
return False
return True


def normalize_events_timestamps(events):
for ev in events:
ev.timestamp = ev.timestamp.replace(tzinfo=pytz.UTC)

0 comments on commit af12144

Please sign in to comment.