From 80104a8051905d09827f8b84b0ab88df486e5994 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 3 Aug 2011 23:22:51 +0200 Subject: [PATCH] Add option to throttle download speed. --- examples/pakfire.conf | 4 ++++ pakfire/downloader.py | 27 +++++++++++++++++++-------- pakfire/packages/make.py | 1 + pakfire/repository/index.py | 3 ++- pakfire/server.py | 2 +- po/pakfire.pot | 22 +++++++++++----------- 6 files changed, 38 insertions(+), 21 deletions(-) diff --git a/examples/pakfire.conf b/examples/pakfire.conf index cf947d104..79e1a8f7e 100644 --- a/examples/pakfire.conf +++ b/examples/pakfire.conf @@ -2,8 +2,12 @@ # This is the main configuration file for pakfire. [main] + logfile = /var/log/pakfire.log +# You can throttle the download bandwidth with this +# parameter. Unit: bytes per second. +# bandwidth_throttle = 10240 [distro] name = IPFire diff --git a/pakfire/downloader.py b/pakfire/downloader.py index b920da29a..b5d61d027 100644 --- a/pakfire/downloader.py +++ b/pakfire/downloader.py @@ -16,40 +16,51 @@ class PakfireGrabber(URLGrabber): """ # XXX add proxy, throttle things here - def __init__(self, *args, **kwargs): + def __init__(self, pakfire, *args, **kwargs): kwargs.update({ "quote" : 0, "user_agent" : "pakfire/%s" % PAKFIRE_VERSION, }) + # Get Pakfire configuration + bandwidth_throttle = pakfire.config.get("bandwidth_throttle") + if bandwidth_throttle: + try: + bandwidth_throttle = int(bandwidth_throttle) + except ValueError: + logging.error("Configuration value for bandwidth_throttle is invalid.") + bandwidth_throttle = 0 + + kwargs.update({ "throttle" : bandwidth_throttle }) + URLGrabber.__init__(self, *args, **kwargs) class PackageDownloader(PakfireGrabber): - def __init__(self, *args, **kwargs): + def __init__(self, pakfire, *args, **kwargs): kwargs.update({ "progress_obj" : TextMeter(), }) - PakfireGrabber.__init__(self, *args, **kwargs) + PakfireGrabber.__init__(self, pakfire, *args, **kwargs) class MetadataDownloader(PakfireGrabber): - def __init__(self, *args, **kwargs): + def __init__(self, pakfire, *args, **kwargs): kwargs.update({ "http_headers" : (('Pragma', 'no-cache'),), }) - PakfireGrabber.__init__(self, *args, **kwargs) + PakfireGrabber.__init__(self, pakfire, *args, **kwargs) class DatabaseDownloader(PackageDownloader): - def __init__(self, *args, **kwargs): + def __init__(self, pakfire, *args, **kwargs): kwargs.update({ "http_headers" : (('Pragma', 'no-cache'),), }) - PackageDownloader.__init__(self, *args, **kwargs) + PackageDownloader.__init__(self, pakfire, *args, **kwargs) class Mirror(object): @@ -105,7 +116,7 @@ class MirrorList(object): force = True if force: - g = MetadataDownloader() + g = MetadataDownloader(self.pakfire) try: mirrordata = g.urlread(self.mirrorlist, limit=MIRRORLIST_MAXSIZE) diff --git a/pakfire/packages/make.py b/pakfire/packages/make.py index 605c4e0be..fb2dbeb28 100644 --- a/pakfire/packages/make.py +++ b/pakfire/packages/make.py @@ -18,6 +18,7 @@ class SourceDownloader(object): def __init__(self, pakfire): self.pakfire = pakfire + # XXX need to use downloader.py self.grabber = URLGrabber( prefix = self.pakfire.config.get("source_download_url"), progress_obj = TextMeter(), diff --git a/pakfire/repository/index.py b/pakfire/repository/index.py index 0e9346b88..cccf339ad 100644 --- a/pakfire/repository/index.py +++ b/pakfire/repository/index.py @@ -200,7 +200,7 @@ class IndexSolv(Index): logging.debug("Going to (re-)download the repository metadata.") # Initialize a grabber for download. - grabber = downloader.MetadataDownloader() + grabber = downloader.MetadataDownloader(self.pakfire) grabber = self.repo.mirrors.group(grabber) data = grabber.urlread(filename, limit=METADATA_DOWNLOAD_LIMIT) @@ -228,6 +228,7 @@ class IndexSolv(Index): if not self.cache.exists(filename): # Initialize a grabber for download. grabber = downloader.DatabaseDownloader( + self.pakfire, text = _("%s: package database") % self.repo.name, ) grabber = self.repo.mirrors.group(grabber) diff --git a/pakfire/server.py b/pakfire/server.py index 79c0c3382..9d4c2c6fd 100644 --- a/pakfire/server.py +++ b/pakfire/server.py @@ -346,7 +346,7 @@ class Server(object): logfile = os.path.join(tmpdir, "build.log") # Get a package grabber and add mirror download capabilities to it. - grabber = pakfire.downloader.PackageDownloader() + grabber = pakfire.downloader.PackageDownloader(self.pakfire) try: # Download the source. diff --git a/po/pakfire.pot b/po/pakfire.pot index ca2756b91..7ef03bc77 100644 --- a/po/pakfire.pot +++ b/po/pakfire.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-08-03 14:24+0200\n" +"POT-Creation-Date: 2011-08-03 23:16+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,24 +17,24 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: ../pakfire/actions.py:100 ../pakfire/actions.py:157 +#: ../pakfire/actions.py:101 ../pakfire/actions.py:158 msgid "Installing" msgstr "" -#: ../pakfire/actions.py:110 +#: ../pakfire/actions.py:111 msgid "Updating" msgstr "" -#: ../pakfire/actions.py:124 +#: ../pakfire/actions.py:125 msgid "Removing" msgstr "" #. Cleaning up leftover files and stuff. -#: ../pakfire/actions.py:142 +#: ../pakfire/actions.py:143 msgid "Cleanup" msgstr "" -#: ../pakfire/actions.py:167 +#: ../pakfire/actions.py:168 msgid "Downgrading" msgstr "" @@ -356,19 +356,19 @@ msgstr "" msgid "Requires" msgstr "" -#: ../pakfire/repository/index.py:231 +#: ../pakfire/repository/index.py:232 #, python-format msgid "%s: package database" msgstr "" #. Create progress bar. -#: ../pakfire/repository/index.py:319 +#: ../pakfire/repository/index.py:320 #, python-format msgid "Loading from %s" msgstr "" #. Add all packages from the database to the index. -#: ../pakfire/repository/index.py:372 +#: ../pakfire/repository/index.py:373 msgid "Loading installed packages" msgstr "" @@ -453,11 +453,11 @@ msgstr "" msgid "Freed size: %s" msgstr "" -#: ../pakfire/transaction.py:219 +#: ../pakfire/transaction.py:217 msgid "Is this okay?" msgstr "" -#: ../pakfire/transaction.py:225 +#: ../pakfire/transaction.py:223 msgid "Running transaction" msgstr "" -- 2.39.5