libzypp  17.30.0
RepoInfoBase.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 
14 #include <zypp/ZConfig.h>
16 
17 #include <zypp/repo/RepoInfoBase.h>
18 #include <zypp/TriBool.h>
19 #include <zypp/Pathname.h>
20 
21 using std::endl;
22 
24 namespace zypp
25 {
27  namespace repo
28  {
29 
35  {
36  Impl()
37  : _enabled( indeterminate )
38  , _autorefresh( indeterminate )
39  {}
40 
41  Impl( const std::string & alias_r )
42  : _enabled( indeterminate )
43  , _autorefresh( indeterminate )
44  { setAlias( alias_r ); }
45 
46  public:
49  std::string _alias;
50  std::string _escaped_alias;
53 
54  public:
55 
56  void setAlias( const std::string & alias_r )
57  {
58  _alias = _escaped_alias = alias_r;
59  // replace slashes with underscores
60  str::replaceAll( _escaped_alias, "/", "_" );
61  }
62 
63  private:
64  friend Impl * rwcowClone<Impl>( const Impl * rhs );
66  Impl * clone() const
67  { return new Impl( *this ); }
68  };
70 
72  //
73  // CLASS NAME : RepoInfoBase
74  //
76 
78  : _pimpl( new Impl() )
79  {}
80 
81  RepoInfoBase::RepoInfoBase(const std::string & alias)
82  : _pimpl( new Impl(alias) )
83  {}
84 
86  {}
87 
88  void RepoInfoBase::setEnabled( bool enabled )
89  { _pimpl->_enabled = enabled; }
90 
91  void RepoInfoBase::setAutorefresh( bool autorefresh )
93 
94  void RepoInfoBase::setAlias( const std::string &alias )
95  { _pimpl->setAlias(alias); }
96 
97  void RepoInfoBase::setName( const std::string &name )
98  { _pimpl->_name.raw() = name; }
99 
100  void RepoInfoBase::setFilepath( const Pathname &filepath )
101  { _pimpl->_filepath = filepath; }
102 
103  // true by default (if not set by setEnabled())
105  { return indeterminate(_pimpl->_enabled) ? true : (bool) _pimpl->_enabled; }
106 
107  // false by default (if not set by setAutorefresh())
109  { return indeterminate(_pimpl->_autorefresh) ? false : (bool) _pimpl->_autorefresh; }
110 
111  std::string RepoInfoBase::alias() const
112  { return _pimpl->_alias; }
113 
114  std::string RepoInfoBase::escaped_alias() const
115  { return _pimpl->_escaped_alias; }
116 
117  std::string RepoInfoBase::name() const
118  {
119  if ( rawName().empty() )
120  return alias();
122  }
123 
124  std::string RepoInfoBase::rawName() const
125  { return _pimpl->_name.raw(); }
126 
127  std::string RepoInfoBase::label() const
128  {
129  if ( ZConfig::instance().repoLabelIsAlias() )
130  return alias();
131  return name();
132  }
133 
135  { return _pimpl->_filepath; }
136 
137 
138  std::ostream & RepoInfoBase::dumpOn( std::ostream & str ) const
139  {
140  str << "--------------------------------------" << std::endl;
141  str << "- alias : " << alias() << std::endl;
142  if ( ! rawName().empty() )
143  str << "- name : " << rawName() << std::endl;
144  str << "- enabled : " << enabled() << std::endl;
145  str << "- autorefresh : " << autorefresh() << std::endl;
146 
147  return str;
148  }
149 
150  std::ostream & RepoInfoBase::dumpAsIniOn( std::ostream & str ) const
151  {
152  // we save the original data without variable replacement
153  str << "[" << alias() << "]" << endl;
154  if ( ! rawName().empty() )
155  str << "name=" << rawName() << endl;
156  str << "enabled=" << (enabled() ? "1" : "0") << endl;
157  str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
158 
159  return str;
160  }
161 
162  std::ostream & RepoInfoBase::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
163  {
164  return str << "<!-- there's no XML representation of RepoInfoBase -->" << endl;
165  }
166 
167  std::ostream & operator<<( std::ostream & str, const RepoInfoBase & obj )
168  {
169  return obj.dumpOn(str);
170  }
171 
172  } // namespace repo
174 } // namespace zypp
base::ValueTransform< std::string, repo::RepoVariablesStringReplacer > RepoVariablesReplacedString
Helper managing repo variables replaced strings.
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:823
Base class implementing common features of RepoInfo and ServiceInfo.
Definition: RepoInfoBase.h:40
virtual std::ostream & dumpOn(std::ostream &str) const
Write a human-readable representation of this RepoInfoBase object into the str stream.
std::string label() const
Label for use in messages for the user interface.
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition: RepoInfoBase.cc:91
std::string escaped_alias() const
Same as alias(), just escaped in a way to be a valid file name.
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfoBase object into str in a .repo (ini) file format.
void setFilepath(const Pathname &filename)
set the path to the .repo file
void setAlias(const std::string &alias)
set the repository alias
Definition: RepoInfoBase.cc:94
Pathname filepath() const
File where this repo was read from.
void setName(const std::string &name)
set the repository name
Definition: RepoInfoBase.cc:97
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
std::string name() const
Repository name.
std::string rawName() const
The raw metadata name (no default, no variables replaced).
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this object with content (if available).
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
void setEnabled(bool enabled)
enable or disable the repository
Definition: RepoInfoBase.cc:88
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoInfoBase.h:160
std::string alias() const
unique identifier for this source.
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const DeltaCandidates &obj)
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
Definition: String.cc:330
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
void setAlias(const std::string &alias_r)
Definition: RepoInfoBase.cc:56
Impl(const std::string &alias_r)
Definition: RepoInfoBase.cc:41
RepoVariablesReplacedString _name
Definition: RepoInfoBase.cc:51
Impl * clone() const
clone for RWCOW_pointer
Definition: RepoInfoBase.cc:66
Functor replacing repository variables.