From 489153317aad30a4da1749b2b62ac85ebaba9a0e Mon Sep 17 00:00:00 2001 From: "A. Murat Eren" Date: Wed, 21 Nov 2007 20:20:25 +0000 Subject: [PATCH] Yay for new bandwith usage limitation option for PiSi --- pisi/cli/commands.py | 2 ++ pisi/fetcher.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index c86a9a03..886888dc 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -151,6 +151,8 @@ class Command(object): default=False, help = _("Assume yes in all yes/no queries")) group.add_option("-u", "--username", action="store") group.add_option("-p", "--password", action="store") + group.add_option("-L", "--bandwidth-limit", action="store", default = 0, + help = _("Keep bandwidth usage under specified KB's")) group.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help=_("Detailed output")) diff --git a/pisi/fetcher.py b/pisi/fetcher.py index 17972230..b41bcf3d 100644 --- a/pisi/fetcher.py +++ b/pisi/fetcher.py @@ -136,6 +136,7 @@ class Fetcher: http_headers = self._get_http_headers(), ftp_headers = self._get_ftp_headers(), proxies = self._get_proxies(), + throttle = self._get_bandwith_limit(), user_agent = 'PiSi Fetcher/' + pisi.__version__, reget = 'check_timestamp') @@ -178,6 +179,14 @@ class Fetcher: return proxies + def _get_bandwith_limit(self): + bandwidth_limit = ctx.config.options.bandwidth_limit or ctx.config.values.general.bandwidth_limit + if bandwidth_limit: + ctx.ui.warning(_("Bandwidth usage is limited to %s KB/s") % bandwidth_limit) + return 1024 * int(bandwidth_limit) + else: + return 0 + # helper function def fetch_url(url, destdir, progress=None):