aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2017-03-28 00:00:40 +0200
committerLaurent Bachelier <laurent@bachelier.name>2017-03-28 00:00:40 +0200
commit0d00a5b20f22fc87240f33a21d8daed6c001ee91 (patch)
treec5336132cb16104b2d141a780d90820b0e20cab0
parentHuge speedup for the delete step on large collections (diff)
downloadbrutha-0d00a5b20f22fc87240f33a21d8daed6c001ee91.tar.xz
Use the modern print functionHEADmaster
-rw-r--r--brutha/__main__.py4
-rw-r--r--brutha/output.py37
-rw-r--r--brutha/tree.py8
-rw-r--r--brutha/util.py6
4 files changed, 23 insertions, 32 deletions
diff --git a/brutha/__main__.py b/brutha/__main__.py
index b839a59..428be7b 100644
--- a/brutha/__main__.py
+++ b/brutha/__main__.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
import argparse
import sys
@@ -68,7 +68,7 @@ def main():
out.write(tree.commands(), stream)
if args.execute:
- print >>log, "Synchronizing %s to %s, using %s concurrent jobs." % (args.src, args.dest, jobs)
+ print("Synchronizing %s to %s, using %s concurrent jobs." % (args.src, args.dest, jobs), file=log)
sys.exit(out.run(stream))
diff --git a/brutha/output.py b/brutha/output.py
index c350a3f..5de12db 100644
--- a/brutha/output.py
+++ b/brutha/output.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, division
+from __future__ import absolute_import, division, print_function
import subprocess
-from .util import require_executable, uprint
+from .util import require_executable
def pbar(cur, total, color=True):
@@ -56,30 +56,28 @@ class Shell(Shebang, Output):
NAME = 'sh'
def write(self, commands, stream):
- p = uprint(stream)
- p('#!%s' % require_executable('sh', ['bash', 'zsh', 'dash', 'sh']))
- p('set -eu')
+ print('#!%s' % require_executable('sh', ['bash', 'zsh', 'dash', 'sh']), file=stream)
+ print('set -eu', file=stream)
if self.echo:
- p('set -x')
+ print('set -x', file=stream)
for i, subcommands in enumerate(commands):
- p("\n".join(subcommands))
+ print("\n".join(subcommands), file=stream)
if self.echo:
- p('( set +x ; %s ) 2>/dev/null' % pbar(i+1, len(commands)))
+ print('( set +x ; %s ) 2>/dev/null' % pbar(i+1, len(commands)), file=stream)
else:
- p(pbar(i+1, len(commands)))
- p()
+ print(pbar(i+1, len(commands)), file=stream)
+ print(file=stream)
class Parallel(Shebang, Output):
NAME = 'parallel'
def write(self, commands, stream):
- p = uprint(stream)
verbose = ' --verbose' if self.echo else ''
jobs = ' --jobs %s' % self.jobs if self.jobs else ''
- p('#!%s --shebang --eta%s%s -- -' % (require_executable('parallel'), jobs, verbose))
+ print('#!%s --shebang --eta%s%s -- -' % (require_executable('parallel'), jobs, verbose), file=stream)
for i, subcommands in enumerate(commands):
- p(" && ".join(subcommands + [pbar(i+1, len(commands))]))
+ print(" && ".join(subcommands + [pbar(i+1, len(commands))]), file=stream)
class Make(Output):
@@ -89,17 +87,16 @@ class Make(Output):
return line.replace('$', '$$')
def write(self, commands, stream):
- p = uprint(stream)
prefix = '' if self.echo else '@'
targets = ' '.join('d%s' % i for i in xrange(0, len(commands)))
- p('.PHONY: all %s' % targets)
- p('all: %s' % targets)
- p()
+ print('.PHONY: all %s' % targets, file=stream)
+ print('all: %s' % targets, file=stream)
+ print(file=stream)
for i, subcommands in enumerate(commands):
- p('d%s:' % i)
+ print('d%s:' % i, file=stream)
for subcommand in subcommands:
- p('\t%s%s' % (prefix, self._escape(subcommand)))
- p('\t@%s' % pbar(i+1, len(commands)))
+ print('\t%s%s' % (prefix, self._escape(subcommand)), file=stream)
+ print('\t@%s' % pbar(i+1, len(commands)), file=stream)
def run(self, stream):
if self.jobs:
diff --git a/brutha/tree.py b/brutha/tree.py
index 3c0d830..2b7c2b0 100644
--- a/brutha/tree.py
+++ b/brutha/tree.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
import os
@@ -40,7 +40,7 @@ class Tree(object):
wanted = []
num = 0
if self.log:
- print >>self.log, "Walking source directory..."
+ print("Walking source directory...", file=self.log)
for root, dirs, files in os.walk(self.path, followlinks=True):
for dirname in [dirname for dirname in dirs if not self.allowed(root, dirname)]:
dirs.remove(dirname)
@@ -66,7 +66,7 @@ class Tree(object):
if self.options['delete']:
if self.log:
- print >>self.log, "Walking destination directory..."
+ print("Walking destination directory...", file=self.log)
c = list(self.delete(wanted))
if c:
commands.append(c)
@@ -90,4 +90,4 @@ class Tree(object):
def progress(self, num):
if self.log:
- print >>self.log, "%s directories processed..." % num
+ print("%s directories processed..." % num, file=self.log)
diff --git a/brutha/util.py b/brutha/util.py
index 1a44db5..d6a5c9e 100644
--- a/brutha/util.py
+++ b/brutha/util.py
@@ -16,12 +16,6 @@ def escape(x):
return s
-def uprint(stream):
- def p(text='', end='\n'):
- stream.write(text + end)
- return p
-
-
def find_executable(name, names=None):
envname = '%s_EXECUTABLE' % name.upper()
if names is None: