Skip to content

Commit 862a0a5

Browse files
authored
Merge pull request #1 from LaggAt/master
eliminate 'print' statements, a library should use a logger.
2 parents 2b080c2 + 99477d2 commit 862a0a5

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

urbackup_api/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import shutil
99
import os
1010
import binascii
11+
import logging
12+
logger = logging.getLogger('urbackup-server-python-api-wrapper')
13+
1114

1215
class urbackup_server:
1316

@@ -62,7 +65,7 @@ def _get_response(self, action, params, method="POST"):
6265
elif(target.scheme=='https'):
6366
h = http.HTTPSConnection(target.hostname, target.port, timeout=http_timeout)
6467
else:
65-
print('Unkown scheme: '+target.scheme)
68+
logger.error('Unkown scheme: '+target.scheme)
6669
raise Exception("Unkown scheme: "+target.scheme)
6770

6871
h.request(
@@ -86,7 +89,7 @@ def _get_json(self, action, params = {}):
8689
if(tries==0):
8790
return None
8891
else:
89-
print("API call failed. Retrying...")
92+
logger.error("API call failed. Retrying...")
9093

9194
data = response.read();
9295

@@ -114,18 +117,18 @@ def login(self):
114117

115118
if( not self._logged_in):
116119

117-
print("Trying anonymous login...")
120+
logger.debug("Trying anonymous login...")
118121

119122
login = self._get_json("login", {});
120123

121124
if(not login or 'success' not in login or not login['success']):
122125

123-
print("Logging in...")
126+
logger.debug("Logging in...")
124127

125128
salt = self._get_json("salt", {"username": self._server_username})
126129

127130
if( not salt or not ('ses' in salt) ):
128-
print('Username does not exist')
131+
logger.warning('Username does not exist')
129132
return False
130133

131134
self._session = salt["ses"];
@@ -146,7 +149,7 @@ def login(self):
146149
"password": password_md5 })
147150

148151
if(not login or 'success' not in login or not login['success']):
149-
print('Error during login. Password wrong?')
152+
logger.warning('Error during login. Password wrong?')
150153
return False
151154

152155
else:
@@ -182,7 +185,7 @@ def get_client_status(self, clientname):
182185

183186
return client;
184187

185-
print("Could not find client status. No permission?")
188+
logger.warning("Could not find client status. No permission?")
186189
return None
187190

188191
def download_installer(self, installer_fn, new_clientname):

0 commit comments

Comments
 (0)