148bd6b68ca0f9d1c575a671b8624b9433458d31
[platform/upstream/libzypp.git] / tools / zmart / zmart-misc.cc
1 #include <sstream>
2
3 #include "zmart.h"
4 #include "zmart-misc.h"
5
6 #include <zypp/Patch.h>
7
8 using namespace zypp::detail;
9
10 using namespace std;
11 using namespace zypp;
12 using namespace boost;
13
14 extern ZYpp::Ptr God;
15 extern RuntimeData gData;
16 extern Settings gSettings;
17
18 void mark_package_for_install( const std::string &name )
19 {
20   CapSet capset;
21   capset.insert (CapFactory().parse( ResTraits<Package>::kind, name));
22   //capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo1 > 1.0"));
23   // The user is setting this capablility
24   ResPool::AdditionalCapSet aCapSet;
25   aCapSet[ResStatus::USER] = capset;
26   God->pool().setAdditionalRequire( aCapSet );
27 }
28
29 void show_summary()
30 {
31   MIL << "Pool contains " << God->pool().size() << " items." << std::endl;
32   for ( ResPool::const_iterator it = God->pool().begin(); it != God->pool().end(); ++it )
33   {
34     Resolvable::constPtr res = it->resolvable();
35     if ( it->status().isToBeInstalled() || it->status().isToBeUninstalled() )
36     {
37       if ( it->status().isToBeInstalled() )
38         cout << "<install>   ";
39       if ( it->status().isToBeUninstalled() )
40         cout << "<uninstall> ";
41       cout << res->name() << " " << res->edition() << "]" << std::endl;
42     }
43   } 
44 }
45
46 std::string calculate_token()
47 {
48   SourceManager_Ptr manager;
49   manager = SourceManager::sourceManager();
50   
51   std::string token;
52   stringstream token_stream;
53   for ( std::list<Source_Ref>::iterator it = gData.sources.begin(); it !=  gData.sources.end(); ++it )
54   {
55     Source_Ref src = *it;
56     
57 //     if ( gSettings.disable_system_sources == SourcesFromSystem )
58 //     {
59 //       if ( gSettings.output_type == OutputTypeNice )
60 //         cout << "Refreshing source " <<  src.alias() << endl;
61 //       src.refresh();
62 //     }
63     
64     token_stream << "[" << src.alias() << "| " << src.url() << src.timestamp() << "]";
65     MIL << "Source: " << src.alias() << " from " << src.timestamp() << std::endl;  
66   }
67   
68   token_stream << "[" << "target" << "| " << God->target()->timestamp() << "]";
69   
70   //static std::string digest(const std::string& name, std::istream& is
71   token = Digest::digest("sha1", token_stream);
72   
73   //if ( gSettings.output_type == OutputTypeSimple )
74   //  cout << token;
75   
76   MIL << "new token [" << token << "]" << " previous: [" << gSettings.previous_token << "] previous code: " << gSettings.previous_code << std::endl;
77   
78   return token;
79 }
80
81 void load_target()
82 {
83   cout << "Adding system resolvables to pool..." << endl;
84   God->addResolvables( God->target()->resolvables(), true);
85 }
86
87 void load_sources()
88 {
89   for ( std::list<Source_Ref>::iterator it = gData.sources.begin(); it !=  gData.sources.end(); ++it )
90   {
91     Source_Ref src = *it;
92     // skip non YUM sources for now
93     //if ( it->type() == "YUM" )
94     //{
95     cout << "Adding " << it->alias() << " resolvables to the pool..." << endl;
96     ResStore src_resolvables(it->resolvables());
97     cout << "   " <<  src_resolvables.size() << " resolvables." << endl;
98     God->addResolvables(src_resolvables);
99     //}
100   }
101 }
102
103 void resolve()
104 {
105   cout << "Resolving dependencies ..." << endl;
106   God->resolver()->establishPool();
107   God->resolver()->resolvePool();
108 }
109
110 void show_pool()
111 {
112   MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl;
113   for ( ResPool::byKind_iterator it = God->pool().byKindBegin<Patch>(); it != God->pool().byKindEnd<Patch>(); ++it )
114   {
115     Resolvable::constPtr res = it->resolvable();
116     Patch::constPtr patch = asKind<Patch>(res);
117     //cout << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << ( it->status().isNeeded() ? " [needed]" : " [unneeded]" )<< std::endl;
118     if ( it->status().isNeeded() )
119     {
120       gData.patches_count++;
121       if (patch->category() == "security")
122         gData.security_patches_count++;
123         
124       cerr << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << std::endl;
125     }
126   } 
127   cout << gData.patches_count << " patches needed. ( " << gData.security_patches_count << " security patches )"  << std::endl;
128 }
129
130 void usage(int argc, char **argv)
131 {
132   cerr << "usage: " << argv[0] << " [<previous token>] [previous result]" << endl;
133   exit(-1);
134 }
135
136
137