Skip to content

Commit

Permalink
Add 'download' command (Fate#317077)
Browse files Browse the repository at this point in the history
Download rpms specified on the commandline to a local directory.
  • Loading branch information
mlandres committed Apr 15, 2014
1 parent a667e9a commit cf93e58
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 0 deletions.
25 changes: 25 additions & 0 deletions doc/zypper.8
Expand Up @@ -1626,6 +1626,31 @@ of all licenses uses by the installed packages.
This command can be useful for companies redistributiong a custom
distribution (like appliances) to figure out what licenses they are bound by.

.TP
.B download
Download rpms specified on the commandline to a local directory.

Per default packages are downloaded to the libzypp package cache
(/var/cache/zypp/packages), but this can be changed by using the
global \fI--pkg-cache-dir\fR option.

In XML output a \fB<download-result>\fR node is written for each
package zypper tried to downlad. Upon success the local path is
is found in \fBdownload-result/localpath@path\fR.

.TP
.I \-d, \-\-directory <dir>
Download all source rpms to this directory. Default is \fB/var/cache/zypper/source-download\fR.

.TP
.I \-\-all-matches
Download all versions matching the commandline arguments. Otherwise only the best version of
each matching package is downloaded.

.TP
.I \-\-dry-run
Don't download any package, just report what would be done.

.TP
.B source-download
Download source rpms for all installed packages to a local directory.
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -19,6 +19,7 @@ SET (zypper_HEADERS
Table.h
locks.h
update.h
download.h
source-download.h
solve-commit.h
PackageArgs.h
Expand All @@ -42,6 +43,7 @@ SET( zypper_SRCS
Table.cc
locks.cc
update.cc
download.cc
source-download.cc
solve-commit.cc
PackageArgs.cc
Expand Down
2 changes: 2 additions & 0 deletions src/Command.cc
Expand Up @@ -78,6 +78,7 @@ namespace
_T( VERSION_CMP_e ) | "versioncmp" | "vcmp";
_T( LICENSES_e ) | "licenses";
_T( PS_e ) | "ps";
_T( DOWNLOAD_e ) | "download";
_T( SOURCE_DOWNLOAD_e ) | "source-download";

_T( HELP_e ) | "help" | "?";
Expand Down Expand Up @@ -152,6 +153,7 @@ DEF_ZYPPER_COMMAND( TARGET_OS );
DEF_ZYPPER_COMMAND( VERSION_CMP );
DEF_ZYPPER_COMMAND( LICENSES );
DEF_ZYPPER_COMMAND( PS );
DEF_ZYPPER_COMMAND( DOWNLOAD );
DEF_ZYPPER_COMMAND( SOURCE_DOWNLOAD );

DEF_ZYPPER_COMMAND( HELP );
Expand Down
2 changes: 2 additions & 0 deletions src/Command.h
Expand Up @@ -68,6 +68,7 @@ struct ZypperCommand
static const ZypperCommand VERSION_CMP;
static const ZypperCommand LICENSES;
static const ZypperCommand PS;
static const ZypperCommand DOWNLOAD;
static const ZypperCommand SOURCE_DOWNLOAD;

static const ZypperCommand HELP;
Expand Down Expand Up @@ -141,6 +142,7 @@ struct ZypperCommand
VERSION_CMP_e,
LICENSES_e,
PS_e,
DOWNLOAD_e,
SOURCE_DOWNLOAD_e,

HELP_e,
Expand Down
66 changes: 66 additions & 0 deletions src/Zypper.cc
Expand Up @@ -56,6 +56,7 @@
#include "locks.h"
#include "search.h"
#include "info.h"
#include "download.h"
#include "source-download.h"

#include "output/OutNormal.h"
Expand Down Expand Up @@ -272,6 +273,7 @@ void print_main_help(Zypper & zypper)
"\ttargetos, tos\t\tPrint the target operating system ID string.\n"
"\tlicenses\t\tPrint report about licenses and EULAs of\n"
"\t\t\t\tinstalled packages.\n"
"\tdownload\t\tDownload rpms specified on the commandline to a local directory.\n"
"\tsource-download\t\tDownload source rpms for all installed packages\n"
"\t\t\t\tto a local directory.\n"
);
Expand Down Expand Up @@ -2480,6 +2482,40 @@ void Zypper::processCommandOptions()
}


case ZypperCommand::DOWNLOAD_e:
{
shared_ptr<DownloadOptions> myOpts( new DownloadOptions() );
_commandOptions = myOpts;
static struct option options[] =
{
{"help", no_argument, 0, 'h'},
{"all-matches", no_argument, &myOpts->_allmatches, 1},
{"dry-run", no_argument, &myOpts->_dryrun, 1},
{0, 0, 0, 0}
};
specific_options = options;
_command_help = _(
"download [options] <packages>...\n"
"\n"
"Download rpms specified on the commandline to a local directory.\n"
"Per default packages are downloaded to the libzypp package cache\n"
"(/var/cache/zypp/packages), but this can be changed by using the\n"
"global --pkg-cache-dir option.\n"
"In XML output a <download-result> node is written for each\n"
"package zypper tried to downlad. Upon success the local path is\n"
"is found in 'download-result/localpath@path'.\n"
"\n"
" Command options:\n"
"--all-matches Download all versions matching the commandline\n"
" arguments. Otherwise only the best version of\n"
" each matching package is downloaded.\n"
"--dry-run Don't download any package, just report what\n"
" would be done.\n"
);
break;
}


case ZypperCommand::SOURCE_DOWNLOAD_e:
{
shared_ptr<SourceDownloadOptions> myOpts( new SourceDownloadOptions() );
Expand Down Expand Up @@ -4879,6 +4915,36 @@ void Zypper::doCommand()
break;
}


case ZypperCommand::DOWNLOAD_e:
{
if (runningHelp()) { out().info(_command_help, Out::QUIET); return; }

if (_arguments.empty())
{
report_required_arg_missing(out(), _command_help);
setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
return;
}

init_target( *this );
initRepoManager();
init_repos( *this );
if ( exitCode() != ZYPPER_EXIT_OK )
return;
// now load resolvables:
load_resolvables( *this );

shared_ptr<DownloadOptions> myOpts( assertCommandOptions<DownloadOptions>() );

if ( _copts.count( "dry-run" ) )
myOpts->_dryrun = true;

download( *this );
break;
}


case ZypperCommand::SOURCE_DOWNLOAD_e:
{
if (runningHelp()) { out().info(_command_help, Out::QUIET); return; }
Expand Down

0 comments on commit cf93e58

Please sign in to comment.