diff --git a/README b/README index 47aacb5e6c145a666eec465213703858e6a1a3a3..f755f0f784b3728d4fae88c583662716813703c1 100644 --- a/README +++ b/README @@ -4,3 +4,4 @@ dependencies: opentracker rsync mktorrent + python-progressbar diff --git a/p2pacman.py b/p2pacman.py index b8115513dfeb3b38952443013a693c34c05f5179..6668f8fb0f628c58df28acb25c4e8f19232c79eb 100644 --- a/p2pacman.py +++ b/p2pacman.py @@ -7,7 +7,10 @@ import libtorrent as lt import time from sys import exit import os -import progressbar +from progressbar import AnimatedMarker, Bar, BouncingBar, Counter, ETA, \ + FileTransferSpeed, FormatLabel, Percentage, \ + ProgressBar, ReverseBar, RotatingMarker, \ + SimpleProgress, Timer ses = lt.session() @@ -25,9 +28,31 @@ ses.listen_on(6881, 6891) # pacman like usage: python-progressbar # p2p packet database list # libtorrent python3 bindings 32bit systeme failed noch +# test for root, use less root permissions packages = [] +class ETA(Timer): + """Widget which attempts to estimate the time of arrival.""" + + TIME_SENSITIVE = True + + def update(self, pbar): + """Updates the widget to show the ETA or total time when finished.""" + + if pbar.currval == 0: + return '--:--:--' + elif pbar.finished: + return 'Time: %s' % self.format_time(pbar.seconds_elapsed) + else: + elapsed = pbar.seconds_elapsed + eta = elapsed * pbar.maxval / pbar.currval - elapsed + return '%s' % self.format_time(eta) + +class PackageStat(): + def update(self, pbar): + return ' Downloading x/x packages ' + class torrent: def __init__(self, path, link): self.path = path @@ -72,8 +97,8 @@ class threadstart(threading.Thread): self.path = path self.link = link def run(self): - #logging.debug('Loading torrent file in thread: '+self.path) - print("Loading torrent file in thread") + #logging.debug(' Loading torrent file in thread: '+self.path) + print(" Loading torrent file in thread") package = torrent(self.path, self.link) packages.append(package) @@ -90,7 +115,8 @@ else: print("no updates available") exit(0) -print("downloading torrent metadata ...") +print(" Downloading torrent metadata ...") + for link in torrentlinks: try: r = requests.get(link) @@ -109,19 +135,26 @@ for link in torrentlinks: thread.start() time.sleep(5) -print("starting torrents ...") +print(" Starting torrents ...") + +package_count = len(packages) +widgets = [PackageStat(), ' ', FileTransferSpeed(), '' , + ETA(), Bar(left=' [',right=']'), + ' ', Percentage()] +pbar = ProgressBar(widgets=widgets, maxval=len(packages)) +pbar.start() while len(packages): - print("downloading "+str(len(packages))+" package(s):") + pbar.update(package_count - len(packages)) for torrent in packages: - torrent.print_state() + #torrent.print_state() if torrent.idle() > 60: - print("timeout reached, skipping torrent. idle time: %d" % torrent.idle()) - print("starting manual direct download of: %s" % vars(torrent)['link'].split('/')[-1].replace('.torrent','')) + #print("timeout reached, skipping torrent. idle time: %d" % torrent.idle()) + #print("starting manual direct download of: %s" % vars(torrent)['link'].split('/')[-1].replace('.torrent','')) packages.pop(-1) try: r = requests.get(vars(torrent)['link'].replace('.torrent','')) except: - print("error: mirror refues the connection, aborting.") + #print("error: mirror refues the connection, aborting.") exit(1) if r.status_code == 200: with open("/var/cache/pacman/pkg/"+vars(torrent)['link'].split('/')[-1].replace('.torrent',''), 'wb') as f: @@ -129,14 +162,16 @@ while len(packages): f.write(chunk) f.close else: - print("error: your mirror doesn't have proper torrent support") + #print("error: your mirror doesn't have proper torrent support") exit(1) if not torrent.return_state(): packages.pop(-1) - time.sleep(5) + time.sleep(1) +pbar.finish() + -print("all downloads finished!") -print("installing packages ...") +print(" All downloads finished!") +print(" Installing packages ...") links = "" for n, torrentlink in enumerate(torrentlinks):