libzypp  17.37.5
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/Pathname.h>
19 
20 using std::endl;
21 
23 namespace zypp
24 {
26  namespace repo
27  {
28 
34  {
35  Impl()
36  {}
37 
38  Impl( const std::string & alias_r )
39  { setAlias( alias_r ); }
40 
41  public:
42  bool _enabled = true;
43  bool _autorefresh = false;
44  std::string _alias;
45  std::string _escaped_alias;
48 
49  public:
50 
51  void setAlias( const std::string & alias_r )
52  {
53  _alias = _escaped_alias = alias_r;
54  // replace slashes with underscores
55  str::replaceAll( _escaped_alias, "/", "_" );
56  }
57 
58  private:
59  friend Impl * rwcowClone<Impl>( const Impl * rhs );
61  Impl * clone() const
62  { return new Impl( *this ); }
63  };
65 
67  //
68  // CLASS NAME : RepoInfoBase
69  //
71 
73  : _pimpl( new Impl() )
74  {}
75 
76  RepoInfoBase::RepoInfoBase(const std::string & alias)
77  : _pimpl( new Impl(alias) )
78  {}
79 
81  {}
82 
83  void RepoInfoBase::setEnabled( bool enabled )
84  { _pimpl->_enabled = enabled; }
85 
86  void RepoInfoBase::setAutorefresh( bool autorefresh )
88 
89  void RepoInfoBase::setAlias( const std::string &alias )
90  { _pimpl->setAlias(alias); }
91 
92  void RepoInfoBase::setName( const std::string &name )
93  { _pimpl->_name.raw() = name; }
94 
95  void RepoInfoBase::setFilepath( const Pathname &filepath )
96  { _pimpl->_filepath = filepath; }
97 
98  bool RepoInfoBase::enabled() const
99  { return _pimpl->_enabled; }
100 
102  { return _pimpl->_autorefresh; }
103 
104  std::string RepoInfoBase::alias() const
105  { return _pimpl->_alias; }
106 
107  std::string RepoInfoBase::escaped_alias() const
108  { return _pimpl->_escaped_alias; }
109 
110  std::string RepoInfoBase::name() const
111  {
112  if ( rawName().empty() )
113  return alias();
115  }
116 
117  std::string RepoInfoBase::rawName() const
118  { return _pimpl->_name.raw(); }
119 
120  std::string RepoInfoBase::label() const
121  {
122  if ( ZConfig::instance().repoLabelIsAlias() )
123  return alias();
124  return name();
125  }
126 
128  { return _pimpl->_filepath; }
129 
130 
131  std::ostream & RepoInfoBase::dumpOn( std::ostream & str ) const
132  {
133  str << "--------------------------------------" << std::endl;
134  str << "- alias : " << alias() << std::endl;
135  if ( ! rawName().empty() )
136  str << "- name : " << rawName() << std::endl;
137  str << "- enabled : " << enabled() << std::endl;
138  str << "- autorefresh : " << autorefresh() << std::endl;
139 
140  return str;
141  }
142 
143  std::ostream & RepoInfoBase::dumpAsIniOn( std::ostream & str ) const
144  {
145  // we save the original data without variable replacement
146  str << "[" << alias() << "]" << endl;
147  if ( ! rawName().empty() )
148  str << "name=" << rawName() << endl;
149  str << "enabled=" << (enabled() ? "1" : "0") << endl;
150  str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
151 
152  return str;
153  }
154 
155  std::ostream & RepoInfoBase::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
156  {
157  return str << "<!-- there's no XML representation of RepoInfoBase -->" << endl;
158  }
159 
160  std::ostream & operator<<( std::ostream & str, const RepoInfoBase & obj )
161  {
162  return obj.dumpOn(str);
163  }
164 
165  } // namespace repo
167 } // namespace zypp
Pathname filepath() const
File where this repo was read from.
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition: RepoInfoBase.cc:86
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:940
Impl * clone() const
clone for RWCOW_pointer
Definition: RepoInfoBase.cc:61
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:83
RepoVariablesReplacedString _name
Definition: RepoInfoBase.cc:46
void setAlias(const std::string &alias)
set the repository alias
Definition: RepoInfoBase.cc:89
String related utilities and Regular expression matching.
void setFilepath(const Pathname &filename)
set the path to the .repo file
Definition: RepoInfoBase.cc:95
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...
Definition: RepoInfoBase.cc:98
base::ValueTransform< std::string, repo::RepoVariablesStringReplacer > RepoVariablesReplacedString
std::string alias() const
unique identifier for this source.
std::ostream & operator<<(std::ostream &str, const DeltaCandidates &obj)
std::string rawName() const
The raw metadata name (no default, no variables replaced).
Impl(const std::string &alias_r)
Definition: RepoInfoBase.cc:38
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:92
void setAlias(const std::string &alias_r)
Definition: RepoInfoBase.cc:51
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: Application.cc:19
std::string label() const
Label for use in messages for the user interface.