File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 44
55from Updater .config .yml_loader import get_config
66from Updater .updater .assets .name import get_package_name_from_current_machine
7+ from Updater .updater .downloader .temp import download_to_temp
78from Updater .updater .runner .process import find_processes_by_path , try_terminate
89from Updater .updater .tag .reader import read
910from fetch .github_release_api import fetch_latest_release
@@ -40,10 +41,13 @@ def main():
4041 break
4142
4243 if download_url is None :
43- print (f"Could not find asset for { get_package_name_from_current_machine ()} " )
44+ print (
45+ f"Could not find asset for { get_package_name_from_current_machine ()} \n Please update manually or send an issue." )
4446 return
4547
46- print (download_url )
48+ downloaded_path = download_to_temp (download_url )
49+
50+ print (downloaded_path )
4751
4852 print ("=" * 80 )
4953 time .sleep (INTERVAL )
Original file line number Diff line number Diff line change 1+ import atexit
2+ import tempfile
3+ from datetime import datetime
4+ from pathlib import Path
5+ from urllib .parse import urlparse
6+
7+ import requests
8+
9+
10+ def download_to_temp (url : str ) -> Path :
11+ original_name = Path (urlparse (url ).path ).name
12+
13+ filename = f"{ Path (original_name ).stem } _{ datetime .now ().strftime ("%Y%m%d_%H%M%S" )} { Path (original_name ).suffix } "
14+
15+ temp_path = Path (tempfile .gettempdir ()) / filename
16+
17+ with requests .get (url , stream = True ) as r :
18+ r .raise_for_status ()
19+ with open (temp_path , 'wb' ) as f :
20+ for chunk in r .iter_content (chunk_size = 1024 ):
21+ if chunk :
22+ f .write (chunk )
23+
24+ atexit .register (lambda : temp_path .exists () and temp_path .unlink ())
25+
26+ return temp_path
You can’t perform that action at this time.
0 commit comments