From deb0c119ad2fca8ecd31d75e41f87d1455d5cd94 Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Tue, 26 Feb 2008 09:34:39 +0000 Subject: [PATCH] Download all before installing, report errors --- pisi/db/repodb.py | 8 ++++++-- pisi/operations/history.py | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/pisi/db/repodb.py b/pisi/db/repodb.py index eda29d35..58de91c1 100644 --- a/pisi/db/repodb.py +++ b/pisi/db/repodb.py @@ -112,10 +112,14 @@ class RepoDB(lazydb.LazyDB): return piksemel.parse(index_path) def get_repo(self, repo): + return Repo(pisi.uri.URI(self.get_repo_url(repo))) + + #FIXME: this method is a quick hack around repo_info.indexuri.get_uri() + def get_repo_url(self, repo): urifile_path = pisi.util.join_path(ctx.config.index_dir(), repo, "uri") uri = open(urifile_path, "r").read() - return Repo(pisi.uri.URI(uri)) - + return uri + def add_repo(self, name, repo_info, at = None): repo_path = pisi.util.join_path(ctx.config.index_dir(), name) os.makedirs(repo_path) diff --git a/pisi/operations/history.py b/pisi/operations/history.py index 7c2cd717..799c65a1 100644 --- a/pisi/operations/history.py +++ b/pisi/operations/history.py @@ -9,6 +9,7 @@ # # Please read the COPYING file. +import os import gettext __trans = gettext.translation("pisi", fallback=True) _ = __trans.ugettext @@ -16,6 +17,7 @@ _ = __trans.ugettext import pisi.context as ctx import pisi.util import pisi.db +import pisi.fetcher def __listactions(actions): beinstalled = [] @@ -30,6 +32,32 @@ def __listactions(actions): return beinstalled, beremoved +def __getpackageurl(package): + packagedb = pisi.db.packagedb.PackageDB() + repodb = pisi.db.repodb.RepoDB() + + pkg, ver = pisi.util.parse_package_name(package) + reponame = packagedb.which_repo(pkg) + repourl = repodb.get_repo_url(reponame) + + ctx.ui.info(_("Package %s found in repository %s") % (pkg, reponame)) + + #return _possible_ url for this package + return os.path.join(os.path.dirname(repourl), package) + +def fetch_remote_file(package, errors): + uri = pisi.file.File.make_uri(__getpackageurl(package)) + dest = ctx.config.cached_packages_dir() + filepath = os.path.join(dest, uri.filename()) + if not os.path.exists(filepath): + try: + pisi.fetcher.fetch_url(uri, dest, ctx.ui.Progress) + except pisi.fetcher.FetchError, e: + errors.append(package) + ctx.ui.info(pisi.util.colorize(_("%s could not be found") % (package), "red")) + else: + ctx.ui.info(_('%s [cached]') % uri.filename()) + def takeback(operation): historydb = pisi.db.historydb.HistoryDB() @@ -55,3 +83,16 @@ def takeback(operation): if (beremoved or beinstalled) and not ctx.ui.confirm(_('Do you want to continue?')): return + + errors = [] + paths = [] + for pkg in beinstalled: + ctx.ui.info(pisi.util.colorize(_("Downloading %d / %d") % (beinstalled.index(pkg)+1, len(beinstalled)), "yellow")) + fetch_remote_file(pkg, errors) + paths.append(os.path.join(ctx.config.cached_packages_dir(), pkg)) + + if errors: + ctx.ui.info(_("\nFollowing packages could not be found in repositories and are not cached:\n") + + pisi.util.strlist(errors)) + if not ctx.ui.confirm(_('Do you want to continue?')): + return