Author: mlandres Date: Fri Nov 7 15:50:08 2008 New Revision: 11623 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11623&view=rev Log: Autodetect path/url in TestSetup::loadRepo Modified: trunk/libzypp/devel/devel.ma/Test.cc trunk/libzypp/devel/devel.ma/ToolScanRepos.cc trunk/libzypp/tests/lib/TestSetup.h Modified: trunk/libzypp/devel/devel.ma/Test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/Test.cc?rev=11623&r1=11622&r2=11623&view=diff ============================================================================== --- trunk/libzypp/devel/devel.ma/Test.cc (original) +++ trunk/libzypp/devel/devel.ma/Test.cc Fri Nov 7 15:50:08 2008 @@ -11,7 +11,7 @@ INT << "===[START]==========================================" << endl; // https://bugzilla.novell.com/show_bug.cgi?id=442200 - Pathname mroot( "/tmp/ToolScanRepos" ); + Pathname mroot( "/tmp/Bb" ); TestSetup test( mroot, Arch_x86_64 ); test.loadRepos(); Modified: trunk/libzypp/devel/devel.ma/ToolScanRepos.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/ToolScanRepos.cc?rev=11623&r1=11622&r2=11623&view=diff ============================================================================== --- trunk/libzypp/devel/devel.ma/ToolScanRepos.cc (original) +++ trunk/libzypp/devel/devel.ma/ToolScanRepos.cc Fri Nov 7 15:50:08 2008 @@ -1,53 +1,132 @@ #include "Tools.h" +static std::string appname( "ToolScanRepos" ); + +void message( const std::string & msg_r ) +{ + cerr << "*** " << msg_r << endl; +} + +int usage( const std::string & msg_r = std::string(), int exit_r = 100 ) +{ + if ( ! msg_r.empty() ) + { + cerr << endl; + message( msg_r ); + cerr << endl; + } + cerr << "Usage: " << appname << "[OPTIONS] URL..." << endl; + cerr << " Load repos from URL to test system below /tmp/" << appname << "." << endl; + cerr << " -r ROOT Use /tmp/ROOT as location of test system (default: " << appname << ")." << endl; + cerr << " -a ARCH Use ARCH as test system architecture (default: x86_64)." << endl; + cerr << " -c Clear an existing test system (default)." << endl; + cerr << " -n Do not clear an existing test system but reuse it." << endl; + return exit_r; +} + /****************************************************************** ** ** FUNCTION NAME : main ** FUNCTION TYPE : int */ int main( int argc, char * argv[] ) -try { +{ INT << "===[START]==========================================" << endl; - std::string appname( Pathname::basename( argv[0] ) ); + appname = Pathname::basename( argv[0] ); --argc; ++argv; if ( ! argc ) { - cerr << "Usage: " << appname << "[OPTIONS] URL..." << endl; - cerr << " Load repos from URL to test system below /tmp/" << appname << "." << endl; - cerr << " --nc Do not clear an existing test system but reuse it." << endl; - return 0; + return usage(); } - Pathname mroot( "/tmp/"+appname ); - if ( argc && argv[0] == std::string("--nc") ) + /////////////////////////////////////////////////////////////////// + Pathname mtmp( "/tmp" ); + Pathname mroot( mtmp/appname ); + Arch march( Arch_x86_64 ); + bool oClearRoot = true; + + std::vectorstd::string urls; + + while ( argc ) { + if ( argv[0] == std::string("-c") ) + { + oClearRoot = true; + } + else if ( argv[0] == std::string("-n") ) + { + oClearRoot = false; + } + else if ( argv[0] == std::string("-r") ) + { + --argc; + ++argv; + if ( ! argc ) + return usage( "Missing arg to -r ROOT", 101 ); + + if ( *(argv[0]) ) // empty + mroot = mtmp/argv[0]; + else + mroot = mtmp/appname; + } + else if ( argv[0] == std::string("-a") ) + { + --argc; + ++argv; + if ( ! argc ) + return usage( "Missing arg to -a ARCH", 101 ); + + if ( *(argv[0]) ) // empty + march = Arch( argv[0] ); + else + march = Arch_x86_64; + } + else + { + urls.push_back( argv[0] ); + } --argc; ++argv; } - else + + if ( urls.empty() ) + { + return usage( "Missing URLs", 102 ); + } + + /////////////////////////////////////////////////////////////////// + + if ( oClearRoot ) { + message( "Clear test system at " + mroot.asString() ); filesystem::recursive_rmdir( mroot ); } + else + { + message( "Use test system at " + mroot.asString() ); + } filesystem::assert_dir( mroot ); - TestSetup test( mroot, Arch_x86_64 ); - while ( argc ) + message( "Use archiecture " + march.asString() ); + TestSetup test( mroot, march ); + + int ret = 0; + for_( it, urls.begin(), urls.end() ) { - test.loadRepo( Url( argv[0] ) ); - --argc; - ++argv; + message( "Setup " + *it ); + try + { + test.loadRepo( *it ); + } + catch ( const Exception & exp ) + { + message( exp.asString() + "\n" + exp.historyAsString() ); + ++ret; + } } INT << "===[END]============================================" << endl << endl; - return 0; -} -catch ( const Exception & exp ) -{ - INT; - cerr << exp << endl << exp.historyAsString(); - throw; -} -catch (...) -{} + return ret; +} \ No newline at end of file Modified: trunk/libzypp/tests/lib/TestSetup.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/lib/TestSetup.h?rev=11623&r1=11622&r2=11623&view=diff ============================================================================== --- trunk/libzypp/tests/lib/TestSetup.h (original) +++ trunk/libzypp/tests/lib/TestSetup.h Fri Nov 7 15:50:08 2008 @@ -115,6 +115,25 @@ nrepo.setAlias( alias_r.empty() ? path_r.basename() : alias_r ); satpool().addRepoSolv( path_r, nrepo ); } + /** Directly load repo from some location (url or absolute(!)path). + * An empty alias is guessed. + */ + void loadRepo( const std::string & loc_r, const std::string & alias_r = std::string() ) + { + if ( *loc_r.c_str() == '/' ) + { + loadRepo( Pathname( loc_r ), alias_r ); + } + else + { + loadRepo( Url( loc_r ), alias_r ); + } + } + /** Directly load repo from some location (url or absolute(!)path). + * An empty alias is guessed. + */ + void loadRepo( const char * loc_r, const std::string & alias_r = std::string() ) + { loadRepo( std::string( loc_r ? loc_r : "" ), alias_r ); } public: /** Load all enabled repos in repos.d to pool. */ -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org