#NEWLINE# def _clean_hosting_info( self ) : #NEWLINE# #INDENT# 'Clean the hosting service information.\n\n        If using a hosting service, this will validate that the data\n        provided is valid on that hosting service. Then it will create an\n        account and link it, if necessary, with the hosting service.\n        ' #NEWLINE# hosting_type = self . cleaned_data [ 'hosting_type' ] #NEWLINE# if ( hosting_type == self . NO_HOSTING_SERVICE_ID ) : #NEWLINE# #INDENT# self . data [ 'hosting_account' ] = None #NEWLINE# self . cleaned_data [ 'hosting_account' ] = None #NEWLINE# return #NEWLINE# #UNINDENT# hosting_service_cls = get_hosting_service ( hosting_type ) #NEWLINE# assert hosting_service_cls #NEWLINE# tool_name = self . cleaned_data [ 'tool' ] . name #NEWLINE# if ( tool_name not in hosting_service_cls . supported_scmtools ) : #NEWLINE# #INDENT# self . errors [ 'tool' ] = self . error_class ( [ _ ( 'This tool is not supported on the given hosting service' ) ] ) #NEWLINE# return #NEWLINE# #UNINDENT# hosting_account = self . cleaned_data [ 'hosting_account' ] #NEWLINE# username = self . cleaned_data [ 'hosting_account_username' ] #NEWLINE# password = self . cleaned_data [ 'hosting_account_password' ] #NEWLINE# if hosting_service_cls . self_hosted : #NEWLINE# #INDENT# hosting_url = ( self . cleaned_data [ 'hosting_url' ] or None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# hosting_url = None #NEWLINE# #UNINDENT# if hosting_service_cls . supports_two_factor_auth : #NEWLINE# #INDENT# two_factor_auth_code = self . cleaned_data [ 'hosting_account_two_factor_auth_code' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# two_factor_auth_code = None #NEWLINE# #UNINDENT# if ( hosting_account and ( hosting_service_cls . hosting_url != hosting_url ) ) : #NEWLINE# #INDENT# self . errors [ 'hosting_account' ] = self . error_class ( [ _ ( 'This account is not compatible with this hosting service configuration' ) ] ) #NEWLINE# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( hosting_account and ( not username ) ) : #NEWLINE# #INDENT# username = hosting_account . username #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not hosting_account ) and ( not username ) ) : #NEWLINE# #INDENT# self . errors [ 'hosting_account' ] = self . error_class ( [ _ ( 'An account must be linked in order to use this hosting service' ) ] ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not hosting_account ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# hosting_account = HostingServiceAccount . objects . get ( service_name = hosting_type , username = username , hosting_url = hosting_url , local_site = self . local_site ) #NEWLINE# #UNINDENT# except HostingServiceAccount . DoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# plan = ( self . cleaned_data [ 'repository_plan' ] or self . DEFAULT_PLAN_ID ) #NEWLINE# repository_form = self . repository_forms [ hosting_type ] [ plan ] #NEWLINE# field_vars = repository_form . cleaned_data . copy ( ) #NEWLINE# field_vars . update ( self . cleaned_data ) #NEWLINE# if ( not hosting_account ) : #NEWLINE# #INDENT# hosting_account = HostingServiceAccount ( service_name = hosting_type , username = username , hosting_url = hosting_url , local_site = self . local_site ) #NEWLINE# #UNINDENT# if ( hosting_service_cls . needs_authorization and ( not hosting_account . is_authorized ) ) : #NEWLINE# #INDENT# hosting_service = None #NEWLINE# plan = None #NEWLINE# if hosting_service_cls : #NEWLINE# #INDENT# hosting_service = hosting_service_cls ( hosting_account ) #NEWLINE# if hosting_service : #NEWLINE# #INDENT# plan = ( self . cleaned_data [ 'repository_plan' ] or self . DEFAULT_PLAN_ID ) #NEWLINE# #UNINDENT# #UNINDENT# repository_extra_data = self . _build_repository_extra_data ( hosting_service , hosting_type , plan ) #NEWLINE# try : #NEWLINE# #INDENT# hosting_account . service . authorize ( username , password , hosting_url = hosting_url , two_factor_auth_code = two_factor_auth_code , tool_name = tool_name , local_site_name = self . local_site_name , ** repository_extra_data ) #NEWLINE# #UNINDENT# except TwoFactorAuthCodeRequiredError as e : #NEWLINE# #INDENT# self . errors [ 'hosting_account' ] = self . error_class ( [ six . text_type ( e ) ] ) #NEWLINE# hosting_info = self . hosting_service_info [ hosting_type ] #NEWLINE# hosting_info [ 'needs_two_factor_auth_code' ] = True #NEWLINE# return #NEWLINE# #UNINDENT# except AuthorizationError as e : #NEWLINE# #INDENT# self . errors [ 'hosting_account' ] = self . error_class ( [ ( _ ( 'Unable to link the account: %s' ) % e ) ] ) #NEWLINE# return #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# self . errors [ 'hosting_account' ] = self . error_class ( [ ( _ ( 'Unknown error when linking the account: %s' ) % e ) ] ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# if hosting_account : #NEWLINE# #INDENT# self . hosting_account_linked = True #NEWLINE# hosting_account . save ( ) #NEWLINE# #UNINDENT# self . data [ 'hosting_account' ] = hosting_account #NEWLINE# self . cleaned_data [ 'hosting_account' ] = hosting_account #NEWLINE# try : #NEWLINE# #INDENT# self . cleaned_data . update ( hosting_service_cls . get_repository_fields ( username = hosting_account . username , hosting_url = hosting_account . hosting_url , plan = plan , tool_name = tool_name , field_vars = field_vars ) ) #NEWLINE# #UNINDENT# except KeyError as e : #NEWLINE# #INDENT# raise ValidationError ( [ six . text_type ( e ) ] )