From 7a1b1f8bd649113e99ecef0489e2f2194e283d1e Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Mon, 20 Sep 2004 16:51:33 +0000 Subject: Dselect support Author: jgg Date: 1998-11-22 23:37:03 GMT Dselect support --- cmdline/apt-config.cc | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ cmdline/apt-get.cc | 12 +++-- cmdline/makefile | 8 +++- 3 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 cmdline/apt-config.cc (limited to 'cmdline') diff --git a/cmdline/apt-config.cc b/cmdline/apt-config.cc new file mode 100644 index 000000000..7dfb59192 --- /dev/null +++ b/cmdline/apt-config.cc @@ -0,0 +1,119 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: apt-config.cc,v 1.1 1998/11/22 23:37:07 jgg Exp $ +/* ###################################################################### + + APT Config - Program to manipulate APT configuration files + + This program will parse a config file and then do something with it. + + Commands: + shell - Shell mode. After this a series of word pairs should occure. + The first is the environment var to set and the second is + the key to set it from. Use like: + eval `apt-config shell QMode apt::QMode` + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include +#include +#include +#include "config.h" + +#include + /*}}}*/ + +// DoShell - Handle the shell command /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool DoShell(CommandLine &CmdL) +{ + for (const char **I = CmdL.FileList + 1; *I != 0; I += 2) + { + if (I[1] == 0) + return _error->Error("Arguments not in pairs"); + if (_config->Exists(I[1]) == true) + cout << *I << "=\"" << _config->Find(I[1]) << '"' << endl; + } + + return true; +} + /*}}}*/ +// ShowHelp - Show the help screen /*{{{*/ +// --------------------------------------------------------------------- +/* */ +int ShowHelp() +{ + cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE << + " compiled on " << __DATE__ << " " << __TIME__ << endl; + + cout << "Usage: apt-config [options] command" << endl; + cout << endl; + cout << "apt-config is a simple tool to read the APT config file" << endl; + cout << endl; + cout << "Commands:" << endl; + cout << " shell - Shell mode" << endl; + cout << endl; + cout << "Options:" << endl; + cout << " -h This help text." << endl; + cout << " -c=? Read this configuration file" << endl; + cout << " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl; + return 100; +} + /*}}}*/ + +int main(int argc,const char *argv[]) +{ + CommandLine::Args Args[] = { + {'h',"help","help",0}, + {'c',"config-file",0,CommandLine::ConfigFile}, + {'o',"option",0,CommandLine::ArbItem}, + {0,0,0,0}}; + + // Parse the command line and initialize the package library + CommandLine CmdL(Args,_config); + if (pkgInitialize(*_config) == false || + CmdL.Parse(argc,argv) == false) + { + _error->DumpErrors(); + return 100; + } + + // See if the help should be shown + if (_config->FindB("help") == true || + CmdL.FileSize() == 0) + return ShowHelp(); + + // Match the operation + struct + { + const char *Match; + bool (*Handler)(CommandLine &); + } Map[] = {{"shell",&DoShell}, + {0,0}}; + int I; + for (I = 0; Map[I].Match != 0; I++) + { + if (strcmp(CmdL.FileList[0],Map[I].Match) == 0) + { + if (Map[I].Handler(CmdL) == false && _error->PendingError() == false) + _error->Error("Handler silently failed"); + break; + } + } + + // No matching name + if (Map[I].Match == 0) + _error->Error("Invalid operation %s", CmdL.FileList[0]); + + // Print any errors or warnings found during parsing + if (_error->empty() == false) + { + bool Errors = _error->PendingError(); + _error->DumpErrors(); + return Errors == true?100:0; + } + + return 0; +} diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index e00cf53c3..279a0c4ed 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: apt-get.cc,v 1.15 1998/11/22 03:20:36 jgg Exp $ +// $Id: apt-get.cc,v 1.16 1998/11/22 23:37:07 jgg Exp $ /* ###################################################################### apt-get - Cover for dpkg @@ -502,11 +502,13 @@ bool InstallPackages(pkgDepCache &Cache,bool ShwKept,bool Ask = true) if (PM.GetArchives(&Fetcher,&List,&Recs) == false) return false; + // Display statistics unsigned long FetchBytes = Fetcher.FetchNeeded(); unsigned long DebBytes = Fetcher.TotalNeeded(); if (DebBytes != Cache.DebSize()) c0out << "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl; + // Number of bytes c1out << "Need to get "; if (DebBytes != FetchBytes) c1out << SizeToStr(FetchBytes) << '/' << SizeToStr(DebBytes); @@ -515,6 +517,7 @@ bool InstallPackages(pkgDepCache &Cache,bool ShwKept,bool Ask = true) c1out << " of archives. After unpacking "; + // Size delta if (Cache.UsrSize() >= 0) c1out << SizeToStr(Cache.UsrSize()) << " will be used." << endl; else @@ -523,6 +526,7 @@ bool InstallPackages(pkgDepCache &Cache,bool ShwKept,bool Ask = true) if (_error->PendingError() == true) return false; + // Prompt to continue if (Ask == true) { if (_config->FindI("quiet",0) < 2 || @@ -783,10 +787,7 @@ bool DoInstall(CommandLine &CmdL) // See if we need to prompt if (Cache->InstCount() == ExpectedInst && Cache->DelCount() == 0) - { - cout << "Boink" << endl; return InstallPackages(Cache,false,false); - } return InstallPackages(Cache,false); } @@ -867,6 +868,9 @@ bool DoDSelectUpgrade(CommandLine &CmdL) /* */ bool DoClean(CommandLine &CmdL) { + pkgAcquire Fetcher; + Fetcher.Clean(_config->FindDir("Dir::Cache::archives")); + Fetcher.Clean(_config->FindDir("Dir::Cache::archives") + "partial/"); return true; } /*}}}*/ diff --git a/cmdline/makefile b/cmdline/makefile index d3c1012d9..e52328440 100644 --- a/cmdline/makefile +++ b/cmdline/makefile @@ -11,8 +11,14 @@ SLIBS = -lapt-pkg SOURCE = apt-cache.cc include $(PROGRAM_H) -# The apt-config program +# The apt-get program PROGRAM=apt-get SLIBS = -lapt-pkg SOURCE = apt-get.cc acqprogress.cc include $(PROGRAM_H) + +# The apt-config program +PROGRAM=apt-config +SLIBS = -lapt-pkg +SOURCE = apt-config.cc +include $(PROGRAM_H) -- cgit v1.2.3