3 #include <zypp/base/LogControl.h>
4 #include <zypp/base/LogTools.h>
5 #include <zypp/base/Measure.h>
6 #include <zypp/SourceFactory.h>
7 #include <zypp/Source.h>
8 #include <zypp/Product.h>
9 #include <zypp/ResStore.h>
10 #include <zypp/ResObject.h>
11 #include <zypp/pool/PoolStats.h>
12 #include <zypp/KeyRing.h>
13 #include <zypp/Date.h>
14 #include <zypp/SourceManager.h>
19 static bool verbose = false;
20 static bool debug_flag = false;
22 #define LOG (debug_flag ? USR : cout)
24 struct KeyRingReceiver : public callback::ReceiveReport<KeyRingReport>
31 virtual bool askUserToAcceptUnsignedFile( const std::string & file )
33 LOG << "===[UnsignedFile " << file << "]" << endl;
36 virtual bool askUserToAcceptUnknownKey( const std::string &file,
37 const std::string &id )
39 LOG << "===[UnknownKey " << id << "]" << endl;
42 virtual bool askUserToTrustKey( const PublicKey &key)
44 LOG << "===[TrustKey" << key << "]" << endl;
47 virtual bool askUserToImportKey( const PublicKey &key)
49 LOG << "===[ImportKey " << key << "]" << endl;
52 virtual bool askUserToAcceptVerificationFailed( const std::string &file,
53 const PublicKey &key )
55 LOG << "===[VerificationFailed " << file << " " << key << "]" << endl;
60 struct ResStoreStats : public pool::PoolStats
62 void operator()( const ResObject::constPtr & obj )
64 if ( isKind<Product>( obj ) )
68 pool::PoolStats::operator()( obj );
72 /******************************************************************
74 ** FUNCTION NAME : main
75 ** FUNCTION TYPE : int
77 int main( int argc, char * argv[] )
79 //zypp::base::LogControl::instance().logfile( "" );
80 INT << "===[START]==========================================" << endl;
86 LOG << "Usage: ScanSource [options] url [[options] url...]" << endl;
87 LOG << " Display summary of Sources found at 'url'. " << endl;
90 LOG << " options:" << endl;
91 LOG << " +/-l enable/disable detailed listing of Source content" << endl;
92 LOG << " +/-d enable/disable debug output" << endl;
96 KeyRingReceiver accept;
98 for ( ; argc; --argc, ++argv )
100 if ( *argv == string("+l") )
105 if ( *argv == string("-l") )
110 if ( *argv == string("+d") )
112 zypp::base::LogControl::instance().logfile( "-" );
116 if ( *argv == string("-d") )
118 zypp::base::LogControl::instance().logfile( "" );
123 LOG << "====================================================" << endl;
124 LOG << "===Search Source at Url(" << *argv << ")..." << endl;
128 debug::Measure m( "Create" );
132 src = SourceFactory().createFrom( url, "/", Date::now().asSeconds() );
134 catch ( const source::SourceUnknownTypeException & )
136 src = SourceFactory().createFrom( "Plaindir", url, "/", Date::now().asSeconds(), "", false, true );
139 //LOG << m.asString() << endl;
141 catch ( const Exception & except_r )
143 LOG << "***Failed: " << except_r << endl;
146 LOG << "type: " << src.type() << endl;
147 LOG << "numberOfMedia: " << src.numberOfMedia() << endl;
148 LOG << "alias: " << src.alias() << endl;
149 LOG << "vendor: " << src.vendor() << endl;
150 LOG << "unique_id: " << src.unique_id() << endl;
151 LOG << "baseSource: " << src.baseSource() << endl;
152 LOG << "autorefresh: " << src.autorefresh() << endl;
153 LOG << "publicKeys: " << src.publicKeys() << endl;
155 LOG << "===Parse content..." << endl;
158 debug::Measure m( "Parse" );
161 //LOG << m.asString() << endl;
163 catch ( const Exception & except_r )
165 LOG << "***Failed: " << except_r << endl;
168 LOG << for_each( src.resolvables().begin(), src.resolvables().end(),
169 ResStoreStats() ) << endl;
172 dumpRange( LOG, src.resolvables().begin(), src.resolvables().end() ) << endl;
174 #define TestKind Product
176 for (ResStore::const_iterator it = src.resolvables().begin(); it != src.resolvables().end(); ++it)
178 if ( isKind<TestKind>(*it) )
180 zypp::TestKind::constPtr res = asKind<TestKind>( *it );
181 cout << res->name() << " | " << res->edition() << std::endl;
182 cout << res->distributionName() << " | " << res->distributionEdition() << std::endl;
186 //SourceManager::sourceManager()->addSource( src );
187 //SourceManager::sourceManager()->store( "/", true );
190 INT << "===[END]============================================" << endl << endl;