#NEWLINE# def zephyr_to_zulip( options ) : #NEWLINE# #INDENT# if ( options . use_sessions and os . path . exists ( options . session_path ) ) : #NEWLINE# #INDENT# logger . info ( 'Loading old session' ) #NEWLINE# zephyr_load_session_autoretry ( options . session_path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# zephyr_init_autoretry ( ) #NEWLINE# if options . forward_class_messages : #NEWLINE# #INDENT# update_subscriptions ( ) #NEWLINE# #UNINDENT# if options . forward_personals : #NEWLINE# #INDENT# zephyr_subscribe_autoretry ( ( 'message' , '*' , '%me%' ) ) #NEWLINE# zephyr_subscribe_autoretry ( ( 'mail' , 'inbox' , '%me%' ) ) #NEWLINE# #UNINDENT# if options . nagios_class : #NEWLINE# #INDENT# zephyr_subscribe_autoretry ( ( options . nagios_class , '*' , '*' ) ) #NEWLINE# #UNINDENT# if options . use_sessions : #NEWLINE# #INDENT# open ( options . session_path , 'w' ) . write ( zephyr . _z . dump_session ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( options . logs_to_resend is not None ) : #NEWLINE# #INDENT# with open ( options . logs_to_resend , 'r' ) as log : #NEWLINE# #INDENT# for ln in log : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# zeph = simplejson . loads ( ln ) #NEWLINE# zeph = decode_unicode_byte_strings ( zeph ) #NEWLINE# if ( 'class' in zeph ) : #NEWLINE# #INDENT# zeph [ 'stream' ] = zeph [ 'class' ] #NEWLINE# #UNINDENT# if ( 'instance' in zeph ) : #NEWLINE# #INDENT# zeph [ 'subject' ] = zeph [ 'instance' ] #NEWLINE# #UNINDENT# logger . info ( ( 'sending saved message to %s from %s...' % ( zeph . get ( 'stream' , zeph . get ( 'recipient' ) ) , zeph [ 'sender' ] ) ) ) #NEWLINE# send_zulip ( zeph ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . exception ( 'Could not send saved zephyr:' ) #NEWLINE# time . sleep ( 2 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# logger . info ( 'Successfully initialized; Starting receive loop.' ) #NEWLINE# if ( options . resend_log_path is not None ) : #NEWLINE# #INDENT# with open ( options . resend_log_path , 'a' ) as log : #NEWLINE# #INDENT# process_loop ( log ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# process_loop ( None )