Browse code

Return SSH return code, be silent for SSH errors if not a terminal

Lorenz Hüdepohl authored on 05/12/2017 19:55:42
Showing 1 changed files
... ...
@@ -50,8 +50,8 @@ parser.add_argument('-n', '--dry-run', action="store_true",
50 50
                          'do not actually send anything.')
51 51
 
52 52
 parser.add_argument('-F', '--force', action="store_true",
53
-                    help='Pass `-F` to `zfs receive` to Only echo the transfer commands that would be issued,\n'
54
-                         'do not actually send anything.')
53
+                    help='Pass `-F` to `zfs receive` to overwrite other '
54
+                         'snapshots or diverged changes on the remote side\n')
55 55
 
56 56
 args = parser.parse_args()
57 57
 args.verbose = sum(args.verbose) if args.verbose is not None else 0
... ...
@@ -62,10 +62,11 @@ if not args.cache_dir and args.min_cache_size is not None:
62 62
 elif args.cache_dir and args.min_cache_size is None:
63 63
     args.min_cache_size = "50M"
64 64
 
65
-def check_returncode(proc):
65
+def check_returncode(proc, verbose=True):
66 66
     if not proc.returncode == 0:
67
-        print("\nCommand \"{0}\" returned error {1}, aborting...".format(" ".join(proc.args), proc.returncode), file=sys.stderr)
68
-        raise SystemExit(1)
67
+        if verbose:
68
+            print("\nCommand \"{0}\" returned error {1}, aborting...".format(" ".join(proc.args), proc.returncode), file=sys.stderr)
69
+        raise SystemExit(proc.returncode)
69 70
 
70 71
 
71 72
 def select_snapshots(proc, prefix):
... ...
@@ -89,7 +90,7 @@ def select_snapshots(proc, prefix):
89 90
     if proc.returncode == 1:
90 91
         if proc.stderr.read().endswith(b"dataset does not exist\n"):
91 92
             return []
92
-    check_returncode(proc)
93
+    check_returncode(proc, verbose=os.isatty(2))
93 94
     return res
94 95
 
95 96