@@ -110,40 +110,42 @@ def copy_dir(source, dest, vars, verbosity, simulate, indent=0,
110
110
continue
111
111
elif use_pkg_resources :
112
112
content = pkg_resources .resource_string (source [0 ], full )
113
+ content = content .encode ()
113
114
else :
114
- with open (full , 'r ' ) as f :
115
+ with open (full , 'rb ' ) as f :
115
116
content = f .read ()
116
117
if sub_file :
117
118
try :
119
+ content = content .decode ()
118
120
content = substitute_content (content , vars , filename = full ,
119
121
use_cheetah = use_cheetah ,
120
122
template_renderer = template_renderer )
123
+ content = content .encode ()
121
124
except SkipTemplate :
122
125
continue
123
126
if content is None :
124
127
continue
125
128
already_exists = os .path .exists (dest_full )
126
129
if already_exists :
127
- f = open (dest_full , 'rb' )
128
- old_content = f .read ()
129
- f .close ()
130
- if old_content == content :
131
- if verbosity :
132
- print ('%s%s already exists (same content)' % (pad , dest_full ))
133
- continue
134
- if interactive :
135
- if not query_interactive (
136
- full , dest_full , content , old_content ,
137
- simulate = simulate ):
130
+ with open (dest_full , 'rb' ) as f :
131
+ old_content = f .read ()
132
+ if old_content == content :
133
+ if verbosity :
134
+ print ('%s%s already exists (same content)' % (pad , dest_full ))
135
+ continue
136
+ if interactive :
137
+ if not query_interactive (
138
+ full , dest_full , content .decode (), old_content .decode (),
139
+ simulate = simulate ):
140
+ continue
141
+ elif not overwrite :
138
142
continue
139
- elif not overwrite :
140
- continue
141
143
if verbosity and use_pkg_resources :
142
144
print ('%sCopying %s to %s' % (pad , full , dest_full ))
143
145
elif verbosity :
144
146
print ('%sCopying %s to %s' % (pad , os .path .basename (full ), dest_full ))
145
147
if not simulate :
146
- with open (dest_full , 'w ' ) as f :
148
+ with open (dest_full , 'wb ' ) as f :
147
149
f .write (content )
148
150
if svn_add and not already_exists :
149
151
if os .system ('svn info %r >/dev/null 2>&1' % os .path .dirname (os .path .abspath (dest_full ))) > 0 :
0 commit comments