Skip to content

Commit

Permalink
Refactored change_client_setting + removed semicolons
Browse files Browse the repository at this point in the history
  • Loading branch information
judahpaul16 committed Apr 28, 2024
1 parent 147b875 commit 01b83f0
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions urbackup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _get_json(self, action, params = {}):

def _download_file(self, action, outputfn, params):

req = self._get_response(action, params, 'GET');
req = self._get_response(action, params, 'GET')

if req.status_code != 200:
return False
Expand All @@ -122,7 +122,7 @@ def login(self):

logger.debug('Trying anonymous login...')

login = self._get_json('login', {});
login = self._get_json('login', {})

if not login or 'success' not in login or not login['success'] :
logger.debug('Logging in...')
Expand All @@ -132,7 +132,7 @@ def login(self):
logger.warning('Username does not exist')
return False

self._session = salt['ses'];
self._session = salt['ses']

if 'salt' in salt:
password_md5_bin = hashlib.md5((salt['salt']+self._server_password).encode()).digest()
Expand Down Expand Up @@ -161,7 +161,7 @@ def login(self):
return False
else:
self._logged_in = True
self._session = login['session'];
self._session = login['session']
return True
else:
return True
Expand All @@ -183,7 +183,7 @@ def get_client_status(self, clientname):

if client['name'] == clientname:

return client;
return client

logger.warning('Could not find client status. No permission?')
return None
Expand Down Expand Up @@ -267,7 +267,7 @@ def get_client_settings(self, clientname):
if client == None:
return None

clientid = client['id'];
clientid = client['id']

settings = self._get_json('settings', {'sa': 'clientsettings',
't_clientid': clientid})
Expand All @@ -282,26 +282,31 @@ def change_client_setting(self, clientname, key, new_value):
return False

client = self.get_client_status(clientname)

if client == None:
if client is None:
return False

clientid = client['id'];

settings = self._get_json('settings', {'sa': 'clientsettings',
't_clientid': clientid})

if not settings or not 'settings' in settings:
clientid = client['id']

current_settings = self.get_client_settings(clientname)
if current_settings is None:
return False

settings['settings'][key] = new_value
settings['settings']['overwrite'] = 'true'
settings['settings']['sa'] = 'clientsettings_save'
settings['settings']['t_clientid'] = clientid
if key in current_settings:
current_settings[key] = new_value
else:
logger.warning('Key not found in settings')
return False

ret = self._get_json('settings', settings['settings'])
save_payload = {
'overwrite': 'true',
'sa': 'clientsettings_save',
't_clientid': clientid
}

save_payload.update(current_settings)
ret = self._get_json('settings', save_payload)

return ret != None and 'saved_ok' in ret
return ret is not None and 'saved_ok' in ret

def get_client_authkey(self, clientname):

Expand Down Expand Up @@ -396,7 +401,7 @@ def _start_backup(self, clientname, backup_type):
return False

ret = self._get_json('start_backup', {'start_client': client_info['id'],
'start_type': backup_type } );
'start_type': backup_type } )

if ( ret == None
or 'result' not in ret
Expand All @@ -408,16 +413,16 @@ def _start_backup(self, clientname, backup_type):
return True

def start_incr_file_backup(self, clientname):
return self._start_backup(clientname, 'incr_file');
return self._start_backup(clientname, 'incr_file')

def start_full_file_backup(self, clientname):
return self._start_backup(clientname, 'full_file');
return self._start_backup(clientname, 'full_file')

def start_incr_image_backup(self, clientname):
return self._start_backup(clientname, 'incr_image');
return self._start_backup(clientname, 'incr_image')

def start_full_image_backup(self, clientname):
return self._start_backup(clientname, 'full_image');
return self._start_backup(clientname, 'full_image')

def add_extra_client(self, addr):
if not self.login():
Expand Down

0 comments on commit 01b83f0

Please sign in to comment.