1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """C{copyto [-rpC] -c CLUSTER FILE ... REMOTE_DIR}
19
20 Copies C{FILE}s to C{REMOTE_DIR} on each node of the specified
21 C{CLUSTER}. If C{CLUSTER} is omitted, then the default cluster is
22 used.
23
24 C{REMOTE_DIR} must be an absolute path, (i.e. must begin with C{'/'}).
25
26 C{copyto} is implemented using C{scp}, and the following C{scp} flags
27 are supported:
28 - C{-C}: enable compression.
29 - C{-r}: recursive copy
30 - C{-p}: preserve modification times, access times, and modes.
31 """
32
33 import pickle
34 import threading
35
36 import osh.core
37 import osh.spawn
38
39 Spawn = osh.spawn.Spawn
40
41
44
45
46 -def copyto(cluster, files,
47 compress = False, recursive = False, preserve = False):
48 """Copies files to each node of the specified C{cluster}. The last elements
49 of C{files} is the target directory on each node. The preceding elements are
50 the local files to be copied. Compression is used for copying if C{compress}
51 is True. Directories are copied recursively if C{recursive} is
52 True. File attributes are preserved if C{preserve} is True.
53 """
54 if len(args) > 0:
55 cluster = args[0]
56 args = (osh.args.Option('-c', cluster),) + args[1:]
57 return _CopyTo().process_args(*args)
58
60
61
62
63 _remote_dir = None
64 _files = None
65 _scp_options = None
66
67
68
69
71 osh.core.RemoteOp.__init__(self, 'rpCc:', (2, None))
72
73
74
75
78
80 osh.core.RemoteOp.setup(self)
81 args = self._args.remaining()
82 if len(args) < 2:
83 self.usage()
84 self._remote_dir = args[-1]
85 if not self._remote_dir.startswith('/'):
86 self.usage()
87 self._files = args[:-1]
88 for option in osh.core.SCP_OPTIONS:
89 self._check_option(option)
90
91
92
93
95 _copyup(self._files,
96 self.user(),
97 host.address,
98 self._remote_dir,
99 self.scp_options())
100
101 -def _copyup(files, user, host, remote_dir, options = ''):
102 if isinstance(files, list) or isinstance(files, tuple):
103 files = ' '.join(files)
104 scp_command = 'scp %s %s %s@%s:%s' % (options, files, user, host, remote_dir)
105 Spawn(scp_command, None, None, None).run()
106