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