3
pcp.py - this file is part of S3QL (http://s3ql.googlecode.com)
5
Parallel, recursive copy of directory trees.
8
Copyright (C) 2010 Nikolaus Rath <Nikolaus@rath.org>
10
This program can be distributed under the terms of the GNU LGPL.
13
from __future__ import division, print_function, absolute_import
20
# We are running from the S3QL source directory, make sure
21
# that we use modules from this directory
22
basedir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
23
if (os.path.exists(os.path.join(basedir, 'setup.py')) and
24
os.path.exists(os.path.join(basedir, 'src', 's3ql', '__init__.py'))):
25
sys.path = [os.path.join(basedir, 'src')] + sys.path
27
from s3ql.common import (setup_logging)
28
from s3ql.parse_args import ArgumentParser
30
log = logging.getLogger('pcp')
33
'''Parse command line'''
35
parser = ArgumentParser(
36
description='Recursively copy source(s) to destination using multiple '
37
'parallel rsync processes.')
43
parser.add_argument("-a", action="store_true",
44
help='Pass -aHAX option to rsync.')
45
parser.add_argument("--processes", action="store", type=int, metavar='<no>',
47
help='Number of rsync processes to use (default: %(default)s).')
49
parser.add_argument('source', metavar='<source>', nargs='+',
50
help='Directories to copy')
51
parser.add_argument('dest', metavar='<destination>',
52
help="Target directory")
54
options = parser.parse_args(args)
55
options.pps = options.source + [ options.dest ]
63
options = parse_args(args)
64
setup_logging(options)
66
pool = ( 'abcdefghijklmnopqrstuvwxyz',
67
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
69
steps = [ len(x) / (options.processes-1) for x in pool ]
71
for i in range(options.processes - 1):
72
parts = [ x[int(i*y):int((i+1)*y)] for (x, y) in zip(pool, steps) ]
73
prefixes.append(''.join(parts))
75
filters = [ '-! [%s]*' % x for x in prefixes ]
78
filters.append( '- [%s]*' % ''.join(prefixes))
80
rsync_args = [ 'rsync', '-f', '+ */' ]
82
rsync_args.append('--out-format')
83
rsync_args.append('%n%L')
85
rsync_args.append('-aHAX')
88
for filter_ in filters:
89
cmd = rsync_args + [ '-f', filter_ ] + options.pps
90
log.debug('Calling %s', cmd)
91
processes.append(subprocess.Popen(cmd))
93
if all([ c.wait() == 0 for c in processes]):
99
if __name__ == '__main__':
b'\\ No newline at end of file'