still working on ipxe

This commit is contained in:
2021-01-21 18:15:20 -05:00
parent 084a0fca69
commit 4f7c370499
9 changed files with 466 additions and 257 deletions

View File

@@ -4,6 +4,7 @@ import os
import pathlib
import shutil
import subprocess
import tempfile
##
import psutil
import requests
@@ -95,15 +96,20 @@ class BaseUpdater(object):
req_chk = requests.head(self.iso_url, headers = {'User-Agent': 'curl/7.74.0'})
if not req_chk.ok:
raise RuntimeError('Received non-200/30x {0} for {1}'.format(req_chk.status_code, self.iso_url))
os.makedirs(os.path.dirname(self.dest_iso), exist_ok = True)
_tmpfile = tempfile.mkstemp()[1]
with requests.get(self.iso_url, stream = True, headers = {'User-Agent': 'curl/7.74.0'}) as req:
req.raise_for_status()
with open(self.dest_iso, 'wb') as fh:
with open(_tmpfile, 'wb') as fh:
for chunk in req.iter_content(chunk_size = 8192):
fh.write(chunk)
realhash = self.getISOHash()
if realhash != self.new_hash:
os.remove(_tmpfile)
raise RuntimeError('Hash mismatch: {0} (LOCAL), {1} (REMOTE)'.format(realhash, self.new_hash))
os.makedirs(os.path.dirname(self.dest_iso), exist_ok = True)
pathlib.Path(self.dest_iso).touch(mode = 0o0644, exist_ok = True)
shutil.copyfile(_tmpfile, self.dest_iso)
os.remove(_tmpfile)
self.updateVer()
return(None)