File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change 1212import sys
1313import tarfile
1414import time
15- from urllib .error import URLError
16- from urllib .request import Request , urlopen
15+ from urllib .request import Request
1716
1817BUNDLE_URL = 'https://download.calibre-ebook.com/ci/kitty/{}-64.tar.xz'
1918FONTS_URL = 'https://download.calibre-ebook.com/ci/fonts.tar.xz'
@@ -64,16 +63,19 @@ def run(*a: str, print_crash_reports: bool = False) -> None:
6463 raise SystemExit (f'The following process failed with exit code: { ret } :\n { cmd } ' )
6564
6665
67- def download_with_retry (url_or_rq : str | Request ) -> bytes :
68- ans : bytes = b''
69- try :
70- with urlopen (url_or_rq ) as f :
71- ans = f .read ()
72- except URLError :
73- time .sleep (1 )
74- with urlopen (url_or_rq ) as f :
75- ans = f .read ()
76- return ans
66+ def download_with_retry (url : str | Request , count : int = 5 ) -> bytes :
67+ from urllib .request import urlopen
68+ for i in range (count ):
69+ try :
70+ print ('Downloading' , url , flush = True )
71+ ans : bytes = urlopen (url ).read ()
72+ return ans
73+ except Exception as err :
74+ if i >= count - 1 :
75+ raise
76+ print (f'Download failed with error { err } retrying...' , file = sys .stderr )
77+ time .sleep (1 )
78+ return b''
7779
7880
7981def install_fonts () -> None :
You can’t perform that action at this time.
0 commit comments