#NEWLINE# def add_zulip_subscriptions( verbose ) : #NEWLINE# #INDENT# zephyr_subscriptions = set ( ) #NEWLINE# skipped = set ( ) #NEWLINE# for ( cls , instance , recipient ) in parse_zephyr_subs ( verbose = verbose ) : #NEWLINE# #INDENT# if ( cls . lower ( ) == 'message' ) : #NEWLINE# #INDENT# if ( recipient != '*' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( instance == '*' ) : #NEWLINE# #INDENT# if ( recipient == '*' ) : #NEWLINE# #INDENT# skipped . add ( ( cls , instance , recipient , 'subscribing to all of class message is not supported.' ) ) #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# zephyr_subscriptions . add ( instance ) #NEWLINE# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( cls . lower ( ) == 'mail' ) and ( instance . lower ( ) == 'inbox' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( cls ) > 60 ) : #NEWLINE# #INDENT# skipped . add ( ( cls , instance , recipient , 'Class longer than 60 characters' ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( instance != '*' ) : #NEWLINE# #INDENT# skipped . add ( ( cls , instance , recipient , 'Unsupported non-* instance' ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( recipient != '*' ) : #NEWLINE# #INDENT# skipped . add ( ( cls , instance , recipient , 'Unsupported non-* recipient.' ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# zephyr_subscriptions . add ( cls ) #NEWLINE# #UNINDENT# if ( len ( zephyr_subscriptions ) != 0 ) : #NEWLINE# #INDENT# res = zulip_client . add_subscriptions ( list ( ( { #NEWLINE# #INDENT# 'name' : stream , #NEWLINE# #UNINDENT# } for stream in zephyr_subscriptions ) ) , authorization_errors_fatal = False ) #NEWLINE# if ( res . get ( 'result' ) != 'success' ) : #NEWLINE# #INDENT# logger . error ( ( 'Error subscribing to streams:\n%s' % ( res [ 'msg' ] , ) ) ) #NEWLINE# return #NEWLINE# #UNINDENT# already = res . get ( 'already_subscribed' ) #NEWLINE# new = res . get ( 'subscribed' ) #NEWLINE# unauthorized = res . get ( 'unauthorized' ) #NEWLINE# if verbose : #NEWLINE# #INDENT# if ( ( already is not None ) and ( len ( already ) > 0 ) ) : #NEWLINE# #INDENT# logger . info ( ( '\nAlready subscribed to: %s' % ( ', ' . join ( list ( already . values ( ) ) [ 0 ] ) , ) ) ) #NEWLINE# #UNINDENT# if ( ( new is not None ) and ( len ( new ) > 0 ) ) : #NEWLINE# #INDENT# logger . info ( ( '\nSuccessfully subscribed to: %s' % ( ', ' . join ( list ( new . values ( ) ) [ 0 ] ) , ) ) ) #NEWLINE# #UNINDENT# if ( ( unauthorized is not None ) and ( len ( unauthorized ) > 0 ) ) : #NEWLINE# #INDENT# logger . info ( ( ( '\n' + '\n' . join ( textwrap . wrap ( 'The following streams you have NOT been subscribed to,\nbecause they have been configured in Zulip as invitation-only streams.\nThis was done at the request of users of these Zephyr classes, usually\nbecause traffic to those streams is sent within the Zephyr world encrypted\nvia zcrypt (in Zulip, we achieve the same privacy goals through invitation-only streams).\nIf you wish to read these streams in Zulip, you need to contact the people who are\non these streams and already use Zulip.  They can subscribe you to them via the\n"streams" page in the Zulip web interface:\n' ) ) ) + ( '\n\n  %s' % ( ', ' . join ( unauthorized ) , ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( skipped ) > 0 ) : #NEWLINE# #INDENT# if verbose : #NEWLINE# #INDENT# logger . info ( ( ( '\n' + '\n' . join ( textwrap . wrap ( 'You have some lines in ~/.zephyr.subs that could not be\nsynced to your Zulip subscriptions because they do not\nuse "*" as both the instance and recipient and not one of\nthe special cases (e.g. personals and mail zephyrs) that\nZulip has a mechanism for forwarding.  Zulip does not\nallow subscribing to only some subjects on a Zulip\nstream, so this tool has not created a corresponding\nZulip subscription to these lines in ~/.zephyr.subs:\n' ) ) ) + '\n' ) ) #NEWLINE# #UNINDENT# #UNINDENT# for ( cls , instance , recipient , reason ) in skipped : #NEWLINE# #INDENT# if verbose : #NEWLINE# #INDENT# if ( reason != '' ) : #NEWLINE# #INDENT# logger . info ( ( '  [%s,%s,%s] (%s)' % ( cls , instance , recipient , reason ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logger . info ( ( '  [%s,%s,%s]' % ( cls , instance , recipient ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( skipped ) > 0 ) : #NEWLINE# #INDENT# if verbose : #NEWLINE# #INDENT# logger . info ( ( ( '\n' + '\n' . join ( textwrap . wrap ( 'If you wish to be subscribed to any Zulip streams related\nto these .zephyrs.subs lines, please do so via the Zulip\nweb interface.\n' ) ) ) + '\n' ) )