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