Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress report: estimated time to finish added #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions gogrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ def worker():
assert out.tell() == start
dlsz = ioloop(tid, path, response, out)
if (dlsz == (end - start)+1 and out.tell() == end + 1):
downloadSegmentSuccess= True;
downloadSegmentSuccess= True
succeed = succeed and True
else:
with lock:
Expand All @@ -1765,7 +1765,7 @@ def worker():
warn("failed to download %s, byte_range=%s (%d retries left) -- will retry in %ds..." % (os.path.basename(path), str(se),retries,HTTP_RETRY_DELAY))
else:
error("failed to download %s, byte_range=%s" % (os.path.basename(path), str(se)))
succeed = succeed and False;
succeed = succeed and False
retries = retries -1
except requests.HTTPError as e:
with lock:
Expand Down Expand Up @@ -1797,7 +1797,7 @@ def worker():
assert out.tell() == start
dlsz = ioloop(tid, path, response, out)
if (dlsz == (end - start)+1 and out.tell() == end + 1):
downloadSuccess= True;
downloadSuccess= True
succeed = True
else:
with lock:
Expand All @@ -1807,7 +1807,7 @@ def worker():
time.sleep(HTTP_RETRY_DELAY)
else:
error("failed to download %s, byte_range=%s" % (os.path.basename(path), str(se)))
succeed = False;
succeed = False
retries = retries -1
except requests.HTTPError as e:
error("failed to download %s, byte_range=%s" % (os.path.basename(path), str(se)))
Expand Down Expand Up @@ -1836,21 +1836,41 @@ def worker():
#debug
#info("thread completed")
work.task_done()

# array holding the last 10 samples of download rate
fbpsstack=[0,0,0,0,0,0,0,0,0,0]

# detailed progress report
def progress():
with lock:
left = sum(sizes.values())
fbps = 0
for path, flowrates in sorted(rates.items()):
flows = {}
for tid, (sz, t) in flowrates:
szs, ts = flows.get(tid, (0, 0))
flows[tid] = sz + szs, t + ts
bps = sum(szs/ts for szs, ts in list(flows.values()) if ts > 0)
# sum of bps of all rates
fbps = fbps + bps
info('%10s %8.1fMB/s %2dx %s' % \
(megs(sizes[path]), bps / 1024.0**2, len(flows), "%s/%s" % (os.path.basename(os.path.split(path)[0]), os.path.split(path)[1])))

# update stack of last 10 values
fbpsstack.insert(0,fbps)
fbpsstack.pop()
# average average bit/s
fav = sum(fbpsstack)/len(fbpsstack)

if len(rates) != 0: # only update if there's change
sproj = round(left/fav) #projected download time in seconds
sdl = sproj % 60 # seconds
ddl = sproj // 86400 # days
hdl = (sproj - ddl * 86400) // 3600 # hours
mdl = (sproj - ddl * 86400 - hdl * 3600 - sdl) // 60 # minutes

info('%s remaining' % gigs(left))
info('Time to finish: %s d %s h %s min %s s @ %s MB/s average' % (ddl, hdl, mdl, sdl, round(fav / 1024.0**2 , 3)))
rates.clear()

# process work items with a thread pool
Expand Down Expand Up @@ -1984,7 +2004,7 @@ def cmd_verify(gamedir, skipextras, skipids, check_md5, check_filesize, check_z

items = load_manifest()

save_manifest_needed = False;
save_manifest_needed = False

games_to_check_base = sorted(items, key=lambda g: g.title)

Expand Down Expand Up @@ -2026,13 +2046,13 @@ def cmd_verify(gamedir, skipextras, skipids, check_md5, check_filesize, check_z
_ = game.galaxyDownloads
except KeyError:
game.galaxyDownloads = []
game_changed = True;
game_changed = True

try:
a = game.sharedDownloads
except KeyError:
game.sharedDownloads = []
game_changed = True;
game_changed = True


if skipextras:
Expand Down Expand Up @@ -2085,7 +2105,7 @@ def cmd_verify(gamedir, skipextras, skipids, check_md5, check_filesize, check_z
_ = itm.prev_verified
except AttributeError:
itm.prev_verified = False
game_changed = True;
game_changed = True


if itm.name is None:
Expand Down Expand Up @@ -2138,14 +2158,14 @@ def cmd_verify(gamedir, skipextras, skipids, check_md5, check_filesize, check_z
shutil.move(itm_file, dest_dir)
old_verify = itm.prev_verified
if not fail:
itm.prev_verified= True;
itm.prev_verified= True
else:
itm.prev_verified=False;
itm.prev_verified=False
if (old_verify != itm.prev_verified):
game_changed = True;
game_changed = True
else:
if itm.prev_verified:
itm.prev_verified=False;
itm.prev_verified=False
game_changed = True
info('missing file %s' % itm_dirpath)
missing_cnt += 1
Expand Down