backup
[platform/upstream/libzypp.git] / devel / devel.jkupec / poolquery.cc
1 #include <stdio.h>
2 #include <iostream>
3 #include <iterator>
4 #include <list>
5
6 #include "zypp/ZYppFactory.h"
7 #include "zypp/PoolQuery.h"
8 #include "zypp/PoolQueryUtil.tcc"
9 #include "zypp/RepoInfo.h"
10 #include "zypp/Arch.h"
11 #include "zypp/Pathname.h"
12 #include "zypp/base/Regex.h"
13
14 using std::cout;
15 using std::endl;
16 using std::string;
17 using namespace zypp;
18
19
20 bool result_cb( const sat::Solvable & solvable )
21 {
22   zypp::PoolItem pi( zypp::ResPool::instance().find( solvable ) );
23   cout << pi.resolvable() << endl;
24   // name: yast2-sound 2.16.2-9 i586
25   return true;
26 }
27
28
29 static void init_pool()
30 {
31   Pathname dir(TESTS_SRC_DIR);
32   dir += "/zypp/data/PoolQuery";
33
34   ZYpp::Ptr z = getZYpp();
35   ZConfig::instance().setSystemArchitecture(Arch("i586"));
36
37   RepoInfo i1; i1.setAlias("factory");
38   sat::Pool::instance().addRepoSolv(dir / "factory.solv", i1);
39   RepoInfo i2; i2.setAlias("factory-nonoss");
40   sat::Pool::instance().addRepoSolv(dir / "factory-nonoss.solv", i2);
41   RepoInfo i3; i3.setAlias("zypp_svn");
42   sat::Pool::instance().addRepoSolv(dir / "zypp_svn.solv", i3);
43   RepoInfo i5; i5.setAlias("pyton");
44   sat::Pool::instance().addRepoSolv(dir / "python.solv", i5);
45   RepoInfo i4; i4.setAlias("@System");
46   sat::Pool::instance().addRepoSolv(dir / "@System.solv", i4);
47 }
48
49
50 int main (int argc, const char ** argv)
51 {
52   // ./poolquery regex string
53   if (argc == 3)
54   {
55     str::regex regex(argv[1], REG_EXTENDED | REG_NOSUB | REG_NEWLINE | REG_ICASE);
56     cout << (str::regex_match(argv[2], regex) ? "" : "no") << "match" << endl;
57   }
58
59   init_pool();
60
61   PoolQuery q;
62   q.addAttribute(sat::SolvAttr::name, "cjson");
63
64   /*
65   PoolQuery q;
66   q.addString("weather");
67   q.addAttribute(sat::SolvAttr::name, "thunder");
68   q.addAttribute(sat::SolvAttr::description, "storm");
69   q.addKind(ResKind::package);
70   q.addRepo("factory");
71 */
72   std::for_each(q.begin(), q.end(), &result_cb);
73 //  cout << q.size() << endl;
74 //  cout << q << endl;
75   cout << "=====" << endl;
76   for_(it, q.selectableBegin(), q.selectableEnd())
77     cout << *it << endl;
78 }