]> arthur.barton.de Git - bup.git/blobdiff - cmd/xstat-cmd.py
test-restore-map-owner: accommodate python 3 and test there
[bup.git] / cmd / xstat-cmd.py
index f299cbca7bf5a1ce12e745ad98a54f515c4fdd59..626b4c7e9d2f82476346c01184c21aab764457f8 100755 (executable)
@@ -4,14 +4,20 @@ bup_python="$(dirname "$0")/bup-python" || exit $?
 exec "$bup_python" "$0" ${1+"$@"}
 """
 # end of bup preamble
+
 # Copyright (C) 2010 Rob Browning
 #
 # This code is covered under the terms of the GNU Library General
 # Public License as described in the bup LICENSE file.
+
+from __future__ import absolute_import, print_function
 import sys, stat, errno
+
 from bup import metadata, options, xstat
-from bup.helpers import handle_ctrl_c, parse_timestamp, saved_errors, \
+from bup.compat import argv_bytes
+from bup.helpers import add_error, handle_ctrl_c, parse_timestamp, saved_errors, \
     add_error, log
+from bup.io import byte_stream
 
 
 def parse_timestamp_arg(field, value):
@@ -42,7 +48,7 @@ mtime-resolution=  limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
 ctime-resolution=  limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
 """
 
-target_filename = ''
+target_filename = b''
 active_fields = metadata.all_fields
 
 handle_ctrl_c()
@@ -78,8 +84,12 @@ opt.verbose = opt.verbose or 0
 opt.quiet = opt.quiet or 0
 metadata.verbose = opt.verbose - opt.quiet
 
+sys.stdout.flush()
+out = byte_stream(sys.stdout)
+
 first_path = True
 for path in remainder:
+    path = argv_bytes(path)
     try:
         m = metadata.from_path(path, archive_path = path)
     except (OSError,IOError) as e:
@@ -90,14 +100,15 @@ for path in remainder:
             raise
     if metadata.verbose >= 0:
         if not first_path:
-            print
+            out.write(b'\n')
         if atime_resolution != 1:
             m.atime = (m.atime / atime_resolution) * atime_resolution
         if mtime_resolution != 1:
             m.mtime = (m.mtime / mtime_resolution) * mtime_resolution
         if ctime_resolution != 1:
             m.ctime = (m.ctime / ctime_resolution) * ctime_resolution
-        print metadata.detailed_str(m, active_fields)
+        out.write(metadata.detailed_bytes(m, active_fields))
+        out.write(b'\n')
         first_path = False
 
 if saved_errors: