diff options
author | Johannes Winkelmann <jw@smts.ch> | 2006-04-12 18:35:00 +0000 |
---|---|---|
committer | Johannes Winkelmann <jw@smts.ch> | 2006-04-12 18:35:00 +0000 |
commit | 97351c38522767c62c81861dc6f694e4716f9236 (patch) | |
tree | a340bdfae400a62aafa8a48980ed5c78ece1fbdb /src | |
parent | befaa350b1cf847a920d75edaf93fcb340c31288 (diff) | |
download | prt-get-97351c38522767c62c81861dc6f694e4716f9236.tar.gz prt-get-97351c38522767c62c81861dc6f694e4716f9236.tar.xz |
prt-get: add 'listorphans' command
git-svn-id: https://crux.nu/svn/tools/prt-get/trunk@1236 0b5ae1c7-2405-0410-a7fc-ba219f786e1e
Diffstat (limited to 'src')
-rw-r--r-- | src/argparser.cpp | 7 | ||||
-rw-r--r-- | src/argparser.h | 2 | ||||
-rw-r--r-- | src/main.cpp | 3 | ||||
-rw-r--r-- | src/prtget.cpp | 60 | ||||
-rw-r--r-- | src/prtget.h | 1 |
5 files changed, 67 insertions, 6 deletions
diff --git a/src/argparser.cpp b/src/argparser.cpp index 1aabbc4..85aa149 100644 --- a/src/argparser.cpp +++ b/src/argparser.cpp @@ -121,7 +121,7 @@ const string& ArgParser::alternateConfigFile() const */ bool ArgParser::parse() { - const int commandCount = 34; + const int commandCount = 35; string commands[commandCount] = { "list", "search", "dsearch", "info", "depends", "install", "depinst", @@ -132,7 +132,8 @@ bool ArgParser::parse() "dependent", "sysup", "current", "fsearch", "lock", "unlock", "listlocked", "cat", "ls", "edit", - "remove", "deptree", "dumpconfig" }; + "remove", "deptree", "dumpconfig", + "listorphans" }; Type commandID[commandCount] = { LIST, SEARCH, DSEARCH, INFO, DEPENDS, INSTALL, DEPINST, @@ -143,7 +144,7 @@ bool ArgParser::parse() DEPENDENT, SYSUP, CURRENT, FSEARCH, LOCK, UNLOCK, LISTLOCKED, CAT, LS, EDIT, REMOVE, DEPTREE, - DUMPCONFIG }; + DUMPCONFIG, LISTORPHANS }; if ( m_argc < 2 ) { return false; } diff --git a/src/argparser.h b/src/argparser.h index 0260f06..b560448 100644 --- a/src/argparser.h +++ b/src/argparser.h @@ -37,7 +37,7 @@ public: LISTINST, PRINTF, README, DEPENDENT, SYSUP, CURRENT, FSEARCH, LOCK, UNLOCK, LISTLOCKED, CAT, LS, EDIT, REMOVE, - DEPTREE, DUMPCONFIG }; + DEPTREE, DUMPCONFIG, LISTORPHANS }; bool isCommandGiven() const; bool isForced() const; diff --git a/src/main.cpp b/src/main.cpp index 64904af..abbd52f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -160,6 +160,9 @@ int main( int argc, char** argv ) case ArgParser::DUMPCONFIG: prtGet.dumpConfig(); break; + case ArgParser::LISTORPHANS: + prtGet.listOrphans(); + break; default: cerr << "unknown command" << endl; break; diff --git a/src/prtget.cpp b/src/prtget.cpp index 02fdc91..78e79f0 100644 --- a/src/prtget.cpp +++ b/src/prtget.cpp @@ -107,6 +107,8 @@ void PrtGet::printUsage() << endl; cout << " listinst [<filter>] show a list of installed ports" << endl; + cout << " listorphans list of ports with no " + << "packages depending on them" << endl; cout << " info <port> show info about a port" << endl; cout << " path <port> show path of a port" << endl; cout << " readme <port> show a port's readme file " @@ -145,6 +147,9 @@ void PrtGet::printUsage() cout << " where opt can be:" << endl; cout << " --all list all dependent packages, not " << "only installed" << endl; + cout << " --recursive print recursive listing" << endl; + cout << " --true print recursive tree listing" + << endl; cout << "\nSEARCHING" << endl; cout << " search <expr> show port names containing 'expr'" << endl; @@ -1280,8 +1285,17 @@ void PrtGet::printDependent(const string& dep, int level) } } } - - // prepared for recursive search + + // - there are two modes, tree and non-tree recursive mode; in + // tree mode, packages are shown multiple times, in non tree + // recursive mode they're only printed the first time; this is not + // necessarily optimal for rebuilding: + // + // a -> b -> d + // \ ^ + // > c / + // + // trying to rebuild 'd' before 'c' might possibly fail string indent = ""; if (m_parser->printTree()) { for (int i = 0; i < level; ++i) { @@ -1318,6 +1332,48 @@ void PrtGet::printDependent(const string& dep, int level) } } +void PrtGet::listOrphans() +{ + initRepo(); + map<string, string> installed = m_pkgDB->installedPackages(); + map<string, bool> required; + map<string, string>::iterator it = installed.begin(); + + for (; it != installed.end(); ++it) { + list<string> tokens; + const Package* p = m_repo->getPackage(it->first); + if (p) { + StringHelper::split( p->dependencies(), ',', tokens ); + list<string>::iterator lit = tokens.begin(); + for (; lit != tokens.end(); ++lit) { + required[*lit] = true; + } + } + } + + // - we could store the package pointer in another map to avoid + // another getPackage lockup, but it seems better to optimized for + // memory since it's only used when called with -vv + + it = installed.begin(); + for (; it != installed.end(); ++it) { + if (!required[it->first]) { + cout << it->first; + if ( m_parser->verbose() > 0 ) { + cout << " " << it->second; + } + if ( m_parser->verbose() > 1 ) { + const Package* p = m_repo->getPackage(it->first); + if (p) { + cout << ": " << p->description(); + } + } + cout << endl; + } + } +} + + void PrtGet::warnPackageNotFound(InstallTransaction& transaction) { cerr << "The package '"; diff --git a/src/prtget.h b/src/prtget.h index 602f8c2..1936b05 100644 --- a/src/prtget.h +++ b/src/prtget.h @@ -70,6 +70,7 @@ public: void printDependent(); void printDiff(); void printQuickDiff(); + void listOrphans(); void createCache(); |