<s> from datetime import datetime <EOL> import json <EOL> import os <EOL> import sys <EOL> import time <EOL> def find_in_sys_path ( file_path ) : <EOL> for directory in sys . path : <EOL> abs_path = os . path . join ( directory , file_path ) <EOL> if os . access ( abs_path , os . R_OK ) : <EOL> return abs_path <EOL> return None <EOL> def ensure_readable_directory ( d ) : <EOL> if not os . access ( d , os . R_OK ) : <EOL> raise Exception ( <EOL> "<STR_LIT>" % d <EOL> ) <EOL> def ensure_writable_directory ( d ) : <EOL> if not os . access ( d , os . W_OK ) : <EOL> raise Exception ( <EOL> "<STR_LIT>" % d <EOL> ) <EOL> def utcnow_isoformat ( time_calc = None ) : <EOL> if not time_calc : <EOL> time_calc = time <EOL> return time_calc . strftime ( "<STR_LIT>" , time_calc . gmtime ( ) ) <EOL> def queue_event ( <EOL> enqueuer , <EOL> event_type , service_key , incident_key , description , client , client_url , details , <EOL> agent_id , queued_by , <EOL> ) : <EOL> agent_context = { <EOL> "<STR_LIT>" : agent_id , <EOL> "<STR_LIT>" : queued_by , <EOL> "<STR_LIT>" : utcnow_isoformat ( ) <EOL> } <EOL> event = _build_event_json_str ( <EOL> event_type , service_key , incident_key , description , client , client_url , details , <EOL> agent_context <EOL> ) <EOL> _ , problems = enqueuer . enqueue ( service_key , event ) <EOL> return incident_key , problems <EOL> def resurrect_events ( queue , service_key ) : <EOL> return queue . resurrect ( service_key ) <EOL> def get_stats ( queue , service_key ) : <EOL> return queue . get_stats ( <EOL> detailed_snapshot = True , <EOL> per_service_key_snapshot = True , <EOL> service_key = service_key <EOL> ) <EOL> def _build_event_json_str ( <EOL> event_type , service_key , incident_key , description , client , client_url , details , <EOL> agent_context = None <EOL> ) : <EOL> d = { <EOL> "<STR_LIT>" : service_key , <EOL> "<STR_LIT>" : event_type , <EOL> "<STR_LIT>" : details , <EOL> } <EOL> if incident_key is not None : <EOL> d [ "<STR_LIT>" ] = incident_key <EOL> if description is not None : <EOL> d [ "<STR_LIT:description>" ] = description <EOL> if client is not None : <EOL> d [ "<STR_LIT>" ] = client <EOL> if client_url is not None : <EOL> d [ "<STR_LIT>" ] = client_url <EOL> if agent_context is not None : <EOL> d [ "<STR_LIT>" ] = agent_context <EOL> return json . dumps ( <EOL> d , <EOL> separators = ( '<STR_LIT:U+002C>' , '<STR_LIT::>' ) , <EOL> sort_keys = True <EOL> ) </s>
