fix: parallelization effort, progressbar w/ bit-identitical file write compared to sequential path
This commit is contained in:
parent
35e49044f1
commit
8ca5371a98
9 changed files with 407 additions and 387 deletions
|
|
@ -24,6 +24,7 @@ import sys
|
|||
import stat
|
||||
import zlib
|
||||
import shutil
|
||||
import threading
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from typing import Any, Optional
|
||||
|
|
@ -99,14 +100,14 @@ def error(msg: str) -> None:
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
def warning(msg: str, args) -> None:
|
||||
def warning(msg: str, args: Any) -> None:
|
||||
"""Print a warning message. Warning messages can be silenced with --quiet"""
|
||||
|
||||
if not args.quiet:
|
||||
print(f'[WARNING] {msg}. Continuing regardless.', file=sys.stderr)
|
||||
|
||||
|
||||
def vprint(msg: str, args) -> None:
|
||||
def vprint(msg: str, args: Any) -> None:
|
||||
"""Vprint, verbose print, can be silenced with --quiet"""
|
||||
|
||||
if not args.quiet:
|
||||
|
|
@ -151,22 +152,24 @@ def ird_by_game_id(game_id: str) -> Optional[str]:
|
|||
return (ird_name)
|
||||
|
||||
|
||||
def crc32(filename: str, keep_going: Optional[list] = None) -> Optional[str]:
|
||||
"""Calculate crc32 for file"""
|
||||
if keep_going is None:
|
||||
keep_going = [True]
|
||||
def crc32(filename: str, cancel: Optional[threading.Event] = None) -> Optional[str]:
|
||||
"""Calculate crc32 for file.
|
||||
|
||||
If *cancel* is provided, the computation can be aborted from another
|
||||
thread by calling ``cancel.set()``. Returns ``None`` when cancelled.
|
||||
"""
|
||||
if cancel is None:
|
||||
cancel = threading.Event()
|
||||
|
||||
with open(filename, 'rb') as infile:
|
||||
|
||||
crc_val = 0
|
||||
|
||||
while keep_going[0] is True:
|
||||
while not cancel.is_set():
|
||||
data = infile.read(65536)
|
||||
if not data:
|
||||
break
|
||||
crc_val = zlib.crc32(data, crc_val)
|
||||
|
||||
if keep_going[0] is False:
|
||||
if cancel.is_set():
|
||||
return None
|
||||
|
||||
return f"{crc_val & 0xFFFFFFFF:08X}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue