summaryrefslogtreecommitdiff
path: root/dupfiles
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-04-18 08:21:18 +1200
committerLars Wirzenius <liw@liw.fi>2010-04-18 08:21:18 +1200
commitc67d8ec2f2ca1523c4782287c40cd1a5e5953a4b (patch)
tree9b7d4356a3a4e33a40b97ea68b70a38665e5fb4f /dupfiles
parent5446c802c3ca0c751b3c49488f61fa315d9700a5 (diff)
downloaddupfiles-c67d8ec2f2ca1523c4782287c40cd1a5e5953a4b.tar.gz
Provide some progress reporting for the collection phase.
Diffstat (limited to 'dupfiles')
-rwxr-xr-xdupfiles37
1 files changed, 33 insertions, 4 deletions
diff --git a/dupfiles b/dupfiles
index 950c170..039ecdd 100755
--- a/dupfiles
+++ b/dupfiles
@@ -21,15 +21,40 @@ import hashlib
import optparse
import os
import sys
+import time
+
+
+class ProgressReporter(object):
+
+ def __init__(self, do_report):
+ self.written = ''
+ self.when = 0
+ self.do_report = do_report
+
+ def write(self, msg):
+ if self.do_report and time.time() - self.when >= 1:
+ sys.stdout.flush()
+ sys.stderr.write('\b \b' * len(self.written))
+ msg = msg[:79] # FIXME: use real screen width
+ sys.stderr.write(msg)
+ sys.stderr.flush()
+ self.written = msg
+ self.when = time.time()
+
+ def finished(self):
+ self.write('')
class DuplicateFileFinder(object):
- def __init__(self):
+ def __init__(self, progress):
self.by_size = dict()
+ self.progress = progress
def collect(self, root):
for dirname, subdirs, filenames in os.walk(root):
+ self.progress.write(dirname)
+ subdirs.sort()
pathnames = [os.path.join(dirname, f) for f in filenames]
for pathname in pathnames:
stat = os.stat(pathname)
@@ -40,6 +65,7 @@ class DuplicateFileFinder(object):
else:
self.by_size[stat.st_size] = (stat.st_dev, stat.st_ino,
set([pathname]))
+ self.progress.finished()
def duplicates(self):
for dev, ino, pathnames in self.by_size.itervalues():
@@ -66,18 +92,21 @@ def make_hardlinks(duplicates):
def report(duplicates):
sys.stdout.write('\n'.join(duplicates))
- sys.stdout.write('\n')
+ sys.stdout.write('\n\n')
def main():
parser = optparse.OptionParser()
parser.add_option('--make-hardlinks', action='store_true',
help='hardlink duplicate files to each other')
+ parser.add_option('--progress', action='store_true',
+ help='report progress')
opts, args = parser.parse_args()
- dupfinder = DuplicateFileFinder()
- for dirname in args:
+ progress = ProgressReporter(opts.progress)
+ dupfinder = DuplicateFileFinder(progress)
+ for dirname in sorted(args):
dupfinder.collect(dirname)
for duplicates in dupfinder.duplicates():
if opts.make_hardlinks: