]> git.ipfire.org Git - pakfire.git/commitdiff
Add option to throttle download speed.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2011 21:22:51 +0000 (23:22 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2011 21:22:51 +0000 (23:22 +0200)
examples/pakfire.conf
pakfire/downloader.py
pakfire/packages/make.py
pakfire/repository/index.py
pakfire/server.py
po/pakfire.pot

index cf947d104aabc761672f7ad54ad5d54ec63b1550..79e1a8f7e1b7540b3858305cfd2f01601ea95b65 100644 (file)
@@ -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
index b920da29abcfb5641f6a8e72da3f72e1f6fe78f7..b5d61d02774a79189092167773b8a63d411e1c87 100644 (file)
@@ -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)
index 605c4e0bef5c90db7895bd428acb28bc2b420580..fb2dbeb2890aaa452f39dd510e9b6be9dc6439ad 100644 (file)
@@ -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(),
index 0e9346b88dc0c8c9057534e314d438f2bb5c7fc3..cccf339ad56cb803871a791569bffc7f387d73cc 100644 (file)
@@ -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)
index 79c0c33826b792ab07c7abf9a794f1c39ac2d23c..9d4c2c6fd88ae8d4a9e55cde8c3a9fe0f33095ec 100644 (file)
@@ -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.
index ca2756b91ae54f71773547454345b4b600863488..7ef03bc774962eaa5727d0d5b6d7a1852da38986 100644 (file)
@@ -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 <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\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 ""