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