acfe3ae94598ce4064a924301069c149975f13c2
[platform/upstream/libzypp.git] / devel / devel.dmacvicar / CacheStore_tp.cc
1 #include <sys/time.h>
2
3 #include <iostream>
4 #include <fstream>
5
6 #include <zypp/base/Measure.h>
7 #include <zypp/base/Logger.h>
8 #include <zypp/ZYpp.h>
9 #include <zypp/ZYppFactory.h>
10
11 #include "zypp/Product.h"
12 #include "zypp/detail/PackageImplIf.h"
13 #include "zypp/Package.h"
14
15 #include "zypp2/cache/CacheInitializer.h"
16 #include "zypp2/cache/CacheStore.h"
17 #include "zypp/data/ResolvableData.h"
18 #include "zypp/data/RecordId.h"
19 #include "zypp/capability/CapabilityImpl.h"
20 #include "zypp/base/Measure.h"
21
22 using namespace std;
23 using namespace zypp;
24 using namespace zypp::debug;
25 using namespace zypp::capability;
26
27
28 int main(int argc, char **argv)
29 {
30     try
31     {
32       ZYpp::Ptr z = getZYpp();
33
34 //       CapabilityImpl::Ptr freak = capability::parse( ResTraits<Package>::kind, "libc.so.6");
35 //       MIL << freak << endl;
36 //       MIL << "isVer: " << isKind<VersionedCap>(freak) << endl;
37 //       MIL << "isNam: " << isKind<NamedCap>(freak) << endl;
38 //       MIL << "isFil: " << isKind<FileCap>(freak) << endl;
39 //       VersionedCap::Ptr v = asKind<VersionedCap>(freak);
40 //       DBG << v << endl;
41
42       Pathname dbfile = Pathname(getenv("PWD")) + "data.db";
43       zypp::cache::CacheStore store(getenv("PWD"));
44       //zypp::cache::CacheInitializer init( "/", dbfile );
45       //t.tick("init sqlite database");
46
47       std::list<CapabilityImpl::Ptr> caps;
48       std::ifstream file;
49       file.open((Pathname(SRC_DIR) + "/capabilities.txt").asString().c_str());
50       std::string buffer;
51       Measure cap_parse_timer("Parse capabilities");
52       while (file && !file.eof())
53       {
54         getline(file, buffer);
55         CapabilityImpl::Ptr cap = capability::parse( ResTraits<Package>::kind, buffer );
56         if ( cap == 0L )
57         {
58           //ZYPP_THROW(Exception("Invalid capability: [" + buffer + "]"));
59           ERR << "Invalid cap: [" << buffer << "]" << endl;
60           continue;
61         }
62         //DBG << "capability : [" << buffer << "]" << endl;
63         caps.push_back(cap);
64       }
65       cap_parse_timer.elapsed();
66       MIL << caps.size() << " capabilities" << endl;
67       
68       Measure cap_insert_timer("Insert Capabilities");
69       for ( list<CapabilityImpl::Ptr>::const_iterator it = caps.begin(); it != caps.end(); ++it )
70       {
71         CapabilityImpl::Ptr cap = *it;
72         if ( ( ! cap ) || ( cap->refers() != ResTraits<Package>::kind ) )
73         {
74           ERR << "Invalid capability : [" << buffer << "]" << endl;
75           continue;
76         }
77         store.appendDependency( 1, zypp::Dep::REQUIRES, cap );
78       }
79       cap_insert_timer.elapsed();
80       
81       return 0;
82       
83       file.open((Pathname(SRC_DIR) + "/names").asString().c_str());
84       while (file && !file.eof())
85       {
86         getline(file, buffer);
87         data::RecordId id = store.lookupOrAppendName(buffer);
88       }
89     }
90     catch ( const Exception &e )
91     {
92       cout << e.msg() << endl;
93     }
94     
95     return 0;
96 }
97
98
99