Download all before installing, report errors

This commit is contained in:
Faik Uygur
2008-02-26 09:34:39 +00:00
parent aaf2b1dfea
commit deb0c119ad
2 changed files with 47 additions and 2 deletions
+6 -2
View File
@@ -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)
+41
View File
@@ -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