<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> import difflib <EOL> import phlsys_arcconfig <EOL> import phlsys_arcrc <EOL> import phlsys_conduit <EOL> class InsufficientInfoException ( Exception ) : <EOL> def __init__ ( self , message ) : <EOL> super ( InsufficientInfoException , self ) . __init__ ( message ) <EOL> def _make_exception ( * args ) : <EOL> return InsufficientInfoException ( "<STR_LIT:\n>" + "<STR_LIT>" . join ( args ) ) <EOL> def add_argparse_arguments ( parser ) : <EOL> """<STR_LIT>""" <EOL> connection = parser . add_argument_group ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> connection . add_argument ( <EOL> "<STR_LIT>" , <EOL> type = str , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> connection . add_argument ( <EOL> "<STR_LIT>" , <EOL> type = str , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> connection . add_argument ( <EOL> "<STR_LIT>" , <EOL> type = str , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> connection . add_argument ( <EOL> '<STR_LIT>' , <EOL> type = str , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> def make_conduit ( uri = None , user = None , cert = None , act_as_user = None ) : <EOL> uri , user , cert , _ = get_uri_user_cert_explanation ( uri , user , cert ) <EOL> return phlsys_conduit . Conduit ( uri , user , cert , act_as_user ) <EOL> def obscured_cert ( cert ) : <EOL> """<STR_LIT>""" <EOL> return cert [ : <NUM_LIT:4> ] + '<STR_LIT>' + cert [ - <NUM_LIT:4> : ] <EOL> def get_uri_user_cert_explanation ( uri , user , cert ) : <EOL> if uri and user and cert : <EOL> explanations = [ "<STR_LIT>" ] <EOL> uri = _fix_uri ( explanations , uri ) <EOL> return uri , user , cert , '<STR_LIT>' . join ( explanations ) <EOL> arcrc , arcrc_path = _load_arcrc ( ) <EOL> arcconfig_path , arcconfig = _load_arcconfig ( ) <EOL> install_arc_url = str ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> no_uri = "<STR_LIT>" <EOL> no_user = "<STR_LIT>" <EOL> no_cert = "<STR_LIT>" <EOL> no_arcconfig = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:}>" ) <EOL> no_arcrc = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + install_arc_url ) <EOL> bad_arcrc = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + str ( arcrc_path ) ) <EOL> bad_arcconfig = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + str ( arcconfig_path ) ) <EOL> arcrc_no_default = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + install_arc_url ) <EOL> arcconfig_no_uri = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + str ( arcconfig_path ) ) <EOL> explanations = [ ] <EOL> if uri is None : <EOL> if not arcconfig_path : <EOL> if not arcrc_path : <EOL> raise _make_exception ( no_uri , no_arcconfig , no_arcrc ) <EOL> if arcrc is None : <EOL> raise _make_exception ( no_uri , no_arcconfig , bad_arcrc ) <EOL> if "<STR_LIT>" in arcrc : <EOL> uri = arcrc [ "<STR_LIT>" ] . get ( "<STR_LIT:default>" , None ) <EOL> if uri is None : <EOL> raise _make_exception ( no_uri , no_arcconfig , arcrc_no_default ) <EOL> explanations . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( arcrc_path , uri ) ) <EOL> else : <EOL> if arcconfig is None : <EOL> raise _make_exception ( no_uri , bad_arcconfig ) <EOL> uri = arcconfig . get ( "<STR_LIT>" , None ) <EOL> if uri is None : <EOL> raise _make_exception ( no_uri , arcconfig_no_uri ) <EOL> explanations . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( arcconfig_path , uri ) ) <EOL> uri = _fix_uri ( explanations , uri ) <EOL> arcrc_no_entry = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + uri + "<STR_LIT:\n>" <EOL> "<STR_LIT>" + install_arc_url ) <EOL> if user is None : <EOL> if not arcrc_path : <EOL> raise _make_exception ( no_user , no_arcrc ) <EOL> if arcrc is None : <EOL> raise _make_exception ( no_user , bad_arcrc ) <EOL> if "<STR_LIT>" in arcrc : <EOL> host = phlsys_arcrc . get_host ( arcrc , uri ) <EOL> if host is None : <EOL> raise _make_exception ( no_user , arcrc_no_entry ) <EOL> user = host . get ( "<STR_LIT:user>" , None ) <EOL> explanations . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( arcrc_path , user ) ) <EOL> if cert is None : <EOL> cert = host . get ( "<STR_LIT>" , None ) <EOL> explanations . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( arcrc_path , obscured_cert ( cert ) ) ) <EOL> if user is None : <EOL> raise _make_exception ( no_user , arcrc_no_entry ) <EOL> if user is None : <EOL> raise _make_exception ( no_user , arcrc_no_entry ) <EOL> if cert is None : <EOL> if not arcrc_path : <EOL> raise _make_exception ( no_cert , no_arcrc ) <EOL> if arcrc is None : <EOL> raise _make_exception ( no_cert , bad_arcrc ) <EOL> if "<STR_LIT>" in arcrc : <EOL> host = phlsys_arcrc . get_host ( arcrc , uri ) <EOL> if host is None : <EOL> raise _make_exception ( no_cert , arcrc_no_entry ) <EOL> cert = host . get ( "<STR_LIT>" , None ) <EOL> explanations . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( arcrc_path , obscured_cert ( cert ) ) ) <EOL> if cert is None : <EOL> raise _make_exception ( no_cert , arcrc_no_entry ) <EOL> if not ( uri and user and cert ) or arcrc_path is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return uri , user , cert , '<STR_LIT>' . join ( explanations ) <EOL> def _load_arcconfig ( ) : <EOL> arcconfig_path = phlsys_arcconfig . find_arcconfig ( ) <EOL> arcconfig = None <EOL> try : <EOL> if arcconfig_path is not None : <EOL> arcconfig = phlsys_arcconfig . load ( arcconfig_path ) <EOL> except ValueError : <EOL> pass <EOL> except EnvironmentError : <EOL> pass <EOL> return arcconfig_path , arcconfig <EOL> def _load_arcrc ( ) : <EOL> arcrc_path = phlsys_arcrc . find_arcrc ( ) <EOL> arcrc = None <EOL> try : <EOL> if arcrc_path is not None : <EOL> arcrc = phlsys_arcrc . load ( arcrc_path ) <EOL> except ValueError : <EOL> pass <EOL> except EnvironmentError : <EOL> pass <EOL> return arcrc , arcrc_path <EOL> def _fix_uri ( explanations , uri ) : <EOL> old_uri = uri <EOL> uri = phlsys_conduit . make_conduit_uri ( uri ) <EOL> if uri != old_uri : <EOL> diff = list ( difflib . Differ ( ) . compare ( [ old_uri ] , [ uri ] ) ) <EOL> diff = [ '<STR_LIT:U+0020>' + s . strip ( ) for s in diff ] <EOL> diff = '<STR_LIT:\n>' . join ( diff ) <EOL> explanations . append ( "<STR_LIT>" . format ( diff ) ) <EOL> return uri </s>
