libzypp  13.10.6
SystemCheck.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <fstream>
14 #include <vector>
15 
16 #include "zypp/base/LogTools.h"
17 #include "zypp/base/IOStream.h"
18 #include "zypp/base/String.h"
19 
20 #include "zypp/ZYppFactory.h"
21 #include "zypp/ZConfig.h"
22 #include "zypp/Pathname.h"
23 #include "zypp/PathInfo.h"
25 
26 using namespace std;
27 
29 namespace zypp
30 {
31 
32  Pathname _file = "";
35 
36  typedef vector<string> CapList;
37 
38  const SystemCheck & SystemCheck::instance()
39  {
40  static SystemCheck _val;
41  return _val;
42  }
43 
44 
45  SystemCheck::SystemCheck() {
46  if (_file.empty()) {
47  _file = ZConfig::instance().solver_checkSystemFile();
48  loadFile();
49  }
50  }
51 
52  bool SystemCheck::setFile(const Pathname & file) const{
53  MIL << "Setting checkFile to : " << file << endl;
54  _file = file;
55  loadFile();
56  return true;
57  }
58 
59  const Pathname & SystemCheck::file() {
60  return _file;
61  }
62 
63  const CapabilitySet & SystemCheck::requiredSystemCap() const{
64  return _require;
65  }
66 
67  const CapabilitySet & SystemCheck::conflictSystemCap() const{
68  return _conflict;
69  }
70 
71  bool SystemCheck::loadFile() const{
72  Target_Ptr trg( getZYpp()->getTarget() );
73  if ( trg )
74  _file = trg->assertRootPrefix( _file );
75 
76  PathInfo pi( _file );
77  if ( ! pi.isFile() ) {
78  WAR << "Can't read " << _file << " " << pi << endl;
79  return false;
80  }
81 
82  _require.clear();
83  _conflict.clear();
84 
85  std::ifstream infile( _file.c_str() );
86  for( iostr::EachLine in( infile ); in; in.next() ) {
87  std::string l( str::trim(*in) );
88  if ( ! l.empty() && l[0] != '#' )
89  {
90  CapList capList;
91  str::split( l, back_inserter(capList), ":" );
92  if (capList.size() == 2 ) {
93  CapList::iterator it = capList.begin();
94  if (*it == "requires") {
95  _require.insert(Capability(*(it+1)));
96  } else if (*it == "conflicts") {
97  _conflict.insert(Capability(*(it+1)));
98  } else {
99  ERR << "Wrong parameter: " << l << endl;
100  }
101  } else {
102  ERR << "Wrong line: " << l << endl;
103  }
104  }
105  }
106  MIL << "Read " << pi << endl;
107  return true;
108  }
109 
110 
111  /******************************************************************
112  **
113  ** FUNCTION NAME : operator<<
114  ** FUNCTION TYPE : std::ostream &
115  */
116  std::ostream & operator<<( std::ostream & str, const SystemCheck & obj )
117  {
118  str << _file << endl;
119  str << "requires" << endl;
120  for (CapabilitySet::const_iterator it = _require.begin(); it != _require.end(); ++it)
121  str << " " << *it << endl;
122 
123  str << "conflicts" << endl;
124  for (CapabilitySet::const_iterator it = _conflict.begin(); it != _conflict.end(); ++it)
125  str << " " << *it << endl;
126 
127  return str;
128  }
129 
131 } // namespace zypp
vector< string > CapList
Definition: SystemCheck.cc:36
#define MIL
Definition: Logger.h:47
bool next()
Advance to next line.
Definition: IOStream.cc:72
unsigned split(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
Definition: String.h:394
Simple lineparser: Traverse each line in a file.
Definition: IOStream.h:111
std::tr1::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
#define ERR
Definition: Logger.h:49
CapabilitySet _require
Definition: SystemCheck.cc:33
std::string trim(const std::string &s, const Trim trim_r)
Definition: String.cc:204
#define WAR
Definition: Logger.h:48
std::ostream & operator<<(std::ostream &str, const ::_Dataiterator *obj)
Definition: LookupAttr.cc:799
Save and restore locale set from file.
Definition: SystemCheck.h:29
A sat capability.
Definition: Capability.h:59
CapabilitySet _conflict
Definition: SystemCheck.cc:34
Pathname _file
Definition: SystemCheck.cc:32