42
44
# if dst entity doesn't exist, create directory (no need to recurse,
43
45
# since we're copying the whole directory)
44
46
if dst.type == '_':
45
if the.verbose > 1: self.print_op( rel_file, 'd>_' )
46
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 )
48
52
# if dst entity is a directory, copy permissions, as required (and
50
54
elif dst.type == 'd':
51
55
# TODO: should check permission and only do as necessary
52
if the.verbose > 1: self.print_op( rel_file, 'd>d' )
56
if the.verbose > 1: self.print_cp( rel_file, 'd', 'd' )
53
57
shutil.copystat( src.file, dst.file )
56
# if dst entity is a symlink to a directory, and this is an
57
# 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' )
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', '@' )
63
66
# if dst entity is a file or symlink in home dir, replace it with
64
67
# directory (no need to recurse, since we're copying the whole
66
69
elif dst.type == 'f' or dst.type == 'l':
67
if the.verbose > 1: self.print_op( rel_file, 'd>' + dst.type )
70
if the.verbose > 1: self.print_cp( rel_file, 'd', dst.type )
68
71
os.unlink( dst.file )
69
shutil.copytree( src.file, dst.file, True )
73
shutil.copystat( src.file, dst.file )
72
77
raise NotImplementedError()
74
79
# src entity is file
77
82
# if dst entity doesn't exist, copy file
78
83
if dst.type == '_':
79
if the.verbose > 1: self.print_op( rel_file, 'f>_' )
84
if the.verbose > 1: self.print_cp( rel_file, 'f', '_' )
80
85
shutil.copy( src.file, dst.file )
81
86
shutil.copystat( src.file, dst.file )
83
88
# if dst entity is a file, replace it only if it differs
84
89
elif dst.type == 'f':
85
90
if not filecmp.cmp( src.file, dst.file ):
86
if the.verbose > 1: self.print_op( rel_file, 'f>f' )
91
if the.verbose > 1: self.print_cp( rel_file, 'f', 'f' )
87
92
os.unlink( dst.file )
88
93
shutil.copy( src.file, dst.file )
89
94
shutil.copystat( src.file, dst.file )
91
if the.verbose > 1: self.print_op( rel_file, 'f=f' )
96
if the.verbose > 1: self.print_cp( rel_file, 'f', 'f', '=' )
93
98
# if dst entity is a directory, replace it with file
94
99
elif dst.type == 'd':
95
if the.verbose > 1: self.print_op( rel_file, 'f>d' )
100
if the.verbose > 1: self.print_cp( rel_file, 'f', 'd' )
96
101
shutil.rmtree( dst.file )
97
102
shutil.copy( src.file, dst.file )
98
103
shutil.copystat( src.file, dst.file )
100
105
# if dst entity is a symlink, replace it with file
101
106
elif dst.type == 'l':
102
if the.verbose > 1: self.print_op( rel_file, 'f>l' )
107
if the.verbose > 1: self.print_cp( rel_file, 'f', 'l' )
103
108
os.unlink( dst.file )
104
109
shutil.copy( src.file, dst.file )
105
110
shutil.copystat( src.file, dst.file )
108
113
raise NotImplementedError()
110
115
# src entity is a symlink
111
elif src.type == 'l':
113
118
# if dst entity doesn't exist, copy symlink
114
119
if dst.type == '_':
115
if the.verbose > 1: self.print_op( rel_file, 'l>_' )
120
if the.verbose > 1: self.print_cp( rel_file, 'l', '_' )
116
121
os.symlink( os.readlink( src.file ), dst.file )
118
123
# if dst entity is a symlink, replace it only if it differs
119
124
elif dst.type == 'l':
120
125
if os.readlink( src.file ) != os.readlink( dst.file ):
121
if the.verbose > 1: self.print_op( rel_file, 'l>l' )
126
if the.verbose > 1: self.print_cp( rel_file, 'l', 'l' )
122
127
os.unlink( dst.file )
123
128
os.symlink( os.readlink( src.file ), dst.file )
125
if the.verbose > 1: self.print_op( rel_file, 'l=l' )
130
if the.verbose > 1: self.print_cp( rel_file, 'l', 'l', '=' )
127
132
# if dst entity is a file, replace it with symlink
128
133
elif dst.type == 'f':
129
if the.verbose > 1: self.print_op( rel_file, 'l>f' )
134
if the.verbose > 1: self.print_cp( rel_file, 'l', 'f' )
130
135
os.unlink( dst.file )
131
136
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
138
# if dst entity is a directory, replace it with symlink
141
139
elif dst.type == 'd':
142
if the.verbose > 1: self.print_op( rel_file, 'l>d' )
140
if the.verbose > 1: self.print_cp( rel_file, 'l', 'd' )
143
141
shutil.rmtree( dst.file )
144
142
os.symlink( os.readlink( src.file ), dst.file )
147
145
raise NotImplementedError()
149
147
# src entity is missing
150
elif src.type == '_':
152
150
# if dst entity doesn't exist, we're good
153
151
if dst.type == '_':
156
154
# if dst entity is a file or symlink, delete it
157
elif dst.type == 'f' or dst.type == 'l':
158
if the.verbose > 1: 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 )
159
157
os.unlink( dst.file )
161
159
# if dst entity is a directory, delete it
162
160
elif dst.type == 'd':
163
if the.verbose > 1: self.print_op( rel_file, '_>d' )
161
if the.verbose > 1: self.print_cp( rel_file, '_', 'd' )
164
162
shutil.rmtree( dst.file )
167
165
raise NotImplementedError()
169
# if we got here, we don't want to recurse...
167
# non-directories can not be recursed in to