zypper port starts. zypp2 to zypp
[platform/upstream/libzypp.git] / devel / devel.jkupec / YUMParser_test.cc
1 #include "zypp/ZYpp.h"
2 #include "zypp/ZYppFactory.h"
3 #include "zypp/base/Logger.h"
4 #include "zypp/base/LogControl.h"
5 #include "zypp/base/Measure.h"
6 #include "zypp/cache/CacheStore.h"
7 #include "zypp/parser/yum/RepoParser.h"
8
9 #undef ZYPP_BASE_LOGGER_LOGGROUP
10 #define ZYPP_BASE_LOGGER_LOGGROUP "yumparsertest"
11
12 using namespace std;
13 using namespace zypp;
14 using namespace zypp::parser::yum;
15 using zypp::debug::Measure;
16
17 bool progress_function(ProgressData::value_type p)
18 {
19   cout << "Parsing YUM source [" << p << "%]" << endl;
20 //  cout << "\rParsing YUM source [" << p << "%]" << flush;
21   return true;
22 }
23
24 int main(int argc, char **argv)
25 {
26   base::LogControl::instance().logfile("yumparsertest.log");
27   
28   if (argc < 2)
29   {
30     cout << "usage: yumparsertest path/to/yumsourcedir" << endl << endl;
31     return 1;
32   }
33
34   try
35   {
36     ZYpp::Ptr z = getZYpp();
37
38     Measure open_repository_timer("CacheStore: lookupOrAppendRepository");
39
40     cache::CacheStore store(getenv("PWD"));
41     data::RecordId repository_id = store.lookupOrAppendRepository("somealias");
42
43     open_repository_timer.stop();
44
45     MIL << "creating PrimaryFileParser" << endl;
46     Measure parse_primary_timer("primary.xml.gz parsing");
47
48     parser::yum::RepoParser parser( repository_id, store, &progress_function);
49     parser.parse(argv[1]);
50
51     store.commit();
52     parse_primary_timer.stop();
53
54     cout << endl;
55   }
56   catch ( const Exception &e )
57   {
58     cout << "Oops! " << e.msg() << std::endl;
59   }
60
61   return 0;
62 }
63
64 // vim: set ts=2 sts=2 sw=2 et ai: