36
self.check_src_symlinks = False
37
self.check_dst_symlinks = False
38
self.check_dst_ignores = False
41
37
def process( self, rel_file, src, dst ):
44
if self.check_dst_ignores and the.config.ignores.matches( rel_file ):
46
self.print_op( rel_file, '%s#%s' % ( src.type, dst.type ) )
49
39
# src entity is directory
50
40
if src.type == 'd':
52
42
# if dst entity doesn't exist, create directory (no need to recurse,
53
43
# since we're copying the whole directory)
54
44
if dst.type == '_':
55
if the.verbose >= 2: self.print_op( rel_file, 'd>_' )
45
if the.verbose > 1: self.print_op( rel_file, 'd>_' )
56
46
shutil.copytree( src.file, dst.file, True )
58
48
# if dst entity is a directory, copy permissions, as required (and
60
50
elif dst.type == 'd':
61
51
# TODO: should check permission and only do as necessary
62
if the.verbose >= 2: self.print_op( rel_file, 'd>d' )
52
if the.verbose > 1: self.print_op( rel_file, 'd>d' )
63
53
shutil.copystat( src.file, dst.file )
66
56
# if dst entity is a symlink to a directory, and this is an
67
57
# acceptable substitute, just recurse
68
elif self.check_dst_symlinks and dst.link_type == 'd' and \
69
the.config.symlinks.matches( rel_file ):
70
if the.verbose >= 2: self.print_op( rel_file, 'd@d' )
58
elif dst.link_type == 'd' and \
59
self.accept_list and self.accept_list.match( rel_file ):
60
if the.verbose > 1: self.print_op( rel_file, 'd@d' )
73
63
# if dst entity is a file or symlink in home dir, replace it with
74
64
# directory (no need to recurse, since we're copying the whole
76
66
elif dst.type == 'f' or dst.type == 'l':
77
if the.verbose >= 2: self.print_op( rel_file, 'd>' + dst.type )
67
if the.verbose > 1: self.print_op( rel_file, 'd>' + dst.type )
78
68
os.unlink( dst.file )
79
69
shutil.copytree( src.file, dst.file, True )
87
77
# if dst entity doesn't exist, copy file
88
78
if dst.type == '_':
89
if the.verbose >= 2: self.print_op( rel_file, 'f>_' )
79
if the.verbose > 1: self.print_op( rel_file, 'f>_' )
90
80
shutil.copy( src.file, dst.file )
91
81
shutil.copystat( src.file, dst.file )
93
83
# if dst entity is a file, replace it only if it differs
94
84
elif dst.type == 'f':
95
85
if not filecmp.cmp( src.file, dst.file ):
96
if the.verbose >= 2: self.print_op( rel_file, 'f>f' )
86
if the.verbose > 1: self.print_op( rel_file, 'f>f' )
97
87
os.unlink( dst.file )
98
88
shutil.copy( src.file, dst.file )
99
89
shutil.copystat( src.file, dst.file )
101
if the.verbose >= 2: self.print_op( rel_file, 'f=f' )
91
if the.verbose > 1: self.print_op( rel_file, 'f=f' )
103
93
# if dst entity is a directory, replace it with file
104
94
elif dst.type == 'd':
105
if the.verbose >= 2: self.print_op( rel_file, 'f>d' )
95
if the.verbose > 1: self.print_op( rel_file, 'f>d' )
106
96
shutil.rmtree( dst.file )
107
97
shutil.copy( src.file, dst.file )
108
98
shutil.copystat( src.file, dst.file )
110
100
# if dst entity is a symlink, replace it with file
111
101
elif dst.type == 'l':
112
if the.verbose >= 2: self.print_op( rel_file, 'f>l' )
102
if the.verbose > 1: self.print_op( rel_file, 'f>l' )
113
103
os.unlink( dst.file )
114
104
shutil.copy( src.file, dst.file )
115
105
shutil.copystat( src.file, dst.file )
123
113
# if dst entity doesn't exist, copy symlink
124
114
if dst.type == '_':
125
if the.verbose >= 2: self.print_op( rel_file, 'l>_' )
115
if the.verbose > 1: self.print_op( rel_file, 'l>_' )
126
116
os.symlink( os.readlink( src.file ), dst.file )
128
118
# if dst entity is a symlink, replace it only if it differs
129
119
elif dst.type == 'l':
130
120
if os.readlink( src.file ) != os.readlink( dst.file ):
131
if the.verbose >= 2: self.print_op( rel_file, 'l>l' )
121
if the.verbose > 1: self.print_op( rel_file, 'l>l' )
132
122
os.unlink( dst.file )
133
123
os.symlink( os.readlink( src.file ), dst.file )
135
if the.verbose >= 2: self.print_op( rel_file, 'l=l' )
125
if the.verbose > 1: self.print_op( rel_file, 'l=l' )
137
127
# if dst entity is a file, replace it with symlink
138
128
elif dst.type == 'f':
139
if the.verbose >= 2: self.print_op( rel_file, 'l>f' )
129
if the.verbose > 1: self.print_op( rel_file, 'l>f' )
140
130
os.unlink( dst.file )
141
131
os.symlink( os.readlink( src.file ), dst.file )
143
# if dst entity is a directory...
133
# if dst entity is a directory, and src entity is a symlink to a
134
# directory, and this is an acceptable substitute, just recurse
135
elif dst.type == 'd' and src.link_type == 'd' and \
136
self.accept_list and self.accept_list.match( rel_file ):
137
if the.verbose > 1: self.print_op( rel_file, 'd@d' )
140
# if dst entity is a directory, replace it with symlink
144
141
elif dst.type == 'd':
146
# if src entity is a symlink to a directory, and this is an
147
# acceptable substitute, just recurse
148
if self.check_src_symlinks and src.link_type == 'd' and \
149
the.config.symlinks.matches( rel_file ):
150
if the.verbose >= 2: self.print_op( rel_file, 'd@d' )
153
# else replace it with a symlink
154
if the.verbose >= 2: self.print_op( rel_file, 'l>d' )
142
if the.verbose > 1: self.print_op( rel_file, 'l>d' )
155
143
shutil.rmtree( dst.file )
156
144
os.symlink( os.readlink( src.file ), dst.file )
168
156
# if dst entity is a file or symlink, delete it
169
157
elif dst.type == 'f' or dst.type == 'l':
170
if the.verbose >= 2: self.print_op( rel_file, '_>' + dst.type )
158
if the.verbose > 1: self.print_op( rel_file, '_>' + dst.type )
171
159
os.unlink( dst.file )
173
161
# if dst entity is a directory, delete it
174
162
elif dst.type == 'd':
175
if the.verbose >= 2: self.print_op( rel_file, '_>d' )
163
if the.verbose > 1: self.print_op( rel_file, '_>d' )
176
164
shutil.rmtree( dst.file )