diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2010-05-06 16:15:53 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2010-05-06 16:15:53 +0200 |
commit | d1aa91622b3e0f7653889cab205e4c5c622162f4 (patch) | |
tree | 2daa36375c215c86df9b98c435d7899402748287 /cmdline | |
parent | 2d847a5919828ab26dd3f3c5993497b95df9051b (diff) | |
parent | d7087c493bf2fc7a0eaf6fa308c496c81e6dc98f (diff) |
merge with debian-experimental-ma
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/apt-cache.cc | 27 | ||||
-rw-r--r-- | cmdline/apt-get.cc | 50 | ||||
-rwxr-xr-x | cmdline/apt-mark | 3 |
3 files changed, 78 insertions, 2 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index b981e2fa7..10dbf44d2 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -14,7 +14,9 @@ /*}}}*/ // Include Files /*{{{*/ #include <apt-pkg/error.h> +#include <cassert> #include <apt-pkg/pkgcachegen.h> +#include <apt-pkg/cachefile.h> #include <apt-pkg/init.h> #include <apt-pkg/progress.h> #include <apt-pkg/sourcelist.h> @@ -1406,6 +1408,29 @@ bool Search(CommandLine &CmdL) return _error->Error("Write to stdout failed"); return true; } + + +/* show automatically installed packages (sorted) */ +bool ShowAuto(CommandLine &CmdL) +{ + OpProgress op; + pkgDepCache DepCache(GCache); + DepCache.Init(&op); + + std::vector<string> packages; + packages.reserve(GCache->HeaderP->PackageCount / 3); + + for (pkgCache::PkgIterator P = GCache->PkgBegin(); P.end() == false; P++) + if (DepCache[P].Flags & pkgCache::Flag::Auto) + packages.push_back(P.Name()); + + std::sort(packages.begin(), packages.end()); + + for (vector<string>::iterator I = packages.begin(); I != packages.end(); I++) + cout << *I << "\n"; + + return true; +} /*}}}*/ // ShowPackage - Dump the package record to the screen /*{{{*/ // --------------------------------------------------------------------- @@ -1777,6 +1802,7 @@ bool ShowHelp(CommandLine &Cmd) " unmet - Show unmet dependencies\n" " search - Search the package list for a regex pattern\n" " show - Show a readable record for the package\n" + " showauto - Display a list of automatically installed packages\n" " depends - Show raw dependency information for a package\n" " rdepends - Show reverse dependency information for a package\n" " pkgnames - List the names of all packages in the system\n" @@ -1841,6 +1867,7 @@ int main(int argc,const char *argv[]) /*{{{*/ {"xvcg",&XVcg}, {"show",&ShowPackage}, {"pkgnames",&ShowPkgNames}, + {"showauto",&ShowAuto}, {"policy",&Policy}, {"madison",&Madison}, {0,0}}; diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index de8c7aeaf..00da0855f 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1315,6 +1315,10 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, break; fuzzy = true; Ver = Pkg.VersionList(); + // exit right away from the Pkg.VersionList() loop if we + // don't have any versions + if (Ver.end() == true) + break; } // We match against a concrete version (or a part of this version) if (VerTag.empty() == false && @@ -1934,7 +1938,7 @@ bool DoInstall(CommandLine &CmdL) string target = Start.TargetPkg().FullName(true) + " "; pkgCache::PkgIterator const TarPkg = Start.TargetPkg(); if (TarPkg->SelectedState == pkgCache::State::Install || - TarPkg->SelectedState == pkgCache::State::Hold || + TarPkg->SelectedState == pkgCache::State::Hold || Cache[Start.TargetPkg()].Install()) { foundInstalledInOrGroup=true; @@ -2010,6 +2014,46 @@ bool DoInstall(CommandLine &CmdL) return InstallPackages(Cache,false); } + +/* mark packages as automatically/manually installed. */ +bool DoMarkAuto(CommandLine &CmdL) +{ + bool Action = true; + int AutoMarkChanged = 0; + OpTextProgress progress; + CacheFile Cache; + if (Cache.Open() == false) + return false; + + if (strcasecmp(CmdL.FileList[0],"markauto") == 0) + Action = true; + else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0) + Action = false; + + for (const char **I = CmdL.FileList + 1; *I != 0; I++) + { + const char *S = *I; + // Locate the package + pkgCache::PkgIterator Pkg = Cache->FindPkg(S); + if (Pkg.end() == true) { + return _error->Error(_("Couldn't find package %s"),S); + } + else + { + if (!Action) + ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name()); + else + ioprintf(c1out,_("%s set to automatically installed.\n"), + Pkg.Name()); + + Cache->MarkAuto(Pkg,Action); + AutoMarkChanged++; + } + } + if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false)) + return Cache->writeStateFile(NULL); + return false; +} /*}}}*/ // DoDistUpgrade - Automatic smart upgrader /*{{{*/ // --------------------------------------------------------------------- @@ -2796,6 +2840,8 @@ bool ShowHelp(CommandLine &CmdL) " clean - Erase downloaded archive files\n" " autoclean - Erase old downloaded archive files\n" " check - Verify that there are no broken dependencies\n" + " markauto - Mark the given packages as automatically installed\n" + " unmarkauto - Mark the given packages as manually installed\n" "\n" "Options:\n" " -h This help text.\n" @@ -2902,6 +2948,8 @@ int main(int argc,const char *argv[]) /*{{{*/ {"purge",&DoInstall}, {"autoremove",&DoInstall}, {"purge",&DoInstall}, + {"markauto",&DoMarkAuto}, + {"unmarkauto",&DoMarkAuto}, {"dist-upgrade",&DoDistUpgrade}, {"dselect-upgrade",&DoDSelectUpgrade}, {"build-dep",&DoBuildDep}, diff --git a/cmdline/apt-mark b/cmdline/apt-mark index 12768b708..c64d4356c 100755 --- a/cmdline/apt-mark +++ b/cmdline/apt-mark @@ -8,7 +8,7 @@ import os.path try: import apt_pkg except ImportError: - print "Error importing apt_pkg, is python-apt installed?" + print >> sys.stderr, "Error importing apt_pkg, is python-apt installed?" sys.exit(1) actions = { "markauto" : 1, @@ -68,6 +68,7 @@ if __name__ == "__main__": # option parsing parser = OptionParser() parser.usage = "%prog [options] {markauto|unmarkauto} packages..." + parser.epilog = "apt-mark is deprecated, use apt-get markauto/unmarkauto." parser.add_option("-f", "--file", action="store", type="string", dest="filename", help="read/write a different file") |