diff options
-rw-r--r-- | doc/en/manpage.xml | 32 | ||||
-rw-r--r-- | src/cmdline/Makefile.am | 2 | ||||
-rw-r--r-- | src/cmdline/cmdline_extract_cache_subset.cc | 128 | ||||
-rw-r--r-- | src/cmdline/cmdline_extract_cache_subset.h | 31 | ||||
-rw-r--r-- | src/main.cc | 4 |
5 files changed, 197 insertions, 0 deletions
diff --git a/doc/en/manpage.xml b/doc/en/manpage.xml index 4143c502..c05cedc8 100644 --- a/doc/en/manpage.xml +++ b/doc/en/manpage.xml @@ -106,6 +106,15 @@ <cmdsynopsis> <command>aptitude</command> + <arg choice='plain'>extract-cache-subset</arg> + + <arg choice='plain'><replaceable>output-directory</replaceable></arg> + <arg choice='plain' rep='repeat'><replaceable>packages</replaceable></arg> + </cmdsynopsis> + + <cmdsynopsis> + <command>aptitude</command> + <arg choice='opt' rep='repeat'><replaceable>options</replaceable></arg> <arg choice='plain'>search</arg> @@ -836,6 +845,29 @@ i A texlive-latex-extra Conflicts textopo</screen> </varlistentry> <varlistentry> + <term><literal>extract-cache-subset</literal></term> + + <listitem> + <para> + Extract a subset of the package cache to the specified + directory. If no packages are listed, the entire package + cache is copied; otherwise only the entries corresponding + to the named packages are copied. Each package name may + be a search pattern, and all the packages matching that + pattern will be selected (see the section <quote><link + linkend='secSearchPatterns'>Search Patterns</link></quote> + in the &aptitude; reference manual). Any existing package + lists in the output directory will be overwritten. + </para> + + <para> + Dependencies in binary package stanzas will be rewritten + to remove references to packages not in the selected set. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><literal>help</literal></term> <listitem> diff --git a/src/cmdline/Makefile.am b/src/cmdline/Makefile.am index 3c27b51f..f461cded 100644 --- a/src/cmdline/Makefile.am +++ b/src/cmdline/Makefile.am @@ -18,6 +18,8 @@ libcmdline_a_SOURCES=\ cmdline_download.h \ cmdline_dump_resolver.cc \ cmdline_dump_resolver.h \ + cmdline_extract_cache_subset.cc \ + cmdline_extract_cache_subset.h \ cmdline_forget_new.cc \ cmdline_forget_new.h \ cmdline_moo.cc \ diff --git a/src/cmdline/cmdline_extract_cache_subset.cc b/src/cmdline/cmdline_extract_cache_subset.cc new file mode 100644 index 00000000..845b52dd --- /dev/null +++ b/src/cmdline/cmdline_extract_cache_subset.cc @@ -0,0 +1,128 @@ +// cmdline_extract_cache_subset.cc +// +// Copyright (C) 2008 Daniel Burrows +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "cmdline_extract_cache_subset.h" + +#include "cmdline_util.h" + +#include <aptitude.h> + +#include <generic/apt/apt.h> +#include <generic/apt/dump_packages.h> +#include <generic/apt/matchers.h> + +#include <stdio.h> + +#include <apt-pkg/error.h> +#include <apt-pkg/progress.h> + +namespace aptitude +{ + namespace cmdline + { + int extract_cache_subset(int argc, char *argv[]) + { + if(argc < 2) + { + fprintf(stderr, _("extract-cache-entries: at least one argument is required (the directory\nto which to write files.\n")); + return -1; + } + + std::string out_dir = argv[1]; + + OpTextProgress progress; + + apt_init(&progress, true); + if(_error->PendingError()) + { + _error->DumpErrors(); + return -1; + } + + bool ok = true; + std::set<pkgCache::PkgIterator> packages; + if(argc == 2) + { + for(pkgCache::PkgIterator pIt = (*apt_cache_file)->PkgBegin(); + !pIt.end(); ++pIt) + packages.insert(pIt); + } + else + { + for(int i = 2; i < argc; ++i) + { + std::string arg(argv[i]); + + if(!cmdline_is_search_pattern(arg)) + { + pkgCache::PkgIterator pIt = (*apt_cache_file)->FindPkg(arg); + if(pIt.end()) + { + fprintf(stderr, _("No such package \"%s\".\n"), + arg.c_str()); + ok = false; + } + else + packages.insert(pIt); + } + else + { + aptitude::matching::pkg_matcher *m = + aptitude::matching::parse_pattern(arg, + std::vector<const char *>()); + + if(m == NULL) + { + _error->DumpErrors(); + } + else + { + for(pkgCache::PkgIterator pIt = (*apt_cache_file)->PkgBegin(); + !pIt.end(); ++pIt) + { + if(aptitude::matching::apply_matcher(m, + pIt, + *apt_cache_file, + *apt_package_records)) + packages.insert(pIt); + } + } + } + } + } + + if(!ok) + return 2; + + if(packages.size() == 0) + { + printf(_("No packages were selected by the given search pattern; nothing to do.\n")); + return 0; + } + + aptitude::apt::make_truncated_state_copy(out_dir, packages); + + bool copy_ok = !_error->PendingError(); + + _error->DumpErrors(); + + return copy_ok ? 0 : 1; + } + } +} diff --git a/src/cmdline/cmdline_extract_cache_subset.h b/src/cmdline/cmdline_extract_cache_subset.h new file mode 100644 index 00000000..87bce67a --- /dev/null +++ b/src/cmdline/cmdline_extract_cache_subset.h @@ -0,0 +1,31 @@ +// cmdline_extract_cache_subset.h -*-c++-*- +// +// Copyright (C) 2008 Daniel Burrows +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef CMDLINE_EXTRACT_CACHE_SUBSET_H +#define CMDLINE_EXTRACT_CACHE_SUBSET_H + +namespace aptitude +{ + namespace cmdline + { + int extract_cache_subset(int argc, char *argv[]); + } +} + +#endif // CMDLINE_EXTRACT_CACHE_SUBSET_H diff --git a/src/main.cc b/src/main.cc index 25dd34f1..1792010f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -50,6 +50,7 @@ #include <cmdline/cmdline_do_action.h> #include <cmdline/cmdline_download.h> #include <cmdline/cmdline_dump_resolver.h> +#include <cmdline/cmdline_extract_cache_subset.h> #include <cmdline/cmdline_forget_new.h> #include <cmdline/cmdline_moo.h> #include <cmdline/cmdline_prompt.h> @@ -637,6 +638,9 @@ int main(int argc, char *argv[]) !strcasecmp(argv[optind], "remove-user-tag")) return aptitude::cmdline::cmdline_user_tag(argc - optind, argv + optind, quiet, verbose); + else if(!strcasecmp(argv[optind], "extract-cache-subset")) + return aptitude::cmdline::extract_cache_subset(argc - optind, + argv + optind); else if(!strcasecmp(argv[optind], "download")) return cmdline_download(argc-optind, argv+optind); else if(!strcasecmp(argv[optind], "changelog")) |