Author: jw Date: 2006-04-12 20:35:00 +0200 (Wed, 12 Apr 2006) New Revision: 1236 Modified: tools/prt-get/trunk/ChangeLog tools/prt-get/trunk/TODO tools/prt-get/trunk/configure tools/prt-get/trunk/configure.in tools/prt-get/trunk/doc/prt-get.8 tools/prt-get/trunk/misc/prt-get_complete tools/prt-get/trunk/src/argparser.cpp tools/prt-get/trunk/src/argparser.h tools/prt-get/trunk/src/main.cpp tools/prt-get/trunk/src/prtget.cpp tools/prt-get/trunk/src/prtget.h Log: prt-get: add 'listorphans' command Modified: tools/prt-get/trunk/ChangeLog =================================================================== --- tools/prt-get/trunk/ChangeLog 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/ChangeLog 2006-04-12 18:35:00 UTC (rev 1236) @@ -13,6 +13,7 @@ - add timestamps to log files - fix aliasing bug introduce earlier in the .12 session (thanks Mark) - add --recursive and --tree for dependent +- add listorphans command * 0.5.11 29.05.2005 Johannes Winkelmann - add --path to 'ls' Modified: tools/prt-get/trunk/TODO =================================================================== --- tools/prt-get/trunk/TODO 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/TODO 2006-04-12 18:35:00 UTC (rev 1236) @@ -5,7 +5,6 @@ - add update-footprint, update-md5sum commands (patch in trac) - allow dependency injection for sysup, with previews - prefer toolchain (patch in trac) -- dependent --list-orphaned; should simplify pkgfoster - logging: check for non-root owned symlinks - logging: reject relative logfile names Modified: tools/prt-get/trunk/configure =================================================================== --- tools/prt-get/trunk/configure 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/configure 2006-04-12 18:35:00 UTC (rev 1236) @@ -1614,7 +1614,7 @@ # Define the identity of the package. PACKAGE=prt-get - VERSION=0.5.12pre4 + VERSION=0.5.12pre5 cat >>confdefs.h <<_ACEOF Modified: tools/prt-get/trunk/configure.in =================================================================== --- tools/prt-get/trunk/configure.in 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/configure.in 2006-04-12 18:35:00 UTC (rev 1236) @@ -1,7 +1,7 @@ # Process this file with autoconf to produce a configure script. AC_INIT AC_CONFIG_SRCDIR([src/prtget.cpp]) -AM_INIT_AUTOMAKE(prt-get,0.5.12pre4) +AM_INIT_AUTOMAKE(prt-get,0.5.12pre5) dnl Determine default prefix Modified: tools/prt-get/trunk/doc/prt-get.8 =================================================================== --- tools/prt-get/trunk/doc/prt-get.8 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/doc/prt-get.8 2006-04-12 18:35:00 UTC (rev 1236) @@ -322,8 +322,12 @@ .B wildcards for the listinst command. Make sure you escape where needed +.TP +.B listorphans [\-v|\-vv] +List installed ports which have no dependent packages + .TP .B isinst <package> Check whether a package is installed. The same as Modified: tools/prt-get/trunk/misc/prt-get_complete =================================================================== --- tools/prt-get/trunk/misc/prt-get_complete 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/misc/prt-get_complete 2006-04-12 18:35:00 UTC (rev 1236) @@ -20,7 +20,7 @@ dependent sysup current lock unlock \ listlocked diff quickdiff depends quickdep \ dup isinst cat ls edit deptree \ - remove listinst' $cur )) + remove listinst dumpconfig listofphans' $cur )) fi Modified: tools/prt-get/trunk/src/argparser.cpp =================================================================== --- tools/prt-get/trunk/src/argparser.cpp 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/src/argparser.cpp 2006-04-12 18:35:00 UTC (rev 1236) @@ -121,7 +121,7 @@ */ 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 @@ "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 @@ DEPENDENT, SYSUP, CURRENT, FSEARCH, LOCK, UNLOCK, LISTLOCKED, CAT, LS, EDIT, REMOVE, DEPTREE, - DUMPCONFIG }; + DUMPCONFIG, LISTORPHANS }; if ( m_argc < 2 ) { return false; } Modified: tools/prt-get/trunk/src/argparser.h =================================================================== --- tools/prt-get/trunk/src/argparser.h 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/src/argparser.h 2006-04-12 18:35:00 UTC (rev 1236) @@ -37,7 +37,7 @@ 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; Modified: tools/prt-get/trunk/src/main.cpp =================================================================== --- tools/prt-get/trunk/src/main.cpp 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/src/main.cpp 2006-04-12 18:35:00 UTC (rev 1236) @@ -160,6 +160,9 @@ case ArgParser::DUMPCONFIG: prtGet.dumpConfig(); break; + case ArgParser::LISTORPHANS: + prtGet.listOrphans(); + break; default: cerr << "unknown command" << endl; break; Modified: tools/prt-get/trunk/src/prtget.cpp =================================================================== --- tools/prt-get/trunk/src/prtget.cpp 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/src/prtget.cpp 2006-04-12 18:35:00 UTC (rev 1236) @@ -107,6 +107,8 @@ << 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 @@ 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 @@ } } } - - // 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::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 '"; Modified: tools/prt-get/trunk/src/prtget.h =================================================================== --- tools/prt-get/trunk/src/prtget.h 2006-04-12 17:32:37 UTC (rev 1235) +++ tools/prt-get/trunk/src/prtget.h 2006-04-12 18:35:00 UTC (rev 1236) @@ -70,6 +70,7 @@ void printDependent(); void printDiff(); void printQuickDiff(); + void listOrphans(); void createCache();