43
43
self.walk_list = updated_files if updated_files is not None else \
44
44
self.generate_walk_list( the.repo.full_dir )
46
self.accept_symlinks = list()
49
def process( self, rel_file, src, dst ):
47
def process( self, rel_file, src_file, src_type, dst_file, dst_type ):
51
49
# directory (in repo)
54
52
# if entity doesn't exist in home dir, create directory (no need to
55
53
# recurse, since we're copying the whole directory)
57
55
if the.verbose > 1: print " _<d " + rel_file
59
shutil.copystat( src.file, dst.file )
57
shutil.copystat( src_file, dst_file )
60
# if entity is a file or symlink in home dir, replace it with
61
# directory (no need to recurse, since we're copying the whole
63
elif dst_type == 'f' or dst_type == 'l':
64
if the.verbose > 1: print " %s<d %s" % ( dst_type, rel_file )
67
shutil.copystat( src_file, dst_file )
62
70
# if entity is a directory in home dir, copy permissions, as
63
71
# required (and recurse)
65
73
# TODO: should check permission and only do as necessary
66
74
if the.verbose > 1: print " d<d " + rel_file
67
shutil.copystat( src.file, dst.file )
75
shutil.copystat( src_file, dst_file )
70
# TODO: if entity is a symlink to a directory, and this is
71
# acceptable, just recurse
72
# elif dst.link_type == 'd' and self.accept_list.match( rel_file ):
73
# if the.verbose > 1: print " d@=d " + rel_file
76
# if entity is a file or symlink in home dir, replace it with
77
# directory (no need to recurse, since we're copying the whole
79
elif dst.type == 'f' or dst.type == 'l':
80
if the.verbose > 1: print " %s<d %s" % ( dst.type, rel_file )
83
shutil.copystat( src.file, dst.file )
87
79
raise NotImplementedError()
92
84
# if entity doesn't exist in home dir, copy file
94
86
if the.verbose > 1: print " _<f " + rel_file
95
shutil.copy( src.file, dst.file )
96
shutil.copystat( src.file, dst.file )
87
shutil.copy( src_file, dst_file )
88
shutil.copystat( src_file, dst_file )
90
# if entity is a symlink in home dir, replace it with file
92
if the.verbose > 1: print " l<f " + rel_file
94
shutil.copy( src_file, dst_file )
95
shutil.copystat( src_file, dst_file )
98
97
# if entity is a file in home dir, replace it only if it differs
100
if not filecmp.cmp( src.file, dst.file ):
99
if not filecmp.cmp( src_file, dst_file ):
101
100
if the.verbose > 1: print " f<f " + rel_file
102
os.unlink( dst.file )
103
shutil.copy( src.file, dst.file )
104
shutil.copystat( src.file, dst.file )
101
os.unlink( dst_file )
102
shutil.copy( src_file, dst_file )
103
shutil.copystat( src_file, dst_file )
106
105
if the.verbose > 1: print " f=f " + rel_file
108
107
# if entity is a directory in home dir, replace it with file
109
elif dst.type == 'd':
108
elif dst_type == 'd':
110
109
if the.verbose > 1: print " d<f " + rel_file
111
shutil.rmtree( dst.file )
112
shutil.copy( src.file, dst.file )
113
shutil.copystat( src.file, dst.file )
115
# if entity is a symlink in home dir, replace it with file
116
elif dst.type == 'l':
117
if the.verbose > 1: print " l<f " + rel_file
118
os.unlink( dst.file )
119
shutil.copy( src.file, dst.file )
120
shutil.copystat( src.file, dst.file )
110
shutil.rmtree( dst_file )
111
shutil.copy( src_file, dst_file )
112
shutil.copystat( src_file, dst_file )
123
115
raise NotImplementedError()
128
120
# if entity doesn't exist in home dir, copy symlink
130
122
if the.verbose > 1: print " _<l " + rel_file
131
os.symlink( os.readlink( src.file ), dst.file )
123
os.symlink( os.readlink( src_file ), dst_file )
133
125
# if entity is a symlink in home dir, replace it only if it differs
134
elif dst.type == 'l':
135
if os.readlink( src.file ) != os.readlink( dst.file ):
126
elif dst_type == 'l':
127
if os.readlink( src_file ) != os.readlink( dst_file ):
136
128
if the.verbose > 1: print " l<l " + rel_file
137
os.unlink( dst.file )
138
os.symlink( os.readlink( src.file ), dst.file )
129
os.unlink( dst_file )
130
os.symlink( os.readlink( src_file ), dst_file )
140
132
if the.verbose > 1: print " l=l " + rel_file
142
134
# if entity is a file in home dir, replace it with file
143
elif dst.type == 'f':
135
elif dst_type == 'f':
144
136
if the.verbose > 1: print " f<l " + rel_file
145
os.unlink( dst.file )
146
os.symlink( os.readlink( src.file ), dst.file )
137
os.unlink( dst_file )
138
os.symlink( os.readlink( src_file ), dst_file )
148
140
# if entity is a directory in home dir, replace it with file
149
elif dst.type == 'd':
141
elif dst_type == 'd':
150
142
if the.verbose > 1: print " d<l " + rel_file
151
shutil.rmtree( dst.file )
152
os.symlink( os.readlink( src.file ), dst.file )
143
shutil.rmtree( dst_file )
144
os.symlink( os.readlink( src_file ), dst_file )
155
147
raise NotImplementedError()
157
# deleted file (in repo)
160
152
# if entity doesn't exist in home dir, we're good
164
156
# if entity is a file or symlink in home dir, delete it
165
if dst.type == 'f' or dst.type == 'l':
166
if the.verbose > 1: print " %s<_ %s" % ( dst.type, rel_file )
167
os.unlink( dst.file )
157
if dst_type == 'f' or dst_type == 'l':
158
if the.verbose > 1: print " %s<_ %s" % ( dst_type, rel_file )
159
os.unlink( dst_file )
169
161
# if entity is a directory in home dir, delete it
170
elif dst.type == 'd':
162
elif dst_type == 'd':
171
163
if the.verbose > 1: print " d<_ " + rel_file
172
shutil.rmtree( dst.file )
164
shutil.rmtree( dst_file )
175
167
raise NotImplementedError()