mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-06-01 01:20:58 +03:00
automatic enable --progress on tty's. added stderr/out flushing to get syncronised logfiles. send progress actually to stderr
This commit is contained in:
parent
8a960389d1
commit
002aa6a731
@ -40,6 +40,7 @@ class Log:
|
|||||||
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:
|
||||||
print("! "+txt, file=sys.stderr)
|
print("! "+txt, file=sys.stderr)
|
||||||
|
sys.stderr.flush()
|
||||||
|
|
||||||
def verbose(self, txt):
|
def verbose(self, txt):
|
||||||
if self.show_verbose:
|
if self.show_verbose:
|
||||||
@ -47,6 +48,7 @@ class Log:
|
|||||||
print(colorama.Style.NORMAL+ " "+txt+colorama.Style.RESET_ALL)
|
print(colorama.Style.NORMAL+ " "+txt+colorama.Style.RESET_ALL)
|
||||||
else:
|
else:
|
||||||
print(" "+txt)
|
print(" "+txt)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
def debug(self, txt):
|
def debug(self, txt):
|
||||||
if self.show_debug:
|
if self.show_debug:
|
||||||
@ -54,6 +56,7 @@ class Log:
|
|||||||
print(colorama.Fore.GREEN+ "# "+txt+colorama.Style.RESET_ALL)
|
print(colorama.Fore.GREEN+ "# "+txt+colorama.Style.RESET_ALL)
|
||||||
else:
|
else:
|
||||||
print("# "+txt)
|
print("# "+txt)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1317,8 +1320,8 @@ class ZfsNode(ExecuteNode):
|
|||||||
bytes_left=self._progress_total_bytes-bytes
|
bytes_left=self._progress_total_bytes-bytes
|
||||||
minutes_left=int((bytes_left/(bytes/(time.time()-self._progress_start_time)))/60)
|
minutes_left=int((bytes_left/(bytes/(time.time()-self._progress_start_time)))/60)
|
||||||
|
|
||||||
print(">>> {}% {}MB/s (total {}MB, {} minutes left) \r".format(percentage, speed, int(self._progress_total_bytes/(1024*1024)), minutes_left), end='')
|
print(">>> {}% {}MB/s (total {}MB, {} minutes left) \r".format(percentage, speed, int(self._progress_total_bytes/(1024*1024)), minutes_left), end='', file=sys.stderr)
|
||||||
sys.stdout.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1480,13 +1483,16 @@ class ZfsAutobackup:
|
|||||||
parser.add_argument('--verbose', action='store_true', help='verbose output')
|
parser.add_argument('--verbose', action='store_true', help='verbose output')
|
||||||
parser.add_argument('--debug', action='store_true', help='Show zfs commands that are executed, stops after an exception.')
|
parser.add_argument('--debug', action='store_true', help='Show zfs commands that are executed, stops after an exception.')
|
||||||
parser.add_argument('--debug-output', action='store_true', help='Show zfs commands and their output/exit codes. (noisy)')
|
parser.add_argument('--debug-output', action='store_true', help='Show zfs commands and their output/exit codes. (noisy)')
|
||||||
parser.add_argument('--progress', action='store_true', help='show zfs progress output (to stderr)')
|
parser.add_argument('--progress', action='store_true', help='show zfs progress output (to stderr). Enabled by default on ttys.')
|
||||||
|
|
||||||
#note args is the only global variable we use, since its a global readonly setting anyway
|
#note args is the only global variable we use, since its a global readonly setting anyway
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
self.args=args
|
self.args=args
|
||||||
|
|
||||||
|
if sys.stderr.isatty():
|
||||||
|
args.progress=True
|
||||||
|
|
||||||
if args.debug_output:
|
if args.debug_output:
|
||||||
args.debug=True
|
args.debug=True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user