@@ -1166,40 +1166,39 @@ def do_custom_build(self):
1166
1166
if not os .path .exists ('build' ):
1167
1167
os .makedirs ('build' )
1168
1168
1169
- sourceforge_url = (
1169
+ url_fmts = [
1170
1170
'https://downloads.sourceforge.net/project/freetype'
1171
- '/freetype2/{0}/' .format (LOCAL_FREETYPE_VERSION )
1172
- )
1173
- url_fmts = (
1174
- sourceforge_url + '{0}' ,
1175
- 'https://download.savannah.gnu.org/releases/freetype/{0}'
1176
- )
1171
+ '/freetype2/{version}/{tarball}' ,
1172
+ 'https://download.savannah.gnu.org/releases/freetype'
1173
+ '/{tarball}'
1174
+ ]
1177
1175
for url_fmt in url_fmts :
1178
- tarball_url = url_fmt .format (tarball )
1176
+ tarball_url = url_fmt .format (
1177
+ version = LOCAL_FREETYPE_VERSION , tarball = tarball )
1179
1178
1180
1179
print ("Downloading {0}" .format (tarball_url ))
1181
1180
try :
1182
1181
urlretrieve (tarball_url , tarball_path )
1183
- except :
1182
+ except IOError : # URLError (a subclass) on Py3.
1184
1183
print ("Failed to download {0}" .format (tarball_url ))
1185
1184
else :
1186
- break
1187
- if not os .path .isfile (tarball_path ):
1185
+ if get_file_hash (tarball_path ) != LOCAL_FREETYPE_HASH :
1186
+ print ("Invalid hash." )
1187
+ else :
1188
+ break
1189
+ else :
1188
1190
raise IOError ("Failed to download freetype" )
1189
- if get_file_hash (tarball_path ) == LOCAL_FREETYPE_HASH :
1190
- try :
1191
- os .makedirs (tarball_cache_dir )
1192
- except OSError :
1193
- # Don't care if it exists.
1194
- pass
1195
- try :
1196
- shutil .copy (tarball_path , tarball_cache_path )
1197
- print ('Cached tarball at: {}'
1198
- .format (tarball_cache_path ))
1199
- except OSError :
1200
- # again, we do not care if this fails, can
1201
- # always re download
1202
- pass
1191
+ try :
1192
+ os .makedirs (tarball_cache_dir )
1193
+ except OSError :
1194
+ # Don't care if it exists.
1195
+ pass
1196
+ try :
1197
+ shutil .copy (tarball_path , tarball_cache_path )
1198
+ print ('Cached tarball at: {}' .format (tarball_cache_path ))
1199
+ except OSError :
1200
+ # If this fails, we can always re-download.
1201
+ pass
1203
1202
1204
1203
if get_file_hash (tarball_path ) != LOCAL_FREETYPE_HASH :
1205
1204
raise IOError (
0 commit comments