11#!/usr/bin/python3
22
3- import json
4- import os
3+ import urllib .request
54import shutil
5+ import json
66import sys
7- import urllib . request
7+ import os
88import zipfile
9- from pathlib import Path
109
1110sha = '2a7b1fcd8bf3082bc0f0ed78404b8ecb4972669c'
1211filename = 'usdx-dlls-x86_64'
1312urlbase = 'https://api.github.com/repos/UltraStar-Deluxe/mxe/'
1413headers = {
1514 'Accept' : 'application/vnd.github+json' ,
16- 'X-GitHub-Api-Version' : '2022-11-28' ,
17- }
15+ 'X-GitHub-Api-Version' : '2022-11-28'
16+ }
1817
1918token = os .environ .get ('ARTIFACT_ACCESS_TOKEN' )
20- if token is None or token .strip () == '' :
19+ if token == None or token .strip () == '' :
2120 token = os .environ .get ('GITHUB_TOKEN' )
22- if token is not None and token .strip () != '' :
21+ if token != None and token .strip () != '' :
2322 headers ['Authorization' ] = 'Bearer ' + token
2423
24+ print ('Searching for binaries built from commit ' + sha )
2525
2626def download_bass ():
2727 bass_url = 'https://www.un4seen.com/files/bass24.zip'
2828 zip_name = 'bass24.zip'
29- target = Path ( 'game' ) / ' bass.dll'
29+ target = 'game/ bass.dll'
3030 with urllib .request .urlopen (bass_url ) as dl , open (zip_name , 'wb' ) as out :
3131 out .write (dl .read ())
3232 with zipfile .ZipFile (zip_name , 'r' ) as zf :
3333 member = 'x64/bass.dll'
3434 with zf .open (member ) as src , open (target , 'wb' ) as dst :
3535 dst .write (src .read ())
36- print (f 'Downloaded { member } to { target } ' )
36+ print ('Downloaded ' + member + ' to ' + target )
3737
3838
3939def search_releases ():
4040 pagesuffix = ''
4141 page = 1
4242 links = '"next"'
43- while links is not None and '"next"' in links :
44- req = urllib .request .Request (url = urlbase + 'tags' + pagesuffix ,
45- headers = headers )
43+ while links != None and links . find ( '"next"' ) != - 1 :
44+ req = urllib .request .Request (url = urlbase + 'tags' + pagesuffix ,
45+ headers = headers )
4646 rsp = urllib .request .urlopen (req )
4747 links = rsp .headers ['link' ]
4848 for tag in json .load (rsp ):
4949 if tag ['commit' ]['sha' ] == sha :
50- req = urllib .request .Request (url = urlbase + 'releases/tags/'
50+ req = urllib .request .Request (url = urlbase + 'releases/tags/'
5151 + tag ['name' ],
52- headers = headers )
52+ headers = headers )
5353 rsp = urllib .request .urlopen (req )
5454 release = json .load (rsp )
5555 for asset in release ['assets' ]:
@@ -62,17 +62,16 @@ def search_releases():
6262 print ('No release matches' )
6363 return None
6464
65-
6665def search_artifacts ():
6766 pagesuffix = ''
6867 page = 1
6968 links = '"next"'
70- while links is not None and '"next"' in links :
71- req = urllib .request .Request (url = urlbase
69+ while links != None and links . find ( '"next"' ) != - 1 :
70+ req = urllib .request .Request (url = urlbase
7271 + 'actions/artifacts'
7372 + '?name=' + filename
7473 + pagesuffix ,
75- headers = headers )
74+ headers = headers )
7675 rsp = urllib .request .urlopen (req )
7776 links = rsp .headers ['link' ]
7877 for artifact in json .load (rsp )['artifacts' ]:
@@ -84,17 +83,15 @@ def search_artifacts():
8483 print ('No workflow artifact matches' )
8584 return None
8685
87-
8886download_bass ()
89- print ('Searching for binaries built from commit ' + sha )
9087
9188dllurl = search_releases ()
92- if dllurl is None and token is not None :
89+ if dllurl == None and token != None :
9390 dllurl = search_artifacts ()
94- if dllurl is None :
91+ if dllurl == None :
9592 sys .exit (1 )
9693print ('Downloading from ' + dllurl )
97- req = urllib .request .Request (url = dllurl )
94+ req = urllib .request .Request (url = dllurl )
9895for key in headers :
9996 req .add_unredirected_header (key , headers [key ])
10097shutil .copyfileobj (urllib .request .urlopen (req ),
0 commit comments