libzypp  13.10.6
RepoFileReader.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include "zypp/base/Logger.h"
14 #include "zypp/base/String.h"
15 #include "zypp/base/Regex.h"
16 #include "zypp/base/InputStream.h"
18 
19 #include "zypp/parser/IniDict.h"
21 
22 using std::endl;
24 
26 namespace zypp
27 {
28  namespace parser
30  {
31 
36  static void repositories_in_stream( const InputStream &is,
37  const RepoFileReader::ProcessRepo &callback,
38  const ProgressData::ReceiverFnc &progress )
39  {
40  parser::IniDict dict(is);
42  its != dict.sectionsEnd();
43  ++its )
44  {
45  RepoInfo info;
46  info.setAlias(*its);
47  Url url;
48 
49  for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
50  it != dict.entriesEnd(*its);
51  ++it )
52  {
53  //MIL << (*it).first << endl;
54  if (it->first == "name" )
55  info.setName(it-> second);
56  else if ( it->first == "enabled" )
57  info.setEnabled( str::strToTrue( it->second ) );
58  else if ( it->first == "priority" )
59  info.setPriority( str::strtonum<unsigned>( it->second ) );
60  else if ( it->first == "baseurl" && !it->second.empty())
61  url = it->second;
62  else if ( it->first == "path" )
63  info.setPath( Pathname(it->second) );
64  else if ( it->first == "type" )
65  info.setType(repo::RepoType(it->second));
66  else if ( it->first == "autorefresh" )
67  info.setAutorefresh( str::strToTrue( it->second ) );
68  else if ( it->first == "mirrorlist" && !it->second.empty())
69  info.setMirrorListUrl(Url(it->second));
70  else if ( it->first == "gpgkey" && !it->second.empty())
71  {
72  std::vector<std::string> keys;
73  str::split( it->second, std::back_inserter(keys) );
74  if ( ! keys.empty() )
75  info.setGpgKeyUrl( Url(*keys.begin()) );
76  }
77  else if ( it->first == "gpgcheck" )
78  info.setGpgCheck( str::strToTrue( it->second ) );
79  else if ( it->first == "keeppackages" )
80  info.setKeepPackages( str::strToTrue( it->second ) );
81  else if ( it->first == "service" )
82  info.setService( it->second );
83  else if ( it->first == "proxy" )
84  {
85  if (it->second != "_none_" )
86  {
87  str::regex ex("^(.*):([0-9]+)$");
88  str::smatch what;
89  if(str::regex_match(it->second, what, ex)){
90  url.setQueryParam("proxy", what[1]);
91  url.setQueryParam("proxyport", what[2]);
92  }
93  }
94  } else
95  ERR << "Unknown attribute in [" << *its << "]: " << it->second << " ignored" << endl;
96  }
97  if (url.isValid())
98  info.addBaseUrl(url);
99  info.setFilepath(is.path());
100  MIL << info << endl;
101  // add it to the list.
102  callback(info);
103  //if (!progress.tick())
104  // ZYPP_THROW(AbortRequestException());
105  }
106  }
107 
109  //
110  // CLASS NAME : RepoFileReader
111  //
113 
114  RepoFileReader::RepoFileReader( const Pathname & repo_file,
115  const ProcessRepo & callback,
116  const ProgressData::ReceiverFnc &progress )
117  : _callback(callback)
118  {
119  repositories_in_stream(InputStream(repo_file), _callback, progress);
120  }
121 
123  const ProcessRepo & callback,
124  const ProgressData::ReceiverFnc &progress )
125  : _callback(callback)
126  {
127  repositories_in_stream(is, _callback, progress);
128  }
129 
131  {}
132 
133 
134  std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj )
135  {
136  return str;
137  }
138 
140  } // namespace parser
143 } // namespace zypp
#define MIL
Definition: Logger.h:47
void setGpgKeyUrl(const Url &gpgkey)
Key to use for gpg checking of this repository.
Definition: RepoInfo.cc:173
MapKVIteratorTraits< SectionSet >::Key_const_iterator section_const_iterator
Definition: IniDict.h:46
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:827
function< bool(const RepoInfo &)> ProcessRepo
Callback definition.
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition: RepoInfoBase.cc:94
Regular expression.
Definition: Regex.h:86
void setPriority(unsigned newval_r)
Set repository priority for solver.
Definition: RepoInfo.cc:164
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
void setMirrorListUrl(const Url &url)
Set mirror list url.
Definition: RepoInfo.cc:170
void setEnabled(bool enabled)
enable or disable the repository
Definition: RepoInfoBase.cc:89
void setAlias(const std::string &alias)
set the repository alias
Definition: RepoInfoBase.cc:99
void setFilepath(const Pathname &filename)
set the path to the .repo file
What is known about a repository.
Definition: RepoInfo.h:66
std::ostream & operator<<(std::ostream &str, const IniDict &obj)
Definition: IniDict.cc:143
Helper to create and pass std::istream.
Definition: InputStream.h:56
RepoFileReader(const Pathname &repo_file, const ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Constructor.
bool isValid() const
Verifies the Url.
Definition: Url.cc:483
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:144
#define ERR
Definition: Logger.h:49
static void repositories_in_stream(const InputStream &is, const RepoFileReader::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress)
List of RepoInfo&#39;s from a file.
void setPath(const Pathname &path)
set the product path.
Definition: RepoInfo.cc:185
void setService(const std::string &name)
sets service which added this repository
Definition: RepoInfo.cc:204
section_const_iterator sectionsBegin() const
Definition: IniDict.cc:94
const Pathname & path() const
Path to the input file or empty if no file.
Definition: InputStream.h:111
void setType(const repo::RepoType &t)
set the repository type
Definition: RepoInfo.cc:188
void setKeepPackages(bool keep)
Set if packaqes downloaded from this repository will be kept in local cache.
Definition: RepoInfo.cc:201
zypp::Url url
Definition: MediaCurl.cc:193
Read repository data from a .repo file.
entry_const_iterator entriesEnd(const std::string &section) const
Definition: IniDict.cc:82
void addBaseUrl(const Url &url)
Add a base url.
Definition: RepoInfo.cc:176
Parses a INI file and offers its structure as a dictionary.
Definition: IniDict.h:40
bool strToTrue(const C_Str &str)
Parsing boolean from string.
Definition: String.cc:61
Regular expression match result.
Definition: Regex.h:145
entry_const_iterator entriesBegin(const std::string &section) const
Definition: IniDict.cc:71
void setGpgCheck(bool check)
Whether to check or not this repository with gpg.
Definition: RepoInfo.cc:167
bool regex_match(const std::string &s, smatch &matches, const regex &regex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
Definition: Regex.h:70
EntrySet::const_iterator entry_const_iterator
Definition: IniDict.h:47
void setName(const std::string &name)
set the repository name
section_const_iterator sectionsEnd() const
Definition: IniDict.cc:99
Url manipulation class.
Definition: Url.h:87
Repository type enumeration.
Definition: RepoType.h:27