added installation_sources from y2pm,
authorMartin Vidner <mvidner@suse.cz>
Wed, 28 Jun 2006 09:19:28 +0000 (09:19 +0000)
committerMartin Vidner <mvidner@suse.cz>
Wed, 28 Jun 2006 09:19:28 +0000 (09:19 +0000)
https://svn.suse.de/svn/yast/trunk/packagemanager/src r25445

devel/devel.mvidner/installation_sources.cc [new file with mode: 0644]

diff --git a/devel/devel.mvidner/installation_sources.cc b/devel/devel.mvidner/installation_sources.cc
new file mode 100644 (file)
index 0000000..42f20c7
--- /dev/null
@@ -0,0 +1,123 @@
+#include <getopt.h>
+
+#include <iomanip>
+#include <list>
+#include <string>
+
+#undef  Y2LOG
+#define Y2LOG "PM_installation_sources"
+#include <y2util/Y2SLog.h>
+
+#include <y2util/Url.h>
+
+#include <Y2PM.h>
+#include <y2pm/PMError.h>
+#include <y2pm/InstSrcManager.h>
+#include <y2pm/InstSrcDescr.h>
+
+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;
+}