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