libzypp 17.37.17
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
18#include <zypp/Pathname.h>
19
20using std::endl;
21
23namespace zypp
24{
26 namespace repo
27 {
28
34 {
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
56 }
57
58 private:
59 friend Impl * rwcowClone<Impl>( const Impl * rhs );
61 Impl * clone() const
62 { return new Impl( *this ); }
63 };
64
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
82
84 { _pimpl->_enabled = enabled; }
85
87 { _pimpl->_autorefresh = 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
96 { _pimpl->_filepath = filepath; }
97
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
base::ValueTransform< std::string, repo::RepoVariablesStringReplacer > RepoVariablesReplacedString
Helper managing repo variables replaced strings.
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:940
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
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
Pathname filepath() const
File where this repo was read from.
void setName(const std::string &name)
set the repository name
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
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
std::string alias() const
unique identifier for this source.
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:333
Easy-to use interface to the ZYPP dependency resolver.
void setAlias(const std::string &alias_r)
Impl(const std::string &alias_r)
friend Impl * rwcowClone(const Impl *rhs)
RepoVariablesReplacedString _name
Impl * clone() const
clone for RWCOW_pointer
Functor replacing repository variables.