mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-11 22:40:01 +03:00
cleaner progress clearing
This commit is contained in:
parent
f4e81bddb7
commit
0c6c75bf58
@ -10,6 +10,7 @@ class LogConsole:
|
||||
self.last_log = ""
|
||||
self.show_debug = show_debug
|
||||
self.show_verbose = show_verbose
|
||||
self._progress_uncleared=False
|
||||
|
||||
if color:
|
||||
# try to use color, failback if colorama not available
|
||||
@ -25,6 +26,7 @@ class LogConsole:
|
||||
self.colorama=False
|
||||
|
||||
def error(self, txt):
|
||||
self.clear_progress()
|
||||
if self.colorama:
|
||||
print(colorama.Fore.RED + colorama.Style.BRIGHT + "! " + txt + colorama.Style.RESET_ALL, file=sys.stderr)
|
||||
else:
|
||||
@ -32,6 +34,7 @@ class LogConsole:
|
||||
sys.stderr.flush()
|
||||
|
||||
def warning(self, txt):
|
||||
self.clear_progress()
|
||||
if self.colorama:
|
||||
print(colorama.Fore.YELLOW + colorama.Style.BRIGHT + " NOTE: " + txt + colorama.Style.RESET_ALL)
|
||||
else:
|
||||
@ -40,6 +43,7 @@ class LogConsole:
|
||||
|
||||
def verbose(self, txt):
|
||||
if self.show_verbose:
|
||||
self.clear_progress()
|
||||
if self.colorama:
|
||||
print(colorama.Style.NORMAL + " " + txt + colorama.Style.RESET_ALL)
|
||||
else:
|
||||
@ -48,6 +52,7 @@ class LogConsole:
|
||||
|
||||
def debug(self, txt):
|
||||
if self.show_debug:
|
||||
self.clear_progress()
|
||||
if self.colorama:
|
||||
print(colorama.Fore.GREEN + "# " + txt + colorama.Style.RESET_ALL)
|
||||
else:
|
||||
@ -57,10 +62,13 @@ class LogConsole:
|
||||
def progress(self, txt):
|
||||
"""print progress output to stderr (stays on same line)"""
|
||||
self.clear_progress()
|
||||
self._progress_uncleared=True
|
||||
print(">>> {}\r".format(txt), end='', file=sys.stderr)
|
||||
sys.stderr.flush()
|
||||
|
||||
def clear_progress(self):
|
||||
import colorama
|
||||
print(colorama.ansi.clear_line(), end='', file=sys.stderr)
|
||||
sys.stderr.flush()
|
||||
if self._progress_uncleared:
|
||||
import colorama
|
||||
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:
|
||||
dataset.error("Error during thinning of missing datasets ({})".format(str(e)))
|
||||
|
||||
if self.args.progress:
|
||||
self.clear_progress()
|
||||
# if self.args.progress:
|
||||
# self.clear_progress()
|
||||
|
||||
# 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):
|
||||
@ -217,13 +217,13 @@ class ZfsAutobackup(ZfsAuto):
|
||||
dataset.destroy(fail_exception=True)
|
||||
|
||||
except Exception as e:
|
||||
if self.args.progress:
|
||||
self.clear_progress()
|
||||
# if self.args.progress:
|
||||
# self.clear_progress()
|
||||
|
||||
dataset.error("Error during --destroy-missing: {}".format(str(e)))
|
||||
|
||||
if self.args.progress:
|
||||
self.clear_progress()
|
||||
# if self.args.progress:
|
||||
# self.clear_progress()
|
||||
|
||||
def get_send_pipes(self, logger):
|
||||
"""determine the zfs send pipe"""
|
||||
@ -333,8 +333,8 @@ class ZfsAutobackup(ZfsAuto):
|
||||
decrypt=self.args.decrypt, encrypt=self.args.encrypt,
|
||||
zfs_compressed=self.args.zfs_compressed)
|
||||
except Exception as e:
|
||||
if self.args.progress:
|
||||
self.clear_progress()
|
||||
# if self.args.progress:
|
||||
# self.clear_progress()
|
||||
|
||||
fail_count = fail_count + 1
|
||||
source_dataset.error("FAILED: " + str(e))
|
||||
@ -342,8 +342,8 @@ class ZfsAutobackup(ZfsAuto):
|
||||
self.verbose("Debug mode, aborting on first error")
|
||||
raise
|
||||
|
||||
if self.args.progress:
|
||||
self.clear_progress()
|
||||
# if self.args.progress:
|
||||
# self.clear_progress()
|
||||
|
||||
target_path_dataset = target_node.get_dataset(self.args.target_path)
|
||||
if not self.args.no_thinning:
|
||||
@ -477,6 +477,7 @@ class ZfsAutobackup(ZfsAuto):
|
||||
self.verbose("")
|
||||
self.warning("TEST MODE - DID NOT MAKE ANY CHANGES!")
|
||||
|
||||
self.clear_progress()
|
||||
return fail_count
|
||||
|
||||
except Exception as e:
|
||||
|
@ -203,8 +203,8 @@ class ZfsAutoverify(ZfsAuto):
|
||||
|
||||
|
||||
except Exception as e:
|
||||
if self.args.progress:
|
||||
self.clear_progress()
|
||||
# if self.args.progress:
|
||||
# self.clear_progress()
|
||||
|
||||
fail_count = fail_count + 1
|
||||
target_dataset.error("FAILED: " + str(e))
|
||||
@ -212,8 +212,8 @@ class ZfsAutoverify(ZfsAuto):
|
||||
self.verbose("Debug mode, aborting on first error")
|
||||
raise
|
||||
|
||||
if self.args.progress:
|
||||
self.clear_progress()
|
||||
# if self.args.progress:
|
||||
# self.clear_progress()
|
||||
|
||||
return fail_count
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user