GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — BPI-Router-Images/downloadfiles.py at main · jimbertools/BPI-Router-Images Expand file tree/ Copy pathdownloadfiles.pyMore file actions 281 lines (241 loc) · 9.49 KB / Copy pathdownloadfiles.pyFile metadata and controls281 lines (241 loc) · 9.49 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 import requests from urllib.parse import urlparse import os import sys, json import re board=None kernel=None device="sdmmc" argc=len(sys.argv)-1 if argc>0: board=sys.argv[1] if argc>1: kernel=sys.argv[2] if argc>2: device=sys.argv[3] print(f"board : {board}") print(f"kernel : {kernel}") print(f"device : {device}") def read_settings(infile): config={} with open(infile) as f: for line in f: # ignore comments if line[0] == '#': continue key, value = line.split("=", 1) key = key.lower() config[key]=value.replace("\n", "") return config config={} conffile='sourcefiles_'+board+'.conf' if os.path.isfile(conffile): config=read_settings(conffile) print(config) newconfig = config.copy() def download(url, file_name=None): # get request response = requests.get(url) if file_name: # open in binary mode # write to file with open(file_name, "wb") as file: file.write(response.content) else: return response.content boardpattern='^(bpi-r[2346]+(pro|mini|lite)?).*$' def getUbootInfo(): uboot_release_url="https://api.github.com/repos/frank-w/u-boot/releases/latest" uboot_data=download(uboot_release_url) uj=json.loads(uboot_data) ubootfiles={} if uj: bl2files={} fipfiles={} uname=uj.get("name") #print("name:",uname) ufiles=uj.get("assets") #print("files:",json.dumps(ufiles,indent=2)) for uf in ufiles: #print("file:",json.dumps(uf,indent=2)) ufname=uf.get("name") if re.match(r'u-boot.*\.bin',ufname): continue ufurl=uf.get("browser_download_url") board_=re.sub(boardpattern,r'\1',ufname) device_=re.sub(r'^.*_(sdmmc|emmc|spim-nand|nor|ram).*$',r'\1',ufname) if not board_ in ubootfiles: ubootfiles[board_]={} if not device_ in ubootfiles[board_]: ubootfiles[board_][device_]={} if ufname.endswith("img.gz"): ubootfiles[board_][device_]={"name":ufname,"url":ufurl} elif device_=="ram" and ufname.endswith("bl2.bin"): if not "bl2" in ubootfiles[board_][device_]: ubootfiles[board_][device_]["bl2"]={} if "8GB" in ufname: if not "8G" in ubootfiles[board_][device_]["bl2"]: ubootfiles[board_][device_]["bl2"]["8G"]={} ubootfiles[board_][device_]["bl2"]["8G"]={"name":ufname,"url":ufurl} else: ubootfiles[board_][device_]["bl2"]={"name":ufname,"url":ufurl} elif ufname.endswith("bl2.img"): #print(ufname) if not "bl2" in ubootfiles[board_][device_]: ubootfiles[board_][device_]["bl2"]={} if "8GB" in ufname: if not "8G" in ubootfiles[board_][device_]["bl2"]: ubootfiles[board_][device_]["bl2"]["8G"]={} if "ubi" in ufname: if not "UBI" in ubootfiles[board_][device_]["bl2"]: ubootfiles[board_][device_]["bl2"]["UBI"]={} ubootfiles[board_][device_]["bl2"]["8G"]["UBI"]={"name":ufname,"url":ufurl} else: ubootfiles[board_][device_]["bl2"]["8G"]["name"]=ufname ubootfiles[board_][device_]["bl2"]["8G"]["url"]=ufurl elif "ubi" in ufname: ubootfiles[board_][device_]["bl2"]["UBI"]={"name":ufname,"url":ufurl} else: ubootfiles[board_][device_]["bl2"]["name"]=ufname ubootfiles[board_][device_]["bl2"]["url"]=ufurl elif ufname.endswith("fip.bin"): ubootfiles[board_][device_]["fip"]={"name":ufname,"url":ufurl} return ubootfiles ubootfiles=getUbootInfo() print("files:",json.dumps(ubootfiles,indent=2)) def getKernelInfo(): kernel_releases_url="https://api.github.com/repos/frank-w/BPI-Router-Linux/releases" kernel_releases=download(kernel_releases_url) krj=json.loads(kernel_releases) kfiles={} if krj: for rel in krj: kname=rel.get("name") if re.search('CI-BUILD-.*-main',kname): branch=re.sub(r'^CI-BUILD-([56]\.[0-9]+-main).*$',r'\1',kname) #print("branch:",branch) rel["body"]="" if branch == kernel+'-main': #print("kernel-release",kname) if not branch in kfiles: rdata={} for kf in rel.get("assets"): kfname=kf.get("name") if re.search(r"^bpi-r.*\.tar.gz$",kfname): board_=re.sub(boardpattern,r'\1',kfname) #if not board in rdata: # rdata[board]={} #rdata[board][kfname]=kf.get("browser_download_url") rdata[board_]=kf.get("browser_download_url") kfiles[branch]=rdata #print("release-data:",json.dumps(rel,indent=2)) return kfiles kfiles=getKernelInfo() print("kernel-files:",json.dumps(kfiles,indent=2)) def getBinInfo(): bin_releases_url="https://api.github.com/repos/frank-w/arm-crosscompile/releases" bin_releases=download(bin_releases_url) brj=json.loads(bin_releases) bfiles={} if brj: for rel in brj: bname=rel.get("name") for f in rel.get("assets"): fname=f.get("name") if not fname in bfiles: if re.search(r"^(hostapd|iproute2|iperf|wpa_supplicant).*\.tar.gz$",fname): #fn=re.sub(boardpattern,r'\1',kfname) bfiles[fname]=f.get("browser_download_url") return bfiles bfiles=getBinInfo() #print("binfiles:",bfiles) def getInitrdInfo(): releases_url="https://api.github.com/repos/frank-w/buildroot/releases" releases=download(releases_url) irj=json.loads(releases) #print("initrd releases:",json.dumps(irj,indent=2)) ifiles={} if irj: for rel in irj: bname=rel.get("tag_name") for f in rel.get("assets"): fname=f.get("name") if not fname in ifiles: if re.search(r"arm(hf|64).cpio.zst$",fname): ifiles[fname]=f.get("browser_download_url") return ifiles ifiles=getInitrdInfo() print("initfiles:",ifiles) ufile=None kfile=None variant = config.get("variant") if variant and variant in ubootfiles and device in ubootfiles[variant]: ufile=ubootfiles[variant][device] elif board and board in ubootfiles: ufile=ubootfiles[board][device] if ufile: print(f"board:{board} variant:{variant} ubootfile: {ufile}") if kernel: if kernel+"-main" in kfiles: b=board if b=="bpi-r3mini": b="bpi-r3" if b in kfiles[kernel+"-main"]: kfile=kfiles[kernel+"-main"][b] print(f"board:{board} kernelfile: {kfile}") else: print(f"board not in kfiles[kernel]") else: print(f"kernel not in kfiles") else: print(f"kernel not set!") else: print(f"{board} not found in ubootfiles") if not config.get("skipubootdownload") and ufile: if "mmc" in device: fname=ufile.get("name") a = urlparse(ufile.get("url")) #fname=os.path.basename(a.path) print(f"ubootfile: {ufile} filename: {fname}") if os.path.isfile(fname): print(fname,"already exists") c=input('overwrite it [yn]? ').lower() else: c='y' if c=='y': download(ufile.get("url"),fname) newconfig["imgfile"]=fname elif device in ['spim-nand','nor']: #bl2=ufile.get("bl2") fip=ufile.get("fip") #if bl2: # download(bl2.get("url"),bl2.get("name")) # newconfig["bl2file"]=bl2.get("name") if fip: download(fip.get("url"),fip.get("name")) newconfig["fipfile"]=fip.get("name") else: print("no uboot image defined!") if not config.get("skipkerneldownload") and kfile: a = urlparse(kfile) fname=os.path.basename(a.path) print(f"kernelfile: {kfile} filename: {fname}") if not os.path.isfile(fname): download(kfile,fname) else: print(fname,"already exists") newconfig["kernelfile"]=fname else: print("no kernel defined!") for replacement in ["hostapd","wpa_supplicant","iperf","iproute2"]: if config and config.get("replace"+replacement): newconfig["replace"+replacement]=config.get("replace"+replacement) if bfiles: replacefile=bfiles.get(replacement+"_arm64.tar.gz") a = urlparse(replacefile) fname=os.path.basename(a.path) print(f"{replacement}file: {replacefile} filename: {fname}") download(replacefile,fname) newconfig[replacement+"file"]=fname else: print("no bfiles defined!") if not config.get("skipinitrddownload") and ifiles: if device in ["spim-nand","nor"]: fname="rootfs_arm64.cpio.zst" if fname in ifiles: print(f"initrd-file: {fname}") download(ifiles.get(fname),fname) newconfig["initrd"]=fname with open(conffile, 'w') as f: for d in newconfig: s=d+'='+newconfig[d] f.write(s+'\n') |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |