@@ -151,7 +151,7 @@ def get_fs_info(self) -> list[dict[str, str]]:
151151 })
152152 return result
153153
154- async def get_info_from_pak (self ) -> dict [str , Any ]:
154+ async def get_info (self ) -> dict [str , Any ]:
155155 ha = await asyncio .to_thread (self .sha256 )
156156 app = self ._fs_sections [- 1 ]
157157 with self .open (app ) as f :
@@ -204,7 +204,7 @@ def extract_file_system(self, section: Section, dest: Optional[Path] = None) ->
204204 else :
205205 raise Exception ("Unknown file system" )
206206
207- def extract_pak (self , dest : Optional [Path ] = None , force : bool = False ) -> None :
207+ def extract (self , dest : Optional [Path ] = None , force : bool = False ) -> None :
208208 dest = (Path .cwd () / "reolink_firmware" ) if dest is None else dest
209209 dest .mkdir (parents = True , exist_ok = force )
210210 rootfsdir = [s .name for s in self if s .name in ROOTFS_SECTIONS ][0 ]
@@ -227,20 +227,20 @@ async def download(url: StrOrURL) -> Union[bytes, int]:
227227 return await resp .read () if resp .status == 200 else resp .status
228228
229229
230- def extract_paks (zip : Union [StrPath , IO [bytes ]]) -> list [tuple [str , ReolinkFirmware ]]:
231- """Return a list of tuples, one for each PAK file found in the ZIP.
230+ def firmwares_from_zip (zip : Union [StrPath , IO [bytes ]]) -> list [tuple [str , ReolinkFirmware ]]:
231+ """Return a list of tuples, one for each firmware found in the ZIP.
232232
233- It is the caller's responsibility to close the PAK files.
233+ It is the caller's responsibility to close the firmware files.
234234 """
235- paks = []
235+ fws = []
236236 with ZipFile (zip ) as myzip :
237237 for name in myzip .namelist ():
238238 file = myzip .open (name )
239239 if is_pak_file (file ):
240- paks .append ((file .name , ReolinkFirmware .from_fd (file )))
240+ fws .append ((file .name , ReolinkFirmware .from_fd (file )))
241241 else :
242242 file .close ()
243- return paks
243+ return fws
244244
245245
246246def get_info_from_files (files : Mapping [Files , Optional [bytes ]]) -> dict [str , Optional [str ]]:
@@ -323,19 +323,19 @@ async def direct_download_url(url: str) -> str:
323323 return url
324324
325325
326- async def get_paks (file_or_url : StrPathURL , use_cache : bool = True ) -> list [tuple [Optional [str ], ReolinkFirmware ]]:
327- """Return PAK files read from an on-disk file or a URL.
326+ async def firmwares_from_file (file_or_url : StrPathURL , use_cache : bool = True ) -> list [tuple [Optional [str ], ReolinkFirmware ]]:
327+ """Return firmwares read from an on-disk file or a URL.
328328
329329 The file or resource may be a ZIP or a PAK. On success return a
330330 list of 2-tuples where each tuple is of the form
331- `(pak_name, pak_file )`. When the argument is a URL, `pak_name ` may
331+ `(filename, firmware )`. When the argument is a URL, `filename ` may
332332 be None. If the file is a ZIP the list might be empty.
333- It is the caller's responsibility to close the PAK files.
333+ It is the caller's responsibility to close the firmware files.
334334 """
335335 file_or_url = str (file_or_url )
336336 if is_url (file_or_url ):
337337 if use_cache and has_cache (file_or_url ):
338- return await get_paks (get_cache_file (file_or_url ))
338+ return await firmwares_from_file (get_cache_file (file_or_url ))
339339 file_or_url = await direct_download_url (file_or_url )
340340 zip_or_pak_bytes = await download (file_or_url )
341341 if isinstance (zip_or_pak_bytes , int ):
@@ -348,13 +348,13 @@ async def get_paks(file_or_url: StrPathURL, use_cache: bool = True) -> list[tupl
348348 else :
349349 zipfile = io .BytesIO (zip_or_pak_bytes )
350350 if is_zipfile (zipfile ):
351- return await asyncio .to_thread (extract_paks , zipfile )
351+ return await asyncio .to_thread (firmwares_from_zip , zipfile )
352352 zipfile .close ()
353353 raise Exception ("Not a ZIP or a PAK file" )
354354 elif is_local_file (file_or_url ):
355355 file_or_url = Path (file_or_url )
356356 if is_zipfile (file_or_url ):
357- return await asyncio .to_thread (extract_paks , file_or_url )
357+ return await asyncio .to_thread (firmwares_from_zip , file_or_url )
358358 elif is_pak_file (file_or_url ):
359359 return [(file_or_url .name , ReolinkFirmware .from_file (file_or_url ))]
360360 raise Exception ("Not a ZIP or a PAK file" )
@@ -367,12 +367,12 @@ async def get_info(file_or_url: StrPathURL, use_cache: bool = True) -> list[dict
367367 The file or resource may be a ZIP or a PAK.
368368 """
369369 try :
370- paks = await get_paks (file_or_url , use_cache )
370+ fws = await firmwares_from_file (file_or_url , use_cache )
371371 except Exception as e :
372372 return [{"file" : file_or_url , "error" : str (e )}]
373- if not paks :
373+ if not fws :
374374 return [{"file" : file_or_url , "error" : "No PAKs found in ZIP file" }]
375- info = [{** await pakfile . get_info_from_pak (), "file" : file_or_url , "pak" : pakname } for pakname , pakfile in paks ]
376- for _ , pakfile in paks :
377- pakfile .close ()
375+ info = [{** await fw . get_info (), "file" : file_or_url , "pak" : pakname } for pakname , fw in fws ]
376+ for _ , fw in fws :
377+ fw .close ()
378378 return info
0 commit comments