]> arthur.barton.de Git - bup.git/blobdiff - t/hardlink-sets
helpers.localtime: avoid floor-related deprecation warning
[bup.git] / t / hardlink-sets
index 653b4d2e682423d8d74541874bb25b6c6aabc731..2d17e37b4fa3d1eb8c47c27bc2ef1fe4bf9a7b9a 100755 (executable)
@@ -1,30 +1,53 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+bup_python="$(dirname "$0")/../dev/bup-python" || exit $?
+exec "$bup_python" "$0"
+"""
+# end of bup preamble
 
+from __future__ import absolute_import, print_function
 import os, stat, sys
 
+sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/../lib']
+
+from bup import compat
+from bup.io import byte_stream
+
+
 # Print the full paths of all the files in each hardlink set
 # underneath one of the paths.  Separate sets with a blank line, sort
 # the paths within each set, and sort the sets by their first path.
 
 def usage():
-    print >> sys.stderr, "Usage: hardlink-sets <paths ...>"
+    print("Usage: hardlink-sets <paths ...>", file=sys.stderr)
 
-if len(sys.argv) < 2:
+if len(compat.argv) < 2:
     usage()
     sys.exit(1)
 
 def on_walk_error(e):
     raise e
 
+sys.stdout.flush()
+out = byte_stream(sys.stdout)
+
 hardlink_set = {}
 
-for p in sys.argv[1:]:
+for p in compat.argvb[1:]:
   for root, dirs, files in os.walk(p, onerror = on_walk_error):
       for filename in files:
           full_path = os.path.join(root, filename)
           st = os.lstat(full_path)
           if not stat.S_ISDIR(st.st_mode):
-              node = '%s:%s' % (st.st_dev, st.st_ino)
+              node = b'%d:%d' % (st.st_dev, st.st_ino)
               link_paths = hardlink_set.get(node)
               if link_paths:
                   link_paths.append(full_path)
@@ -41,8 +64,8 @@ for link_paths in sorted(hardlink_set.values(), key = lambda x : x[0]):
         if first_set:
             first_set = False
         else:
-            print
+            out.write(b'\n')
         for p in sorted(link_paths):
-            print p
+            out.write(p + b'\n')
 
 sys.exit(0)