aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2013-01-05 21:20:29 +0100
committerLaurent Bachelier <laurent@bachelier.name>2013-01-05 21:20:29 +0100
commit4ef250b0b6e5ff56f6ab4f43f812c2da0e4c7fda (patch)
tree480a9f4b64f8aca0a58f19d583dac31db9d977c3
parentIgnore broken FLAC files (diff)
downloadbrutha-4ef250b0b6e5ff56f6ab4f43f812c2da0e4c7fda.tar.xz
Display a line every 200 dirs
For huge collection this helps user know what is going on. As with the line before execution, it's on stderr, while the command output is in stdout (or a pipe).
-rw-r--r--brutha/__main__.py7
-rw-r--r--brutha/tree.py11
2 files changed, 15 insertions, 3 deletions
diff --git a/brutha/__main__.py b/brutha/__main__.py
index e5c3666..b917690 100644
--- a/brutha/__main__.py
+++ b/brutha/__main__.py
@@ -39,9 +39,12 @@ def main():
parser.add_argument('dest', help='Destination directory', metavar='DESTINATION')
args = parser.parse_args()
+ log = sys.stderr
tree = Tree(args.src, args.dest,
{'quality': args.quality, 'gain': args.gain, 'delete': args.delete,
- 'maxrate': args.maxrate, 'maxbits': args.maxbits, 'lossycheck': args.lossycheck})
+ 'maxrate': args.maxrate, 'maxbits': args.maxbits,
+ 'lossycheck': args.lossycheck},
+ log)
if args.execute:
stream = StringIO()
else:
@@ -51,7 +54,7 @@ def main():
out.write(tree.commands(), stream)
if args.execute:
- print >>sys.stderr, 'Synchronizing %s to %s, using %s concurrent jobs.' % (args.src, args.dest, jobs)
+ print >>log, 'Synchronizing %s to %s, using %s concurrent jobs.' % (args.src, args.dest, jobs)
sys.exit(out.run(stream))
diff --git a/brutha/tree.py b/brutha/tree.py
index 66bbc62..8ca6d56 100644
--- a/brutha/tree.py
+++ b/brutha/tree.py
@@ -7,7 +7,7 @@ from brutha.util import escape
class Tree(object):
- def __init__(self, path, destpath, options=None):
+ def __init__(self, path, destpath, options=None, log=None):
assert os.path.isdir(path)
self.path = path
self.destpath = destpath
@@ -15,11 +15,16 @@ class Tree(object):
'maxrate': None, 'maxbits': None, 'lossycheck': True}
if options:
self.options.update(options)
+ self.log = log
def commands(self):
commands = []
wanted = []
+ num = 0
for root, dirs, files in os.walk(self.path, followlinks=True):
+ num += 1
+ if not num % 200:
+ self.progress(num)
relpath = os.path.relpath(root, self.path)
if relpath != '.':
destpath = os.path.join(self.destpath, relpath)
@@ -52,3 +57,7 @@ class Tree(object):
f = os.path.join(root, f)
if f not in wanted:
yield 'rm -v %s' % escape(f)
+
+ def progress(self, num):
+ if self.log:
+ print >>self.log, "%s directories processed..." % num