From 01ba5c4c91a16ef76fa68bdaacde36453f6fb36b Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Wed, 28 Jun 2006 09:19:28 +0000 Subject: [PATCH] added installation_sources from y2pm, https://svn.suse.de/svn/yast/trunk/packagemanager/src r25445 --- devel/devel.mvidner/installation_sources.cc | 123 ++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 devel/devel.mvidner/installation_sources.cc diff --git a/devel/devel.mvidner/installation_sources.cc b/devel/devel.mvidner/installation_sources.cc new file mode 100644 index 0000000..42f20c7 --- /dev/null +++ b/devel/devel.mvidner/installation_sources.cc @@ -0,0 +1,123 @@ +#include + +#include +#include +#include + +#undef Y2LOG +#define Y2LOG "PM_installation_sources" +#include + +#include + +#include +#include +#include +#include + +using namespace std; + +void usage() +{ + cout << "Usage:" << endl + << " installation_sources [-e|-d] -a url Add source at given URL." << endl + << " -e Enable source. This is the default." << endl + << " -d Disable source." << endl + << " installation_sources -s Show all available sources." << endl; + exit( 1 ); +} + +/****************************************************************** +** +** +** FUNCTION NAME : main +** FUNCTION TYPE : int +** +** DESCRIPTION : +*/ +int main( int argc, char **argv ) +{ + MIL << "START" << endl; + + const char *urlStr = 0; + + bool showSources = false; + bool addSource = false; + bool enableSource = true; // -e per default + + int c; + while( 1 ) { + c = getopt( argc, argv, "desa:" ); + if ( c < 0 ) break; + + switch ( c ) { + case 's': + showSources = true; + break; + case 'a': + addSource = true; + urlStr = optarg; + break; + case 'd': + enableSource = false; + break; + case 'e': + enableSource = true; + break; + default: + cerr << "Error parsing command line." << endl; + case '?': + case 'h': + usage(); + } + } + + if ( showSources && addSource ) usage(); + if ( !showSources && !addSource ) usage(); + + Y2PM::noAutoInstSrcManager(); + InstSrcManager &instSrcMgr = Y2PM::instSrcManager(); + + InstSrcManager::ISrcIdList sourceIds; + + if ( addSource ) { + Url url( urlStr ); + if ( !url.isValid() ) { + cerr << "URL is invalid." << endl; + exit( 1 ); + } + + PMError error = instSrcMgr.scanMedia( sourceIds, url ); + if ( error ) { + cerr << error << endl; + exit( 1 ); + } + + InstSrcManager::ISrcIdList::const_iterator it; + for( it = sourceIds.begin(); it != sourceIds.end(); ++it ) { + error = instSrcMgr.enableSource( *it ); + if ( error ) { + cerr << error << endl; + exit( 1 ); + } + instSrcMgr.setAutoenable( *it, enableSource ); + } + cout << "Added Installation Sources:" << endl; + } + + if ( showSources ) { + instSrcMgr.getSources( sourceIds ); + cout << "Installation Sources:" << endl; + } + + InstSrcManager::ISrcIdList::const_iterator it; + for( it = sourceIds.begin(); it != sourceIds.end(); ++it ) { + constInstSrcDescrPtr descr = (*it)->descr(); + cout << ( descr->default_activate() ? "[x]" : "[ ]" ); + cout << ( descr->default_refresh() ? "* " : " " ); + cout << descr->content_label() << " (" << descr->url() << ")" << endl; + } + + MIL << "END" << endl; + return 0; +} -- 2.7.4