@@ -377,35 +377,38 @@ def output(page: str, plain: bool = False) -> None:
377
377
378
378
379
379
def update_cache (language : Optional [List [str ]] = None ) -> None :
380
- if language is None :
381
- tldr_language = os .environ .get ("TLDR_LANGUAGE" , get_default_language ())
382
- language = tldr_language if tldr_language else 'en'
383
- elif isinstance (language , list ):
384
- language = language [0 ]
385
- try :
386
- pages_dir = "pages"
387
- if language and language != 'en' :
388
- pages_dir += "." + language
389
- req = urlopen (Request (
390
- DOWNLOAD_CACHE_LOCATION ,
391
- headers = REQUEST_HEADERS
392
- ), context = URLOPEN_CONTEXT )
393
- zipfile = ZipFile (BytesIO (req .read ()))
394
- pattern = re .compile (r"{}/(.+)/(.+)\.md" .format (pages_dir ))
395
- cached = 0
396
- for entry in zipfile .namelist ():
397
- match = pattern .match (entry )
398
- if match :
399
- store_page_to_cache (
400
- zipfile .read (entry ),
401
- match .group (2 ),
402
- match .group (1 ),
403
- language
404
- )
405
- cached += 1
406
- print ("Updated cache for {:d} entries" .format (cached ))
407
- except Exception :
408
- sys .exit ("Error: Unable to update cache from " + DOWNLOAD_CACHE_LOCATION )
380
+ languages = get_language_list ()
381
+ if language and language [0 ] not in languages :
382
+ languages .append (language [0 ])
383
+ for language in languages :
384
+ try :
385
+ cache_location = f"{ DOWNLOAD_CACHE_LOCATION [:- 4 ]} -pages.{ language } .zip"
386
+ req = urlopen (Request (
387
+ cache_location ,
388
+ headers = REQUEST_HEADERS
389
+ ), context = URLOPEN_CONTEXT )
390
+ zipfile = ZipFile (BytesIO (req .read ()))
391
+ pattern = re .compile (r"(.+)/(.+)\.md" )
392
+ cached = 0
393
+ for entry in zipfile .namelist ():
394
+ match = pattern .match (entry )
395
+ if match :
396
+ store_page_to_cache (
397
+ zipfile .read (entry ),
398
+ match .group (2 ),
399
+ match .group (1 ),
400
+ language
401
+ )
402
+ cached += 1
403
+ print (
404
+ "Updated cache for language "
405
+ f"{ language } : { cached } entries"
406
+ )
407
+ except Exception :
408
+ print (
409
+ "Error: Unable to update cache for language "
410
+ f"{ language } from { cache_location } "
411
+ )
409
412
410
413
411
414
def create_parser () -> ArgumentParser :
0 commit comments