]> arthur.barton.de Git - bup.git/blobdiff - cmd/midx-cmd.py
Add bup prune-older command
[bup.git] / cmd / midx-cmd.py
index a18707d8b3eb6a0e9dcb37a1cfdc053de0844990..8e0b87e1d948bf836b58c2b8d65e57122c00dda1 100755 (executable)
@@ -1,8 +1,17 @@
-#!/usr/bin/env python
-import sys, math, struct, glob, resource
-import tempfile
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
+import glob, math, os, resource, struct, sys, tempfile
+
 from bup import options, git, midx, _helpers, xstat
-from bup.helpers import *
+from bup.helpers import (Sha1, add_error, atomically_replaced_file, debug1, fdatasync,
+                         handle_ctrl_c, log, mmap_readwrite, qprogress,
+                         saved_errors, unlink)
+
 
 PAGE_SIZE=4096
 SHA_PER_PAGE=PAGE_SIZE/20.
@@ -41,7 +50,7 @@ def check_midx(name):
     log('Checking %s.\n' % nicename)
     try:
         ix = git.open_idx(name)
-    except git.GitError, e:
+    except git.GitError as e:
         add_error('%s: %s' % (name, e))
         return
     for count,subname in enumerate(ix.idxnames):
@@ -157,7 +166,7 @@ def do_midx(outdir, outfilename, infilenames, prefixstr):
         print rv[1]
 
 
-def do_midx_dir(path):
+def do_midx_dir(path, outfilename):
     already = {}
     sizes = {}
     if opt.force and not opt.auto:
@@ -206,7 +215,7 @@ def do_midx_dir(path):
         all.sort()
         part1 = [name for sz,name in all[:len(all)-DESIRED_LWM+1]]
         part2 = all[len(all)-DESIRED_LWM+1:]
-        all = list(do_midx_group(path, part1)) + part2
+        all = list(do_midx_group(path, outfilename, part1)) + part2
         if len(all) > DESIRED_HWM:
             debug1('\nStill too many indexes (%d > %d).  Merging again.\n'
                    % (len(all), DESIRED_HWM))
@@ -217,13 +226,13 @@ def do_midx_dir(path):
                 print name
 
 
-def do_midx_group(outdir, infiles):
+def do_midx_group(outdir, outfilename, infiles):
     groups = list(_group(infiles, opt.max_files))
     gprefix = ''
     for n,sublist in enumerate(groups):
         if len(groups) != 1:
             gprefix = 'Group %d: ' % (n+1)
-        rv = _do_midx(path, None, sublist, gprefix)
+        rv = _do_midx(outdir, outfilename, sublist, gprefix)
         if rv:
             yield rv
 
@@ -265,7 +274,7 @@ else:
         paths = opt.dir and [opt.dir] or git.all_packdirs()
         for path in paths:
             debug1('midx: scanning %s\n' % path)
-            do_midx_dir(path)
+            do_midx_dir(path, opt.output)
     else:
         o.fatal("you must use -f or -a or provide input filenames")