7676import atexit
7777import grass .script as gs
7878import zipfile as zfile
79+ from pathlib import Path
7980from grass .exceptions import CalledModuleError
8081
8182
130131YDIM 0.000833333333333
131132"""
132133
133- proj = "" .join (
134- [
135- "GEOGCS[" ,
136- '"wgs84",' ,
137- (
138- 'DATUM["WGS_1984",SPHEROID["wgs84",6378137,298.257223563],TOWGS84[0.000000,'
139- "0.000000,0.000000]],"
140- ),
141- 'PRIMEM["Greenwich",0],' ,
142- 'UNIT["degree",0.0174532925199433]' ,
143- "]" ,
144- ]
145- )
134+ proj = 'GEOGCS["wgs84",DATUM["WGS_1984",SPHEROID["wgs84",6378137,298.257223563],TOWGS84[0.000000,0.000000,0.000000]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]'
146135
147136
148137def cleanup ():
@@ -186,8 +175,8 @@ def main():
186175 suff = ".raw"
187176 swbd = True
188177
189- zipfile = "{im}{su }.zip". format ( im = infile , su = suff )
190- hgtfile = "{im}{su}" . format ( im = infile , su = suff )
178+ zipfile = f" { infile } { suff } .zip"
179+ hgtfile = f" { infile } { suff } "
191180
192181 if os .path .isfile (zipfile ):
193182 # really a ZIP file?
@@ -206,28 +195,24 @@ def main():
206195 gs .try_remove (tmpdir )
207196 os .mkdir (tmpdir )
208197 if is_zip :
209- shutil .copyfile (
210- zipfile , os .path .join (tmpdir , "{im}{su}.zip" .format (im = tile , su = suff ))
211- )
198+ shutil .copyfile (zipfile , os .path .join (tmpdir , f"{ tile } { suff } .zip" ))
212199 else :
213- shutil .copyfile (
214- hgtfile , os .path .join (tmpdir , "{im}{su}" .format (im = tile [:7 ], su = suff ))
215- )
200+ shutil .copyfile (hgtfile , os .path .join (tmpdir , f"{ tile [:7 ]} { suff } " ))
216201 # change to temporary directory
217202 os .chdir (tmpdir )
218203 in_temp = True
219204
220- zipfile = "{im}{su }.zip". format ( im = tile , su = suff )
221- hgtfile = "{im}{su}" . format ( im = tile [:7 ], su = suff )
205+ zipfile = f" { tile } { suff } .zip"
206+ hgtfile = f" { tile [:7 ]} { suff } "
222207
223208 bilfile = tile + ".bil"
224209
225210 if is_zip :
226211 # unzip & rename data file:
227212 gs .message (_ ("Extracting '%s'..." ) % infile )
228213 try :
229- zf = zfile .ZipFile (zipfile )
230- zf .extractall ()
214+ with zfile .ZipFile (zipfile ) as zf :
215+ zf .extractall ()
231216 except (zfile .BadZipfile , zfile .LargeZipFile , PermissionError ):
232217 gs .fatal (_ ("Unable to unzip file." ))
233218
@@ -263,15 +248,11 @@ def main():
263248
264249 header = tmpl % (ulxmap , ulymap )
265250 hdrfile = tile + ".hdr"
266- outf = open (hdrfile , "w" )
267- outf .write (header )
268- outf .close ()
251+ Path (hdrfile ).write_text (header )
269252
270253 # create prj file: To be precise, we would need EGS96! But who really cares...
271254 prjfile = tile + ".prj"
272- outf = open (prjfile , "w" )
273- outf .write (proj )
274- outf .close ()
255+ Path (prjfile ).write_text (proj )
275256
276257 try :
277258 gs .run_command ("r.in.gdal" , input = bilfile , out = tileout )
0 commit comments