prt-get: support recursive dependent and a tree view

git-svn-id: https://crux.nu/svn/tools/prt-get/trunk@1234 0b5ae1c7-2405-0410-a7fc-ba219f786e1e
This commit is contained in:
Johannes Winkelmann 2006-04-12 16:06:17 +00:00
parent a4a40a4b02
commit ab768a4a88
10 changed files with 68 additions and 15 deletions

View File

@ -12,6 +12,7 @@
- update default prt-get.conf to reflect new port hierarchy (core/opt/contrib)
- add timestamps to log files
- fix aliasing bug introduce earlier in the .12 session (thanks Mark)
- add --recursive and --tree for dependent
* 0.5.11 29.05.2005 Johannes Winkelmann
- add --path to 'ls'

2
TODO
View File

@ -1,3 +1,5 @@
- add --rebuild-set to dependent
---------------------------
- use `eval $(fgrep -h 'PKGMK_PACKAGE_DIR=' $(which pkgmk) /etc/pkgmk.conf) && echo
$PKGMK_PACKAGE_DIR` to determine PACKAGE_DIR
- add update-footprint, update-md5sum commands (patch in trac)

2
configure vendored
View File

@ -1614,7 +1614,7 @@ fi
# Define the identity of the package.
PACKAGE=prt-get
VERSION=0.5.12pre2
VERSION=0.5.12pre4
cat >>confdefs.h <<_ACEOF

View File

@ -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.12pre2)
AM_INIT_AUTOMAKE(prt-get,0.5.12pre4)
dnl Determine default prefix

View File

@ -209,9 +209,11 @@ to make an install including dependencies
.TP
.B dependent <package>
print a list of package which depend on
.B package.
Only list direct dependencies. Usually shows dependent packages which
are installed. To see all dependencies, add the --all switch
.B package.
Usually shows dependent packages which are installed. To see all dependencies,
add the --all switch; use --recursive to get a recursive list (without
duplication), and --tree to get a nicely indented one
.TP
.B deptree <package>

View File

@ -45,7 +45,9 @@ ArgParser::ArgParser( int argc, char** argv )
m_preferHigher( false ),
m_strictDiff( false ),
m_useRegex(false),
m_fullPath(false)
m_fullPath(false),
m_recursive(false),
m_printTree(false)
{
}
@ -196,6 +198,10 @@ bool ArgParser::parse()
m_useRegex = true;
} else if ( s == "--full" ) {
m_fullPath = true;
} else if ( s == "--recursive" ) {
m_recursive = true;
} else if ( s == "--tree" ) {
m_printTree = true;
} else if ( s == "-f" ) {
m_pkgaddArgs += " " + s;
@ -382,6 +388,16 @@ bool ArgParser::printPath() const
return m_printPath;
}
bool ArgParser::recursive() const
{
return m_recursive;
}
bool ArgParser::printTree() const
{
return m_printTree;
}
const string& ArgParser::commandName() const
{
return m_commandName;

View File

@ -57,6 +57,8 @@ public:
bool strictDiff() const;
bool useRegex() const;
bool fullPath() const;
bool recursive() const;
bool printTree() const;
const string& alternateConfigFile() const;
const string& pkgmkArgs() const;
@ -107,6 +109,9 @@ private:
bool m_useRegex;
bool m_fullPath;
bool m_recursive;
bool m_printTree;
string m_alternateConfigFile;
string m_pkgmkArgs;
string m_pkgaddArgs;

View File

@ -26,7 +26,7 @@ int main( int argc, char** argv )
<< endl;
} else if ( !argParser.isCommandGiven() ) {
if (argParser.commandName() != "") {
cerr << "prt-get: Unknown command '"
cerr << "prt-get: Unknown command '"
<< argParser.commandName() << "'. "
<< "try prt-get help for more information" << endl;
} else {
@ -122,7 +122,7 @@ int main( int argc, char** argv )
prtGet.readme();
break;
case ArgParser::DEPENDENT:
prtGet.printDependendent();
prtGet.printDependent();
break;
case ArgParser::SYSUP:
prtGet.sysup();

View File

@ -1244,37 +1244,58 @@ bool PrtGet::printFile(const string& file)
return true;
}
void PrtGet::printDependendent()
void PrtGet::printDependent()
{
assertExactArgCount(1);
initRepo();
string arg = *(m_parser->otherArgs().begin());
printDependent(arg, 0);
}
void PrtGet::printDependent(const string& dep, int level)
{
map<string, Package*>::const_iterator it = m_repo->packages().begin();
static map<string, bool> shownMap;
set<const Package*> dependent;
for ( ; it != m_repo->packages().end(); ++it ) {
// TODO: is the following line needed?
const Package* p = it->second;
if ( p && p->dependencies().find( arg ) != string::npos ) {
if ( p && p->dependencies().find( dep ) != string::npos ) {
list<string> tokens;
StringHelper::split( p->dependencies(), ',', tokens );
list<string>::iterator it = find( tokens.begin(),
tokens.end(),
arg );
dep );
if ( it != tokens.end() ) {
dependent.insert( p );
}
}
}
// prepared for recursive search
string indent = "";
if (m_parser->printTree()) {
for (int i = 0; i < level; ++i) {
indent += " ";
}
}
set<const Package*>::iterator it2 = dependent.begin();
for ( ; it2 != dependent.end(); ++it2 ) {
const Package* p = *it2;
if (m_parser->recursive() && !m_parser->printTree()) {
if (shownMap[p->name()]) {
continue;
}
shownMap[p->name()] = true;
}
if ( m_parser->all() || m_pkgDB->isInstalled( p->name() ) ) {
cout << p->name();
cout << indent << p->name();
if ( m_parser->verbose() > 0 ) {
cout << " " << p->version() << "-" << p->release();
}
@ -1283,6 +1304,10 @@ void PrtGet::printDependendent()
}
cout << endl;
if (m_parser->recursive()) {
printDependent( p->name(), level+2 );
}
}
}
}

View File

@ -67,7 +67,7 @@ public:
void current();
void printDepends( bool simpleListing=false );
void printDependTree();
void printDependendent();
void printDependent();
void printDiff();
void printQuickDiff();
@ -96,6 +96,8 @@ public:
protected:
void printDepsLevel(int indent, const Package* package);
void printDependent(const std::string& dep, int level);
void executeTransaction( InstallTransaction& transaction,
bool update, bool group );
@ -140,7 +142,7 @@ protected:
void assertMaxArgCount(int count);
void assertExactArgCount(int count);
void argCountFailure(int count, const string& specifier);
bool greaterThan( const string& v1, const string& v2 );
static bool printFile(const string& file);
};