backup: minor code style
- Don't use catch-all except statement. - Use str.format instead of "%" operator. - Use static methods where applicable. - Remove unused local variables. - Don't shadow variables from outer scope
This commit is contained in:
parent
44eed25511
commit
e04ea7512c
@ -313,7 +313,7 @@ class Backup(object):
|
|||||||
for proc in self.processes_to_kill_on_cancel:
|
for proc in self.processes_to_kill_on_cancel:
|
||||||
try:
|
try:
|
||||||
proc.terminate()
|
proc.terminate()
|
||||||
except:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -746,11 +746,11 @@ class Backup(object):
|
|||||||
if self.canceled:
|
if self.canceled:
|
||||||
try:
|
try:
|
||||||
tar_sparse.terminate()
|
tar_sparse.terminate()
|
||||||
except:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
hmac.terminate()
|
hmac.terminate()
|
||||||
except:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
tar_sparse.wait()
|
tar_sparse.wait()
|
||||||
hmac.wait()
|
hmac.wait()
|
||||||
@ -1111,8 +1111,8 @@ class ExtractWorker2(Process):
|
|||||||
self.tar2_process.terminate()
|
self.tar2_process.terminate()
|
||||||
self.tar2_process.wait()
|
self.tar2_process.wait()
|
||||||
self.tar2_process = None
|
self.tar2_process = None
|
||||||
self.log.error("Error while processing '%s': %s " %
|
self.log.error("Error while processing '{}': {}".format(
|
||||||
(self.tar2_current_file, details))
|
self.tar2_current_file, details))
|
||||||
|
|
||||||
# Delete the file as we don't need it anymore
|
# Delete the file as we don't need it anymore
|
||||||
self.log.debug("Removing file " + filename)
|
self.log.debug("Removing file " + filename)
|
||||||
@ -1258,8 +1258,8 @@ class ExtractWorker3(ExtractWorker2):
|
|||||||
self.tar2_process.terminate()
|
self.tar2_process.terminate()
|
||||||
self.tar2_process.wait()
|
self.tar2_process.wait()
|
||||||
self.tar2_process = None
|
self.tar2_process = None
|
||||||
self.log.error("Error while processing '%s': %s " %
|
self.log.error("Error while processing '{}': {}".format(
|
||||||
(self.tar2_current_file, details))
|
self.tar2_current_file, details))
|
||||||
|
|
||||||
# Delete the file as we don't need it anymore
|
# Delete the file as we don't need it anymore
|
||||||
self.log.debug("Removing file " + filename)
|
self.log.debug("Removing file " + filename)
|
||||||
@ -1388,7 +1388,7 @@ class BackupRestore(object):
|
|||||||
for proc in self.processes_to_kill_on_cancel:
|
for proc in self.processes_to_kill_on_cancel:
|
||||||
try:
|
try:
|
||||||
proc.terminate()
|
proc.terminate()
|
||||||
except:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _start_retrieval_process(self, filelist, limit_count, limit_bytes):
|
def _start_retrieval_process(self, filelist, limit_count, limit_bytes):
|
||||||
@ -1459,14 +1459,15 @@ class BackupRestore(object):
|
|||||||
return command, filelist_pipe, error_pipe
|
return command, filelist_pipe, error_pipe
|
||||||
|
|
||||||
def _verify_hmac(self, filename, hmacfile, algorithm=None):
|
def _verify_hmac(self, filename, hmacfile, algorithm=None):
|
||||||
def load_hmac(hmac):
|
def load_hmac(hmac_text):
|
||||||
hmac = hmac.strip().split("=")
|
hmac_text = hmac_text.strip().split("=")
|
||||||
if len(hmac) > 1:
|
if len(hmac_text) > 1:
|
||||||
hmac = hmac[1].strip()
|
hmac_text = hmac_text[1].strip()
|
||||||
else:
|
else:
|
||||||
raise qubes.exc.QubesException("ERROR: invalid hmac file content")
|
raise qubes.exc.QubesException(
|
||||||
|
"ERROR: invalid hmac file content")
|
||||||
|
|
||||||
return hmac
|
return hmac_text
|
||||||
if algorithm is None:
|
if algorithm is None:
|
||||||
algorithm = self.header_data.hmac_algorithm
|
algorithm = self.header_data.hmac_algorithm
|
||||||
passphrase = self.passphrase.encode('utf-8')
|
passphrase = self.passphrase.encode('utf-8')
|
||||||
@ -1523,7 +1524,6 @@ class BackupRestore(object):
|
|||||||
['backup-header', 'backup-header.hmac',
|
['backup-header', 'backup-header.hmac',
|
||||||
'qubes.xml.000', 'qubes.xml.000.hmac'], 4, 1024 * 1024)
|
'qubes.xml.000', 'qubes.xml.000.hmac'], 4, 1024 * 1024)
|
||||||
|
|
||||||
nextfile = None
|
|
||||||
expect_tar_error = False
|
expect_tar_error = False
|
||||||
|
|
||||||
filename = filelist_pipe.readline().strip()
|
filename = filelist_pipe.readline().strip()
|
||||||
@ -1531,7 +1531,7 @@ class BackupRestore(object):
|
|||||||
# tar output filename before actually extracting it, so wait for the
|
# tar output filename before actually extracting it, so wait for the
|
||||||
# next one before trying to access it
|
# next one before trying to access it
|
||||||
if not self.backup_vm:
|
if not self.backup_vm:
|
||||||
nextfile = filelist_pipe.readline().strip()
|
filelist_pipe.readline().strip()
|
||||||
|
|
||||||
self.log.debug("Got backup header and hmac: {}, {}".format(
|
self.log.debug("Got backup header and hmac: {}, {}".format(
|
||||||
filename, hmacfile))
|
filename, hmacfile))
|
||||||
@ -1689,7 +1689,6 @@ class BackupRestore(object):
|
|||||||
if not extract_proc.is_alive():
|
if not extract_proc.is_alive():
|
||||||
retrieve_proc.terminate()
|
retrieve_proc.terminate()
|
||||||
retrieve_proc.wait()
|
retrieve_proc.wait()
|
||||||
expect_tar_error = True
|
|
||||||
if retrieve_proc in self.processes_to_kill_on_cancel:
|
if retrieve_proc in self.processes_to_kill_on_cancel:
|
||||||
self.processes_to_kill_on_cancel.remove(retrieve_proc)
|
self.processes_to_kill_on_cancel.remove(retrieve_proc)
|
||||||
# wait for other processes (if any)
|
# wait for other processes (if any)
|
||||||
@ -1888,7 +1887,8 @@ class BackupRestore(object):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _is_vm_included_in_backup_v2(self, check_vm):
|
@staticmethod
|
||||||
|
def _is_vm_included_in_backup_v2(check_vm):
|
||||||
if check_vm.backup_content:
|
if check_vm.backup_content:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@ -1974,7 +1974,8 @@ class BackupRestore(object):
|
|||||||
|
|
||||||
return vms_to_restore
|
return vms_to_restore
|
||||||
|
|
||||||
def get_restore_summary(self, restore_info):
|
@staticmethod
|
||||||
|
def get_restore_summary(restore_info):
|
||||||
fields = {
|
fields = {
|
||||||
"qid": {"func": "vm.qid"},
|
"qid": {"func": "vm.qid"},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user