1- from __future__ import print_function
2-
31from getpass import getpass
42
53import code42cli .profile as cliprofile
4+ from code42cli .compat import str
5+ from code42cli .profile import print_and_log_no_existing_profile
66from code42cli .args import PROFILE_HELP , PROFILE_ARG_NAME
77from code42cli .commands import Command
88from code42cli .sdk_client import validate_connection
9- from code42cli .util import does_user_agree , print_error , print_no_existing_profile_message
9+ from code42cli .util import does_user_agree
10+ from code42cli .logger import get_main_cli_logger
1011
1112
1213def load_subcommands ():
@@ -79,25 +80,27 @@ def load_subcommands():
7980def show_profile (name = None ):
8081 """Prints the given profile to stdout."""
8182 c42profile = cliprofile .get_profile (name )
82- print (u"\n {0}:" .format (c42profile .name ))
83- print (u"\t * username = {}" .format (c42profile .username ))
84- print (u"\t * authority url = {}" .format (c42profile .authority_url ))
85- print (u"\t * ignore-ssl-errors = {}" .format (c42profile .ignore_ssl_errors ))
83+ logger = get_main_cli_logger ()
84+ logger .print_info (u"\n {0}:" .format (c42profile .name ))
85+ logger .print_info (u"\t * username = {}" .format (c42profile .username ))
86+ logger .print_info (u"\t * authority url = {}" .format (c42profile .authority_url ))
87+ logger .print_info (u"\t * ignore-ssl-errors = {}" .format (c42profile .ignore_ssl_errors ))
8688 if cliprofile .get_stored_password (c42profile .name ) is not None :
87- print (u"\t * A password is set." )
88- print (u"" )
89+ logger . print_info (u"\t * A password is set." )
90+ logger . print_info (u"" )
8991
9092
9193def create_profile (profile , server , username , disable_ssl_errors = False ):
9294 cliprofile .create_profile (profile , server , username , disable_ssl_errors )
9395 _prompt_for_allow_password_set (profile )
96+ get_main_cli_logger ().print_info (u"Successfully created profile '{}'." .format (profile ))
9497
9598
9699def update_profile (name = None , server = None , username = None , disable_ssl_errors = None ):
97100 profile = cliprofile .get_profile (name )
98101 cliprofile .update_profile (profile .name , server , username , disable_ssl_errors )
99102 _prompt_for_allow_password_set (profile .name )
100- print (u"Profile '{}' has been updated." .format (profile .name ))
103+ get_main_cli_logger (). print_info (u"Profile '{}' has been updated." .format (profile .name ))
101104
102105
103106def prompt_for_password_reset (name = None ):
@@ -110,7 +113,8 @@ def prompt_for_password_reset(name=None):
110113
111114def _validate_connection (authority , username , password ):
112115 if not validate_connection (authority , username , password ):
113- print_error (
116+ logger = get_main_cli_logger ()
117+ logger .print_and_log_error (
114118 u"Your credentials failed to validate, so your password was not stored."
115119 u"Check your network connection and the spelling of your username and server URL."
116120 )
@@ -120,11 +124,12 @@ def _validate_connection(authority, username, password):
120124def list_profiles (* args ):
121125 """Lists all profiles that exist for this OS user."""
122126 profiles = cliprofile .get_all_profiles ()
127+ logger = get_main_cli_logger ()
123128 if not profiles :
124- print_no_existing_profile_message ()
129+ print_and_log_no_existing_profile ()
125130 return
126131 for profile in profiles :
127- print ( profile )
132+ logger . print_info ( str ( profile ) )
128133
129134
130135def use_profile (profile ):
@@ -133,28 +138,31 @@ def use_profile(profile):
133138
134139
135140def delete_profile (name ):
141+ logger = get_main_cli_logger ()
136142 if cliprofile .is_default_profile (name ):
137- print (u"\n {} is currently the default profile!" .format (name ))
143+ logger . print_info (u"\n {} is currently the default profile!" .format (name ))
138144 if not does_user_agree (
139- u"\n Deleting this profile will also delete any stored passwords and checkpoints. Are you sure? (y/n): "
145+ u"\n Deleting this profile will also delete any stored passwords and checkpoints. "
146+ u"Are you sure? (y/n): "
140147 ):
141148 return
142149 cliprofile .delete_profile (name )
143150
144151
145152def delete_all_profiles ():
146153 existing_profiles = cliprofile .get_all_profiles ()
154+ logger = get_main_cli_logger ()
147155 if existing_profiles :
148- print (u"\n Are you sure you want to delete the following profiles?" )
156+ logger . print_info (u"\n Are you sure you want to delete the following profiles?" )
149157 for profile in existing_profiles :
150- print (u"\t {}" .format (profile .name ))
158+ logger . print_info (u"\t {}" .format (profile .name ))
151159 if does_user_agree (
152160 u"\n This will also delete any stored passwords and checkpoints. (y/n): "
153161 ):
154162 for profile in existing_profiles :
155163 cliprofile .delete_profile (profile .name )
156164 else :
157- print (u"\n No profiles exist. Nothing to delete." )
165+ logger . print_info (u"\n No profiles exist. Nothing to delete." )
158166
159167
160168def _load_optional_profile_description (argument_collection ):
0 commit comments