changes
[platform/upstream/libzypp.git] / examples / read_plaindir_source.cc
1 // ZyPP Example
2 // Read a directory with rpms as a source
3 // No need for metadata, it is read from the rpms
4
5 #include <zypp/base/Logger.h>
6 #include <zypp/ZYpp.h>
7 #include <zypp/ZYppFactory.h>
8
9 #include "zypp/Product.h"
10 #include "zypp/Package.h"
11
12 #include "zypp/SourceFactory.h"
13
14 using namespace std;
15 using namespace zypp;
16 using namespace zypp::source;
17
18 int
19 main (int argc, char **argv)
20 {
21   if (argc < 2) {
22     cerr << "1|usage: " << argv[0] << " <dir:/somepath>" << endl;
23     return 1;
24   }
25   
26   try
27   {
28     ZYpp::Ptr z = getZYpp();
29     
30     // plaindir sources are not signed so we don't need to initialize the
31     // target to import the system public keys.
32     //z->initializeTarget("/");
33    
34     Source_Ref source = SourceFactory().createFrom( Url(argv[1]), "/", "testsource", Pathname() );
35     ResStore store = source.resolvables();
36     //zypp::testsuite::utils::dump(store, true, true);
37     
38     for (ResStore::const_iterator it = store.begin(); it != store.end(); ++it)
39     {
40       zypp::Package::Ptr res = asKind<zypp::Package>( *it );
41       MIL << res->name() << " " << res->edition() << " " << res->location() << std::endl;
42     }
43         
44   }
45   catch ( const Exception &e )
46   {
47     MIL << "Exception ocurred, bye" << endl;
48   }
49 }
50
51
52