implement --depsort for listinst

This commit is contained in:
Johannes Winkelmann 2006-10-19 10:34:44 +02:00
parent 497c60f0a8
commit 23d8373672
7 changed files with 96 additions and 30 deletions

View File

@ -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

View File

@ -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]

View File

@ -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;

View File

@ -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;

View File

@ -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<string>& names,
const Repository* repo,
PkgDB* pkgDB,
const Configuration* config )
: m_repo( repo ),
m_pkgDB( pkgDB ),
m_depCalced( false ),
m_config( config )
{
list<string>::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<char*>& 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<string>& names,
InstallTransaction::InstallTransaction( const string& name,
const Repository* repo,
PkgDB* pkgDB,
const Configuration* config )
@ -80,10 +102,7 @@ InstallTransaction::InstallTransaction( const list<string>& names,
m_depCalced( false ),
m_config( config )
{
list<string>::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;
}

View File

@ -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<string> m_depNameList;
vector<string> m_depList;
// field for error messages
mutable string m_pkgDest;

View File

@ -111,7 +111,7 @@ void PrtGet::printUsage()
cout << " printf <format> print formatted list of available"
<< " ports"
<< endl;
cout << " listinst [<filter>] show a list of installed ports"
cout << " listinst [<filter>][--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<string, string>::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<string>& depRef = trans.dependencies();
list<string>::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 ) {