Hello, I wrote a patch for listing 'Nice to have' dependencies with prt-get Sometimes I want to known these nice-to-have ports, but I'm not a bash guru and often I use large lines: $ prt-get cat pinentry Pkgfile | grep '^# Nice to have:' | cut -d':' -f2 | sed -e 's/ //g' -e 's/,/ /' gtk qt3 prt-get nicetohave sounds better imho : ) i.e: $ prt-get info pinentry Name: pinentry Path: /usr/ports/opt Version: 0.7.5 Release: 1 Description: Secure PinEntry Dialog URL: http://www.gnupg.org Packager: Alan Mizrahi, alan at mizrahi dot com dot ve Maintainer: Simon Gloßner, viper at hometux dot de Dependencies: ncurses Nice to have: gtk,qt3 $ prt-get nicetohave pinentry gtk qt3 It's not a big changeset, just a little patch which does the trick. I think it could be useful for others, what are your opinions? I attached the patch, for everyone who want to test it and/or give suggestions. Best regards, Jose V Beneyto diff --git a/src/argparser.cpp b/src/argparser.cpp index b971212..f3ac37e 100644 --- a/src/argparser.cpp +++ b/src/argparser.cpp @@ -122,10 +122,10 @@ const string& ArgParser::alternateConfigFile() const */ bool ArgParser::parse() { - const int commandCount = 35; + const int commandCount = 36; string commands[commandCount] = { "list", "search", "dsearch", - "info", - "depends", "install", "depinst", + "info", "depends", "nicetohave", + "install", "depinst", "help", "isinst", "dup", "update", "quickdep", "diff", "quickdiff", "grpinst", "version", "cache", @@ -137,15 +137,15 @@ bool ArgParser::parse() "listorphans" }; Type commandID[commandCount] = { LIST, SEARCH, DSEARCH, INFO, - DEPENDS, INSTALL, DEPINST, - HELP, ISINST, DUP, UPDATE, - QUICKDEP, DIFF, QUICKDIFF, - GRPINST, SHOW_VERSION, CREATE_CACHE, - PATH, LISTINST, PRINTF, README, - DEPENDENT, SYSUP, CURRENT, - FSEARCH, LOCK, UNLOCK, LISTLOCKED, - CAT, LS, EDIT, REMOVE, DEPTREE, - DUMPCONFIG, LISTORPHANS }; + DEPENDS, NICETOHAVE, INSTALL, + DEPINST, HELP, ISINST, DUP, + UPDATE, QUICKDEP, DIFF, + QUICKDIFF, GRPINST, SHOW_VERSION, + CREATE_CACHE, PATH, LISTINST, + PRINTF, README, DEPENDENT, SYSUP, + CURRENT, FSEARCH, LOCK, UNLOCK, + LISTLOCKED, CAT, LS, EDIT, REMOVE, + DEPTREE, DUMPCONFIG, LISTORPHANS }; if ( m_argc < 2 ) { return false; } diff --git a/src/argparser.h b/src/argparser.h index c24e7bd..3fc2b75 100644 --- a/src/argparser.h +++ b/src/argparser.h @@ -31,13 +31,12 @@ public: /*! Command type */ enum Type { HELP, LIST, SEARCH, DSEARCH, INSTALL, DEPINST, - INFO, DEPENDS, ISINST, DUP, UPDATE, - QUICKDEP, DIFF, GRPINST, GRPUPDATE, - QUICKDIFF, SHOW_VERSION, CREATE_CACHE, PATH, - LISTINST, PRINTF, README, DEPENDENT, SYSUP, - CURRENT, FSEARCH, LOCK, UNLOCK, LISTLOCKED, - CAT, LS, EDIT, REMOVE, - DEPTREE, DUMPCONFIG, LISTORPHANS }; + INFO, DEPENDS, NICETOHAVE, ISINST, DUP, UPDATE, + QUICKDEP, DIFF, GRPINST, GRPUPDATE, QUICKDIFF, + SHOW_VERSION, CREATE_CACHE, PATH, LISTINST, + PRINTF, README, DEPENDENT, SYSUP, CURRENT, + FSEARCH, LOCK, UNLOCK, LISTLOCKED, CAT, LS, + EDIT, REMOVE, DEPTREE, DUMPCONFIG, LISTORPHANS }; bool isCommandGiven() const; bool isForced() const; diff --git a/src/installtransaction.h b/src/installtransaction.h index 92cf6ba..d34c38a 100644 --- a/src/installtransaction.h +++ b/src/installtransaction.h @@ -59,7 +59,7 @@ public: PKGMK_EXEC_ERROR, /*!< can't execute pkgmk */ PKGMK_FAILURE, /*!< error while pkgmk */ PKGADD_EXEC_ERROR, /*!< can't execute pkgadd */ - PKGDEST_ERROR, /*!< can't change to PKGDEST */ + PKGDEST_ERROR, /*!< can't change to PKGDEST */ PKGADD_FAILURE, /*!< error while pkgadd */ CYCLIC_DEPEND, /*!< cyclic dependencies found */ LOG_DIR_FAILURE, /*!< couldn't create log directory */ @@ -87,7 +87,7 @@ public: InstallResult install( const ArgParser* parser, bool update, bool group ); - InstallResult calcDependencies(); + InstallResult calcDependencies(); const list< pair<string, InstallInfo> >& installedPackages() const; const list<string>& alreadyInstalledPackages() const; diff --git a/src/main.cpp b/src/main.cpp index abbd52f..45ae00f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,6 +94,9 @@ int main( int argc, char** argv ) case ArgParser::DEPENDS: prtGet.printDepends(); break; + case ArgParser::NICETOHAVE: + prtGet.printNicetohave(); + break; case ArgParser::QUICKDEP: prtGet.printDepends( true ); break; diff --git a/src/package.cpp b/src/package.cpp index 8b3779a..4862eac 100644 --- a/src/package.cpp +++ b/src/package.cpp @@ -43,6 +43,7 @@ Package::Package( const string& name, const string& release, const string& description, const string& dependencies, + const string& nicetohave, const string& url, const string& packager, const string& maintainer, @@ -51,10 +52,10 @@ Package::Package( const string& name, const string& hasPostInstall) : m_loaded( true ) { - m_data = new PackageData( name, path, version, release, - description, dependencies, url, - packager, maintainer, hasReadme, - hasPreInstall, hasPostInstall ); + m_data = new PackageData( name, path, version, release, description, + dependencies, nicetohave, url, packager, + maintainer, hasReadme, hasPreInstall, + hasPostInstall ); } @@ -103,6 +104,13 @@ const string& Package::dependencies() const return m_data->depends; } +/*! \return the nice to have line of this package */ +const string& Package::nicetohave() const +{ + load(); + return m_data->nice; +} + /*! \return the url of this package */ const string& Package::url() const { @@ -237,6 +245,32 @@ void Package::load() const #endif } + else if ( startsWithNoCase( line, "nice" ) ) { + string nice = stripWhiteSpace( getValue( line, ':' ) ); + + StringHelper::replaceAll( nice, " ", "," ); + StringHelper::replaceAll( nice, ",,", "," ); + + // TODO: decide which one to use +#if 0 + // remove commented out packages + list<string> nicetohave = StringHelper::split( nice, ',' ); + list<string>::iterator it = nicetohave.begin(); + for ( ; it != nicetohave.end(); ++it ) { + if ( (*it)[0] == '#' ) { + cerr << "Commented nice to have: " << *it << endl; + } else { + if ( it != nicetohave.begin() ) { + m_data->nice += ","; + } + m_data->nice += *it; + } + } +#else + m_data->nice = nice; +#endif + + } } } } @@ -265,6 +299,10 @@ void Package::setDependencies( const std::string& dependencies ) m_data->depends = dependencies; } +void Package::setNicetohave( const std::string& nicetohave ) +{ + m_data->nice = nicetohave; +} PackageData::PackageData( const string& name_, @@ -273,6 +311,7 @@ PackageData::PackageData( const string& name_, const string& release_, const string& description_, const string& dependencies_, + const string& nicetohave_, const string& url_, const string& packager_, const string& maintainer_, @@ -285,6 +324,7 @@ PackageData::PackageData( const string& name_, release( release_ ), description( description_ ), depends( dependencies_ ), + nice( nicetohave_ ), url( url_ ), packager( packager_ ), maintainer( maintainer_ ) diff --git a/src/package.h b/src/package.h index bc3e055..cd67ebf 100644 --- a/src/package.h +++ b/src/package.h @@ -34,6 +34,7 @@ public: const std::string& release, const std::string& description, const std::string& dependencies, + const std::string& nicetohave, const std::string& url, const std::string& packager, const std::string& maintainer, @@ -49,6 +50,7 @@ public: const std::string& release() const; const std::string& description() const; const std::string& dependencies() const; + const std::string& nicetohave() const; const std::string& url() const; const std::string& packager() const; const std::string& maintainer() const; @@ -59,6 +61,7 @@ public: std::string versionReleaseString() const; void setDependencies( const std::string& dependencies ); + void setNicetohave( const std::string& nicetohave ); private: @@ -81,6 +84,7 @@ struct PackageData const std::string& release_="", const std::string& description_="", const std::string& dependencies_="", + const std::string& nicetohave_="", const std::string& url_="", const std::string& packager="", const std::string& maintainer="", @@ -94,6 +98,7 @@ struct PackageData std::string release; std::string description; std::string depends; + std::string nice; std::string url; std::string packager; std::string maintainer; diff --git a/src/prtget.cpp b/src/prtget.cpp index d1709d8..8961fd4 100644 --- a/src/prtget.cpp +++ b/src/prtget.cpp @@ -141,13 +141,15 @@ void PrtGet::printUsage() << endl; cout << "\nDEPENDENCIES" << endl; - cout << " depends <port1 port2...> show dependencies for these ports" + cout << " depends <port1 port2...> show dependencies for these ports" << endl; - cout << " quickdep <port1 port2...> same as 'depends' but simple format" + cout << " quickdep <port1 port2...> same as 'depends' but simple format" << endl; - cout << " deptree <port> show dependencies tree for <port>" + cout << " deptree <port> show dependencies tree for <port>" << endl; - cout << " dependent [opt] <port> show installed packages which " + cout << " nicetohave <port> show ports which are nice to have" + << endl; + cout << " dependent [opt] <port> show installed packages which " << "depend on 'port'" << endl; cout << " where opt can be:" << endl; @@ -398,10 +400,12 @@ void PrtGet::printInfo() if ( !p->maintainer().empty() ) { cout << "Maintainer: " << p->maintainer() << endl; } - if ( !p->dependencies().empty() ) { cout << "Dependencies: " << p->dependencies() << endl; } + if ( !p->nicetohave().empty() ) { + cout << "Nice to have: " << p->nicetohave() << endl; + } // TODO: don't hardcode file names string filesString = ""; @@ -802,6 +806,36 @@ void PrtGet::printDepends( bool simpleListing ) } } +/*! + print nice to have listing +*/ +void PrtGet::printNicetohave() +{ + assertExactArgCount(1); + + initRepo(); + + list<char*>::const_iterator it = m_parser->otherArgs().begin(); + string arg = *it; + const Package* p = m_repo->getPackage( arg ); + + if (!p) { + cerr << "Package '" << arg << "' not found" << endl; + m_returnValue = PG_GENERAL_ERROR; + return; + } + else { + list<string> tokens; + StringHelper::split( p->nicetohave(), ',', tokens ); + list<string>::iterator it = tokens.begin(); + for ( ; it != tokens.end(); ++it ) { + cout << *it << " "; + } + cout << endl; + } +} + + /*! read the config file */ void PrtGet::readConfig() { @@ -1256,6 +1290,7 @@ void PrtGet::printf() StringHelper::replaceAll( output, "%r", p->release() ); StringHelper::replaceAll( output, "%d", p->description() ); StringHelper::replaceAll( output, "%e", p->dependencies() ); + StringHelper::replaceAll( output, "%n", p->nicetohave() ); StringHelper::replaceAll( output, "%P", p->packager() ); StringHelper::replaceAll( output, "%M", p->maintainer() ); @@ -1269,6 +1304,7 @@ void PrtGet::printf() StringHelper::replaceAll( sortkey, "%r", p->release() ); StringHelper::replaceAll( sortkey, "%d", p->description() ); StringHelper::replaceAll( sortkey, "%e", p->dependencies() ); + StringHelper::replaceAll( sortkey, "%n", p->nicetohave() ); StringHelper::replaceAll( sortkey, "%P", p->packager() ); StringHelper::replaceAll( sortkey, "%M", p->maintainer() ); diff --git a/src/prtget.h b/src/prtget.h index 6a82975..2114046 100644 --- a/src/prtget.h +++ b/src/prtget.h @@ -69,6 +69,7 @@ public: void printDepends( bool simpleListing=false ); void printDependTree(); void printDependent(); + void printNicetohave(); void printDiff(); void printQuickDiff(); void listOrphans(); diff --git a/src/repository.cpp b/src/repository.cpp index e911095..538195c 100644 --- a/src/repository.cpp +++ b/src/repository.cpp @@ -276,11 +276,11 @@ Repository::initFromCache( const string& cacheFile ) ++fieldPos; if ( fieldPos == fieldCount ) { fieldPos = 0; - Package* p = new Package( fields[0], fields[1], - fields[2], fields[3], - fields[4], fields[5], fields[6], - fields[7], fields[8], fields[9], - fields[10], fields[11]); + Package* p = new Package( fields[0], fields[1], fields[2], + fields[3], fields[4], fields[5], + fields[6], fields[7], fields[8], + fields[9], fields[10], fields[11], + fields[12]); m_packageMap[p->name()] = p; fgets( input, length, fp ); // read empty line }