36
self.check_src_symlinks = False
37
self.check_dst_symlinks = False
38
self.check_dst_ignores = False
35
def __init__( self, updated_files = None ):
36
self.accept_list = FileMatcher()
41
39
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
41
# src entity is directory
50
42
if src.type == 'd':
52
44
# if dst entity doesn't exist, create directory (no need to recurse,
53
45
# since we're copying the whole directory)
54
46
if dst.type == '_':
55
if the.verbose >= 2: self.print_op( rel_file, 'd>_' )
56
shutil.copytree( src.file, dst.file, True )
47
if the.verbose > 1: self.print_cp( rel_file, 'd', '_' )
49
shutil.copystat( src.file, dst.file )
58
52
# if dst entity is a directory, copy permissions, as required (and
60
54
elif dst.type == 'd':
61
55
# TODO: should check permission and only do as necessary
62
if the.verbose >= 2: self.print_op( rel_file, 'd>d' )
56
if the.verbose > 1: self.print_cp( rel_file, 'd', 'd' )
63
57
shutil.copystat( src.file, dst.file )
66
# if dst entity is a symlink to a directory, and this is an
67
# 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' )
60
# TODO: if dst entity is a symlink to a directory, and rel_file is
61
# matched by the acceptable symlinks file matcher, just recurse
62
# elif dst.link_type == 'd' and self.accept_list.match( rel_file ):
63
# if the.verbose > 1: self.print_cp( rel_file, 'd', 'd', '@' )
73
66
# if dst entity is a file or symlink in home dir, replace it with
74
67
# directory (no need to recurse, since we're copying the whole
76
69
elif dst.type == 'f' or dst.type == 'l':
77
if the.verbose >= 2: self.print_op( rel_file, 'd>' + dst.type )
70
if the.verbose > 1: self.print_cp( rel_file, 'd', dst.type )
78
71
os.unlink( dst.file )
79
shutil.copytree( src.file, dst.file, True )
73
shutil.copystat( src.file, dst.file )
82
77
raise NotImplementedError()
84
79
# src entity is file
87
82
# if dst entity doesn't exist, copy file
88
83
if dst.type == '_':
89
if the.verbose >= 2: self.print_op( rel_file, 'f>_' )
84
if the.verbose > 1: self.print_cp( rel_file, 'f', '_' )
90
85
shutil.copy( src.file, dst.file )
91
86
shutil.copystat( src.file, dst.file )
93
88
# if dst entity is a file, replace it only if it differs
94
89
elif dst.type == 'f':
95
90
if not filecmp.cmp( src.file, dst.file ):
96
if the.verbose >= 2: self.print_op( rel_file, 'f>f' )
91
if the.verbose > 1: self.print_cp( rel_file, 'f', 'f' )
97
92
os.unlink( dst.file )
98
93
shutil.copy( src.file, dst.file )
99
94
shutil.copystat( src.file, dst.file )
101
if the.verbose >= 2: self.print_op( rel_file, 'f=f' )
96
if the.verbose > 1: self.print_cp( rel_file, 'f', 'f', '=' )
103
98
# if dst entity is a directory, replace it with file
104
99
elif dst.type == 'd':
105
if the.verbose >= 2: self.print_op( rel_file, 'f>d' )
100
if the.verbose > 1: self.print_cp( rel_file, 'f', 'd' )
106
101
shutil.rmtree( dst.file )
107
102
shutil.copy( src.file, dst.file )
108
103
shutil.copystat( src.file, dst.file )
110
105
# if dst entity is a symlink, replace it with file
111
106
elif dst.type == 'l':
112
if the.verbose >= 2: self.print_op( rel_file, 'f>l' )
107
if the.verbose > 1: self.print_cp( rel_file, 'f', 'l' )
113
108
os.unlink( dst.file )
114
109
shutil.copy( src.file, dst.file )
115
110
shutil.copystat( src.file, dst.file )
118
113
raise NotImplementedError()
120
115
# src entity is a symlink
121
elif src.type == 'l':
123
118
# if dst entity doesn't exist, copy symlink
124
119
if dst.type == '_':
125
if the.verbose >= 2: self.print_op( rel_file, 'l>_' )
120
if the.verbose > 1: self.print_cp( rel_file, 'l', '_' )
126
121
os.symlink( os.readlink( src.file ), dst.file )
128
123
# if dst entity is a symlink, replace it only if it differs
129
124
elif dst.type == 'l':
130
125
if os.readlink( src.file ) != os.readlink( dst.file ):
131
if the.verbose >= 2: self.print_op( rel_file, 'l>l' )
126
if the.verbose > 1: self.print_cp( rel_file, 'l', 'l' )
132
127
os.unlink( dst.file )
133
128
os.symlink( os.readlink( src.file ), dst.file )
135
if the.verbose >= 2: self.print_op( rel_file, 'l=l' )
130
if the.verbose > 1: self.print_cp( rel_file, 'l', 'l', '=' )
137
132
# if dst entity is a file, replace it with symlink
138
133
elif dst.type == 'f':
139
if the.verbose >= 2: self.print_op( rel_file, 'l>f' )
134
if the.verbose > 1: self.print_cp( rel_file, 'l', 'f' )
140
135
os.unlink( dst.file )
141
136
os.symlink( os.readlink( src.file ), dst.file )
143
# if dst entity is a directory...
138
# if dst entity is a directory, replace it with symlink
144
139
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' )
140
if the.verbose > 1: self.print_cp( rel_file, 'l', 'd' )
155
141
shutil.rmtree( dst.file )
156
142
os.symlink( os.readlink( src.file ), dst.file )
159
145
raise NotImplementedError()
161
147
# src entity is missing
162
elif src.type == '_':
164
150
# if dst entity doesn't exist, we're good
165
151
if dst.type == '_':
168
154
# if dst entity is a file or symlink, delete it
169
elif dst.type == 'f' or dst.type == 'l':
170
if the.verbose >= 2: self.print_op( rel_file, '_>' + dst.type )
155
if dst.type == 'f' or dst.type == 'l':
156
if the.verbose > 1: self.print_cp( rel_file, '_', dst.type )
171
157
os.unlink( dst.file )
173
159
# if dst entity is a directory, delete it
174
160
elif dst.type == 'd':
175
if the.verbose >= 2: self.print_op( rel_file, '_>d' )
161
if the.verbose > 1: self.print_cp( rel_file, '_', 'd' )
176
162
shutil.rmtree( dst.file )
179
165
raise NotImplementedError()
181
# if we got here, we don't want to recurse...
167
# non-directories can not be recursed in to