diff --git a/ChangeLog b/ChangeLog index f17a683..3da91cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ * 5.15 27.09.2006 Johannes Winkelmann - fix PKGMK_PACKAGE_DIR determination +- add --depsort to 'listinst' * 5.14 13.09.2006 Johannes Winkelmann - Remove handling of external dependency list diff --git a/doc/prt-get.8 b/doc/prt-get.8 index 8a477e2..30d3d93 100644 --- a/doc/prt-get.8 +++ b/doc/prt-get.8 @@ -332,7 +332,7 @@ to filter by package name. .TP -.B listinst [\-v|\-vv] [filter] [--regex] +.B listinst [\-v|\-vv] [filter] [--regex] [--depsort] List installed ports. It's basically the same as .B pkginfo \-i, but omits version when called without verbose (\-v, \-vv) switch. Plus @@ -343,7 +343,9 @@ adds version and description. both the ports database and the ports tree. It's also possible to use shell like .B wildcards -for the listinst command. Make sure you escape where needed +for the listinst command. Make sure you escape where needed. Finally, by +default it's sorted alphabetically; use the \-\-depsort switch to sort by +dependencies .TP .B listorphans [\-v|\-vv] diff --git a/src/argparser.cpp b/src/argparser.cpp index 85aa149..b971212 100644 --- a/src/argparser.cpp +++ b/src/argparser.cpp @@ -47,7 +47,8 @@ ArgParser::ArgParser( int argc, char** argv ) m_useRegex(false), m_fullPath(false), m_recursive(false), - m_printTree(false) + m_printTree(false), + m_depSort(false) { } @@ -203,6 +204,8 @@ bool ArgParser::parse() m_recursive = true; } else if ( s == "--tree" ) { m_printTree = true; + } else if ( s == "--depsort" ) { + m_depSort = true; } else if ( s == "-f" ) { m_pkgaddArgs += " " + s; @@ -399,6 +402,11 @@ bool ArgParser::printTree() const return m_printTree; } +bool ArgParser::depSort() const +{ + return m_depSort; +} + const string& ArgParser::commandName() const { return m_commandName; diff --git a/src/argparser.h b/src/argparser.h index b560448..c24e7bd 100644 --- a/src/argparser.h +++ b/src/argparser.h @@ -59,6 +59,7 @@ public: bool fullPath() const; bool recursive() const; bool printTree() const; + bool depSort() const; const string& alternateConfigFile() const; const string& pkgmkArgs() const; @@ -111,6 +112,8 @@ private: bool m_recursive; bool m_printTree; + + bool m_depSort; string m_alternateConfigFile; string m_pkgmkArgs; diff --git a/src/installtransaction.cpp b/src/installtransaction.cpp index 977b9e0..4cdd756 100644 --- a/src/installtransaction.cpp +++ b/src/installtransaction.cpp @@ -41,7 +41,27 @@ const string InstallTransaction::PKGMK_DEFAULT_COMMAND = "/usr/bin/pkgmk"; const string InstallTransaction::PKGADD_DEFAULT_COMMAND = "/usr/bin/pkgadd"; const string InstallTransaction::PKGRM_DEFAULT_COMMAND = "/usr/bin/pkgrm"; +/*! + Create a nice InstallTransaction + \param names a list of port names to be installed + \param repo the repository to look for packages + \param pkgDB the pkgDB with already installed packages +*/ +InstallTransaction::InstallTransaction( const list& names, + const Repository* repo, + PkgDB* pkgDB, + const Configuration* config ) + : m_repo( repo ), + m_pkgDB( pkgDB ), + m_depCalced( false ), + m_config( config ) +{ + list::const_iterator it = names.begin(); + for ( ; it != names.end(); ++it ) { + m_packages.push_back( make_pair( *it, m_repo->getPackage( *it ) ) ); + } +} /*! Create a nice InstallTransaction @@ -65,13 +85,15 @@ InstallTransaction::InstallTransaction( const list& names, } + + /*! Create a nice InstallTransaction \param names a list of port names to be installed \param repo the repository to look for packages \param pkgDB the pkgDB with already installed packages */ -InstallTransaction::InstallTransaction( const list& names, +InstallTransaction::InstallTransaction( const string& name, const Repository* repo, PkgDB* pkgDB, const Configuration* config ) @@ -80,10 +102,7 @@ InstallTransaction::InstallTransaction( const list& names, m_depCalced( false ), m_config( config ) { - list::const_iterator it = names.begin(); - for ( ; it != names.end(); ++it ) { - m_packages.push_back( make_pair( *it, m_repo->getPackage( *it ) ) ); - } + m_packages.push_back( make_pair( name, m_repo->getPackage( name ) ) ); } @@ -592,7 +611,7 @@ string InstallTransaction::getPkgDest() const if (pkgdest.size() == 0) { pkgdest = getPkgDestFromFile("/usr/bin/pkgmk"); } - + m_pkgDest = pkgdest; return pkgdest; } @@ -602,7 +621,7 @@ string InstallTransaction::getPkgDestFromFile(const string& fileName) FILE* fp = fopen(fileName.c_str(), "r"); if (!fp) return ""; - + string candidate; string s; char line[256]; @@ -624,7 +643,7 @@ string InstallTransaction::getPkgDestFromFile(const string& fileName) fclose(p); } } - + return pkgdest; } diff --git a/src/installtransaction.h b/src/installtransaction.h index 0d46e45..92cf6ba 100644 --- a/src/installtransaction.h +++ b/src/installtransaction.h @@ -41,6 +41,10 @@ public: const Repository* repo, PkgDB* pkgDB, const Configuration* config ); + InstallTransaction( const string& name, + const Repository* repo, + PkgDB* pkgDB, + const Configuration* config ); static const std::string PKGMK_DEFAULT_COMMAND; static const std::string PKGADD_DEFAULT_COMMAND; @@ -130,7 +134,7 @@ private: list m_depNameList; vector m_depList; - + // field for error messages mutable string m_pkgDest; diff --git a/src/prtget.cpp b/src/prtget.cpp index 6f785cd..d1709d8 100644 --- a/src/prtget.cpp +++ b/src/prtget.cpp @@ -111,7 +111,7 @@ void PrtGet::printUsage() cout << " printf print formatted list of available" << " ports" << endl; - cout << " listinst [] show a list of installed ports" + cout << " listinst [][--depsort] show a list of installed ports" << endl; cout << " listorphans list of ports with no " << "packages depending on them" << endl; @@ -536,24 +536,53 @@ void PrtGet::listInstalled() return; } - if ( m_parser->verbose() > 1 ) { - // warning: will slow down the process... - initRepo(); - } + if (m_parser->depSort()) { + // sort by dependency, without injecting missing ones + // calcDependencies chokes on the full list, so go through the + // ports one by one + + initRepo(); + map::iterator mit; + string name; + while (!l.empty()) { + mit = l.begin(); + name = mit->first; + l.erase(mit); + + InstallTransaction trans( name, m_repo, m_pkgDB, m_config ); + InstallTransaction::InstallResult result = trans.calcDependencies(); + const list& depRef = trans.dependencies(); + list::const_iterator it = depRef.begin(); - for ( ; it != l.end(); ++it ) { - cout << it->first.c_str(); - if ( m_parser->verbose() > 0 ) { - cout << " " << it->second.c_str(); - } - if ( m_parser->verbose() > 1 ) { - const Package* p = m_repo->getPackage( it->first ); - if ( p ) { - cout << " " << p->description(); - } - } - cout << endl; + for (; it != depRef.end(); ++it) { + if (l.find(*it) != l.end()) { + cout << *it << endl; + l.erase(*it); + } + } + cout << name << endl; + } + + } else { + for ( ; it != l.end(); ++it ) { + if ( m_parser->verbose() > 1 ) { + // warning: will slow down the process... + initRepo(); + } + cout << it->first.c_str(); + if ( m_parser->verbose() > 0 ) { + cout << " " << it->second.c_str(); + } + if ( m_parser->verbose() > 1 ) { + const Package* p = m_repo->getPackage( it->first ); + if ( p ) { + cout << " " << p->description(); + } + } + + cout << endl; + } } } @@ -659,7 +688,7 @@ void PrtGet::executeTransaction( InstallTransaction& transaction, cout << m_appName << " couldn't excecute pkgadd. " << "Make sure it's installed properly" << endl; } else if ( result == InstallTransaction::PKGDEST_ERROR ) { - cout << m_appName << ": error changing to PKGDEST directory " + cout << m_appName << ": error changing to PKGDEST directory " << transaction.pkgDest() << endl; failed = true; } else if ( result == InstallTransaction::PKGADD_FAILURE ) {