Skip to content

Commit

Permalink
macrecovery: Fix error when running headless (#550)
Browse files Browse the repository at this point in the history
macrecovery: Fix error when running headless

---------

Co-authored-by: Mike Beaton <[email protected]>
  • Loading branch information
mkorje and mikebeaton authored Aug 16, 2024
1 parent 8ee5b37 commit a5a5e3e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Utilities/macrecovery/macrecovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
INFO_SIGN_SESS = 'CT'
INFO_REQURED = [INFO_PRODUCT, INFO_IMAGE_LINK, INFO_IMAGE_HASH, INFO_IMAGE_SESS, INFO_SIGN_LINK, INFO_SIGN_HASH, INFO_SIGN_SESS]

# Use -2 for better resize stability on Windows
TERMINAL_MARGIN = 2

def run_query(url, headers, post=None, raw=False):
if post is not None:
Expand Down Expand Up @@ -223,10 +225,9 @@ def save_image(url, sess, filename='', directory=''):
break
fh.write(chunk)
size += len(chunk)
terminalsize = os.get_terminal_size().columns
terminalsize = max(os.get_terminal_size().columns - TERMINAL_MARGIN, 0)
if oldterminalsize != terminalsize:
# Use -2 for better resize stability on Windows
print(f'\r{"":<{terminalsize - 2}}', end='')
print(f'\r{"":<{terminalsize}}', end='')
oldterminalsize = terminalsize
if totalsize > 0:
progress = size / totalsize
Expand All @@ -249,7 +250,8 @@ def verify_image(dmgpath, cnkpath):

with open(dmgpath, 'rb') as dmgf:
for cnkcount, (cnksize, cnkhash) in enumerate(verify_chunklist(cnkpath), 1):
print(f'\r{f"Chunk {cnkcount} ({cnksize} bytes)":<{os.get_terminal_size().columns - 2}}', end='')
terminalsize = max(os.get_terminal_size().columns - TERMINAL_MARGIN, 0)
print(f'\r{f"Chunk {cnkcount} ({cnksize} bytes)":<{terminalsize}}', end='')
sys.stdout.flush()
cnk = dmgf.read(cnksize)
if len(cnk) != cnksize:
Expand Down

0 comments on commit a5a5e3e

Please sign in to comment.