From 177b4e977dd6865ffa9062fae68c619a3f6d0b0d Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Sun, 18 Oct 2009 19:13:11 +0000 Subject: [PATCH] Add fetch command and fetch api to 2008... this will be used by upgrade tool --- branches/pisi-2.1/pisi/api.py | 21 ++++++++++ branches/pisi-2.1/pisi/cli/fetch.py | 56 +++++++++++++++++++++++++++ branches/pisi-2.1/pisi/cli/pisicli.py | 1 + 3 files changed, 78 insertions(+) create mode 100644 branches/pisi-2.1/pisi/cli/fetch.py diff --git a/branches/pisi-2.1/pisi/api.py b/branches/pisi-2.1/pisi/api.py index 1c7a944f..e84c6143 100644 --- a/branches/pisi-2.1/pisi/api.py +++ b/branches/pisi-2.1/pisi/api.py @@ -14,6 +14,7 @@ import fcntl import re import logging import logging.handlers +import fetcher import gettext __trans = gettext.translation('pisi', fallback=True) @@ -687,6 +688,26 @@ def __update_repo(repo, force=False): else: raise pisi.Error(_('No repository named %s found.') % repo) +def fetch(packages=[], path=os.path.curdir): + """ + Fetches the given packages from the repository without installing, just downloads the packages. + @param packages: list of package names -> list_of_strings + @param path: path to where the packages will be downloaded. If not given, packages will be downloaded + to the current working directory. + """ + packagedb = pisi.db.packagedb.PackageDB() + repodb = pisi.db.repodb.RepoDB() + for name in packages: + package, repo = packagedb.get_package_repo(name) + ctx.ui.info(_("%s package found in %s repository") % (package.name, repo)) + uri = pisi.uri.URI(package.packageURI) + if uri.is_absolute_path(): + url = str(pkg_uri) + else: + url = os.path.join(os.path.dirname(repodb.get_repo_url(repo)), str(uri.path())) + + fetcher.fetch_url(url, path, ctx.ui.Progress) + @locked def delete_cache(): pisi.util.clean_dir(ctx.config.cached_packages_dir()) diff --git a/branches/pisi-2.1/pisi/cli/fetch.py b/branches/pisi-2.1/pisi/cli/fetch.py new file mode 100644 index 00000000..571085c1 --- /dev/null +++ b/branches/pisi-2.1/pisi/cli/fetch.py @@ -0,0 +1,56 @@ +# -*- coding:utf-8 -*- +# +# Copyright (C) 2009, TUBITAK/UEKAE +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# Please read the COPYING file. +# + +import os +import optparse + +import gettext +__trans = gettext.translation('pisi', fallback=True) +_ = __trans.ugettext + +import pisi.cli.command as command +import pisi.context as ctx +import pisi.api + +class Fetch(command.Command): + __doc__ = _("""Fetch a package + +Usage: fetch [ ... ] + +: package name + +Downloads the given pisi packages to working directory +""") + __metaclass__ = command.autocommand + + def __init__(self,args): + super(Fetch, self).__init__(args) + + name = ("fetch", "fc") + + def options(self): + group = optparse.OptionGroup(self.parser, _("fetch options")) + self.add_options(group) + self.parser.add_option_group(group) + + def add_options(self, group): + group.add_option("-o", "--output-dir", action="store", default=os.path.curdir, + help=_("Output directory for the fetched packages")) + + def run(self): + self.init(database = False, write = False) + + if not self.args: + self.help() + return + + pisi.api.fetch(self.args, ctx.config.options.output_dir) diff --git a/branches/pisi-2.1/pisi/cli/pisicli.py b/branches/pisi-2.1/pisi/cli/pisicli.py index 27baf142..2b617103 100644 --- a/branches/pisi-2.1/pisi/cli/pisicli.py +++ b/branches/pisi-2.1/pisi/cli/pisicli.py @@ -28,6 +28,7 @@ import pisi.cli.configurepending import pisi.cli.deletecache import pisi.cli.delta import pisi.cli.emerge +import pisi.cli.fetch import pisi.cli.graph import pisi.cli.index import pisi.cli.info