cleaner progress clearing
This commit is contained in:
@ -10,6 +10,7 @@ class LogConsole:
|
|||||||
self.last_log = ""
|
self.last_log = ""
|
||||||
self.show_debug = show_debug
|
self.show_debug = show_debug
|
||||||
self.show_verbose = show_verbose
|
self.show_verbose = show_verbose
|
||||||
|
self._progress_uncleared=False
|
||||||
|
|
||||||
if color:
|
if color:
|
||||||
# try to use color, failback if colorama not available
|
# try to use color, failback if colorama not available
|
||||||
@ -25,6 +26,7 @@ class LogConsole:
|
|||||||
self.colorama=False
|
self.colorama=False
|
||||||
|
|
||||||
def error(self, txt):
|
def error(self, txt):
|
||||||
|
self.clear_progress()
|
||||||
if self.colorama:
|
if self.colorama:
|
||||||
print(colorama.Fore.RED + colorama.Style.BRIGHT + "! " + txt + colorama.Style.RESET_ALL, file=sys.stderr)
|
print(colorama.Fore.RED + colorama.Style.BRIGHT + "! " + txt + colorama.Style.RESET_ALL, file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
@ -32,6 +34,7 @@ class LogConsole:
|
|||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
def warning(self, txt):
|
def warning(self, txt):
|
||||||
|
self.clear_progress()
|
||||||
if self.colorama:
|
if self.colorama:
|
||||||
print(colorama.Fore.YELLOW + colorama.Style.BRIGHT + " NOTE: " + txt + colorama.Style.RESET_ALL)
|
print(colorama.Fore.YELLOW + colorama.Style.BRIGHT + " NOTE: " + txt + colorama.Style.RESET_ALL)
|
||||||
else:
|
else:
|
||||||
@ -40,6 +43,7 @@ class LogConsole:
|
|||||||
|
|
||||||
def verbose(self, txt):
|
def verbose(self, txt):
|
||||||
if self.show_verbose:
|
if self.show_verbose:
|
||||||
|
self.clear_progress()
|
||||||
if self.colorama:
|
if self.colorama:
|
||||||
print(colorama.Style.NORMAL + " " + txt + colorama.Style.RESET_ALL)
|
print(colorama.Style.NORMAL + " " + txt + colorama.Style.RESET_ALL)
|
||||||
else:
|
else:
|
||||||
@ -48,6 +52,7 @@ class LogConsole:
|
|||||||
|
|
||||||
def debug(self, txt):
|
def debug(self, txt):
|
||||||
if self.show_debug:
|
if self.show_debug:
|
||||||
|
self.clear_progress()
|
||||||
if self.colorama:
|
if self.colorama:
|
||||||
print(colorama.Fore.GREEN + "# " + txt + colorama.Style.RESET_ALL)
|
print(colorama.Fore.GREEN + "# " + txt + colorama.Style.RESET_ALL)
|
||||||
else:
|
else:
|
||||||
@ -57,10 +62,13 @@ class LogConsole:
|
|||||||
def progress(self, txt):
|
def progress(self, txt):
|
||||||
"""print progress output to stderr (stays on same line)"""
|
"""print progress output to stderr (stays on same line)"""
|
||||||
self.clear_progress()
|
self.clear_progress()
|
||||||
|
self._progress_uncleared=True
|
||||||
print(">>> {}\r".format(txt), end='', file=sys.stderr)
|
print(">>> {}\r".format(txt), end='', file=sys.stderr)
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
def clear_progress(self):
|
def clear_progress(self):
|
||||||
import colorama
|
if self._progress_uncleared:
|
||||||
print(colorama.ansi.clear_line(), end='', file=sys.stderr)
|
import colorama
|
||||||
sys.stderr.flush()
|
print(colorama.ansi.clear_line(), end='', file=sys.stderr)
|
||||||
|
# sys.stderr.flush()
|
||||||
|
self._progress_uncleared=False
|
||||||
|
|||||||
@ -157,8 +157,8 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
dataset.error("Error during thinning of missing datasets ({})".format(str(e)))
|
dataset.error("Error during thinning of missing datasets ({})".format(str(e)))
|
||||||
|
|
||||||
if self.args.progress:
|
# if self.args.progress:
|
||||||
self.clear_progress()
|
# self.clear_progress()
|
||||||
|
|
||||||
# NOTE: this method also uses self.args. args that need extra processing are passed as function parameters:
|
# NOTE: this method also uses self.args. args that need extra processing are passed as function parameters:
|
||||||
def destroy_missing_targets(self, target_dataset, used_target_datasets):
|
def destroy_missing_targets(self, target_dataset, used_target_datasets):
|
||||||
@ -217,13 +217,13 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
dataset.destroy(fail_exception=True)
|
dataset.destroy(fail_exception=True)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.args.progress:
|
# if self.args.progress:
|
||||||
self.clear_progress()
|
# self.clear_progress()
|
||||||
|
|
||||||
dataset.error("Error during --destroy-missing: {}".format(str(e)))
|
dataset.error("Error during --destroy-missing: {}".format(str(e)))
|
||||||
|
|
||||||
if self.args.progress:
|
# if self.args.progress:
|
||||||
self.clear_progress()
|
# self.clear_progress()
|
||||||
|
|
||||||
def get_send_pipes(self, logger):
|
def get_send_pipes(self, logger):
|
||||||
"""determine the zfs send pipe"""
|
"""determine the zfs send pipe"""
|
||||||
@ -333,8 +333,8 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
decrypt=self.args.decrypt, encrypt=self.args.encrypt,
|
decrypt=self.args.decrypt, encrypt=self.args.encrypt,
|
||||||
zfs_compressed=self.args.zfs_compressed)
|
zfs_compressed=self.args.zfs_compressed)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.args.progress:
|
# if self.args.progress:
|
||||||
self.clear_progress()
|
# self.clear_progress()
|
||||||
|
|
||||||
fail_count = fail_count + 1
|
fail_count = fail_count + 1
|
||||||
source_dataset.error("FAILED: " + str(e))
|
source_dataset.error("FAILED: " + str(e))
|
||||||
@ -342,8 +342,8 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
self.verbose("Debug mode, aborting on first error")
|
self.verbose("Debug mode, aborting on first error")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if self.args.progress:
|
# if self.args.progress:
|
||||||
self.clear_progress()
|
# self.clear_progress()
|
||||||
|
|
||||||
target_path_dataset = target_node.get_dataset(self.args.target_path)
|
target_path_dataset = target_node.get_dataset(self.args.target_path)
|
||||||
if not self.args.no_thinning:
|
if not self.args.no_thinning:
|
||||||
@ -477,6 +477,7 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
self.verbose("")
|
self.verbose("")
|
||||||
self.warning("TEST MODE - DID NOT MAKE ANY CHANGES!")
|
self.warning("TEST MODE - DID NOT MAKE ANY CHANGES!")
|
||||||
|
|
||||||
|
self.clear_progress()
|
||||||
return fail_count
|
return fail_count
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -203,8 +203,8 @@ class ZfsAutoverify(ZfsAuto):
|
|||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.args.progress:
|
# if self.args.progress:
|
||||||
self.clear_progress()
|
# self.clear_progress()
|
||||||
|
|
||||||
fail_count = fail_count + 1
|
fail_count = fail_count + 1
|
||||||
target_dataset.error("FAILED: " + str(e))
|
target_dataset.error("FAILED: " + str(e))
|
||||||
@ -212,8 +212,8 @@ class ZfsAutoverify(ZfsAuto):
|
|||||||
self.verbose("Debug mode, aborting on first error")
|
self.verbose("Debug mode, aborting on first error")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if self.args.progress:
|
# if self.args.progress:
|
||||||
self.clear_progress()
|
# self.clear_progress()
|
||||||
|
|
||||||
return fail_count
|
return fail_count
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user