from . import client
from . import config
from . import daemon
+from . import downloaders
from . import packages
from . import repository
from . import ui
for line in t.splitlines():
self.ui.message(line)
+ def _download_transaction(self, transaction):
+ """
+ Downloads all packages required for this transaction
+ """
+ d = downloaders.TransactionDownloader(self.pakfire, transaction)
+
+ # Run the download
+ d.download()
+
def _execute_transaction(self, transaction):
# Don't do anything if the transaction is empty
if len(transaction) == 0:
self.ui.message(_("Aborted by user"))
return
+ # Download transaction
+ self._download_transaction(transaction)
+
# Run the transaction
transaction.run()
log = logging.getLogger("pakfire.downloader")
log.propagate = 1
-
class Downloader(object):
pass
# XXX compare checksum here
downloader.retrieve("repodata/%s" % self.metadata.database, filename=path,
message=_("%s: package database") % self.repo.name)
+
+ def download_package(self, pkg):
+ """
+ Downloads a package to it's cache path
+ """
+ downloader = self.make_downloader()
+
+ downloader.retrieve(pkg.filename, filename=pkg.cache_path,
+ message="%s" % pkg, checksum_algo="sha1", checksum=pkg.checksum)
+
+
+class TransactionDownloader(Downloader):
+ def __init__(self, pakfire, transaction):
+ self.pakfire = pakfire
+
+ # The transaction that we process
+ self.transaction = transaction
+
+ # Cache repository downloaders
+ self._repo_downloaders = {}
+
+ def _get_repo_downloader(self, repo):
+ try:
+ return self._repo_downloaders[repo]
+ except KeyError:
+ d = RepositoryDownloader(self.pakfire, repo)
+ self._repo_downloaders[repo] = d
+
+ return d
+
+ def download(self):
+ for step in self.transaction:
+ # Skip any steps that do not need a download
+ if not step.needs_download:
+ continue
+
+ # Get the downloader
+ downloader = self._get_repo_downloader(step.package.repo)
+
+ # Download the package
+ downloader.download_package(step.package)