1
+ """Classes allowing copying files around.
2
+
3
+ "Syncers" copy files from the local machine, while "Pullers" copy files to
4
+ the local machine.
5
+
6
+ """
1
7
import getpass
2
8
import logging
3
9
import os
11
17
class LocalSyncer (object ):
12
18
13
19
@classmethod
14
- def copy (cls , path , target , file = False , ** kwargs ):
20
+ def copy (cls , path , target , is_file = False , ** __ ):
15
21
"""A copy command that works with files or directories."""
16
- log .info ("Local Copy %s to %s" % ( path , target ) )
17
- if file :
22
+ log .info ("Local Copy %s to %s" , path , target )
23
+ if is_file :
18
24
if path == target :
19
25
# Don't copy the same file over itself
20
26
return
@@ -30,7 +36,7 @@ def copy(cls, path, target, file=False, **kwargs):
30
36
class RemoteSyncer (object ):
31
37
32
38
@classmethod
33
- def copy (cls , path , target , file = False , ** kwargs ):
39
+ def copy (cls , path , target , is_file = False , ** __ ):
34
40
"""
35
41
A better copy command that works with files or directories.
36
42
@@ -39,14 +45,14 @@ def copy(cls, path, target, file=False, **kwargs):
39
45
sync_user = getattr (settings , 'SYNC_USER' , getpass .getuser ())
40
46
app_servers = getattr (settings , 'MULTIPLE_APP_SERVERS' , [])
41
47
if app_servers :
42
- log .info ("Remote Copy %s to %s" % ( path , target ) )
48
+ log .info ("Remote Copy %s to %s on %s" , path , target , app_servers )
43
49
for server in app_servers :
44
50
mkdir_cmd = ("ssh %s@%s mkdir -p %s" % (sync_user , server , target ))
45
51
ret = os .system (mkdir_cmd )
46
52
if ret != 0 :
47
53
log .info ("COPY ERROR to app servers:" )
48
54
log .info (mkdir_cmd )
49
- if file :
55
+ if is_file :
50
56
slash = ""
51
57
else :
52
58
slash = "/"
@@ -68,19 +74,19 @@ def copy(cls, path, target, file=False, **kwargs):
68
74
class DoubleRemotePuller (object ):
69
75
70
76
@classmethod
71
- def copy (cls , path , target , host , file = False , ** kwargs ):
77
+ def copy (cls , path , target , host , is_file = False , ** __ ):
72
78
"""
73
79
A better copy command that works from the webs.
74
80
75
81
Respects the ``MULTIPLE_APP_SERVERS`` setting when copying.
76
82
"""
77
83
sync_user = getattr (settings , 'SYNC_USER' , getpass .getuser ())
78
84
app_servers = getattr (settings , 'MULTIPLE_APP_SERVERS' , [])
79
- if not file :
85
+ if not is_file :
80
86
path += "/"
81
- log .info ("Remote Copy %s to %s" % ( path , target ) )
87
+ log .info ("Remote Copy %s to %s" , path , target )
82
88
for server in app_servers :
83
- if not file :
89
+ if not is_file :
84
90
mkdir_cmd = "ssh {user}@{server} mkdir -p {target}" .format (
85
91
user = sync_user , server = server , target = target
86
92
)
@@ -106,16 +112,16 @@ def copy(cls, path, target, host, file=False, **kwargs):
106
112
class RemotePuller (object ):
107
113
108
114
@classmethod
109
- def copy (cls , path , target , host , file = False , ** kwargs ):
115
+ def copy (cls , path , target , host , is_file = False , ** __ ):
110
116
"""
111
117
A better copy command that works from the webs.
112
118
113
119
Respects the ``MULTIPLE_APP_SERVERS`` setting when copying.
114
120
"""
115
121
sync_user = getattr (settings , 'SYNC_USER' , getpass .getuser ())
116
- if not file :
122
+ if not is_file :
117
123
path += "/"
118
- log .info ("Local Copy %s to %s" % ( path , target ) )
124
+ log .info ("Local Copy %s to %s" , path , target )
119
125
os .makedirs (target )
120
126
# Add a slash when copying directories
121
127
sync_cmd = "rsync -e 'ssh -T' -av --delete {user}@{host}:{path} {target}" .format (
0 commit comments