libzypp 17.37.10

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>
15#include <zypp/repo/RepoVariables.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
33 struct RepoInfoBase::Impl
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;
46 RepoVariablesReplacedString _name;
47 Pathname _filepath;
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 };
64
65
67 //
68 // CLASS NAME : RepoInfoBase
69 //
71
72 RepoInfoBase::RepoInfoBase()
73 : _pimpl( new Impl() )
74 {}
75
76 RepoInfoBase::RepoInfoBase(const std::string & alias)
77 : _pimpl( new Impl(alias) )
78 {}
79
80 RepoInfoBase::~RepoInfoBase()
81 {}
82
83 void RepoInfoBase::setEnabled( bool enabled )
84 { _pimpl->_enabled = enabled; }
85
86 void RepoInfoBase::setAutorefresh( bool autorefresh )
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
95 void RepoInfoBase::setFilepath( const Pathname &filepath )
96 { _pimpl->_filepath = filepath; }
97
98 bool RepoInfoBase::enabled() const
99 { return _pimpl->_enabled; }
100
101 bool RepoInfoBase::autorefresh() const
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();
114 return repo::RepoVariablesStringReplacer()( rawName() );
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
127 Pathname RepoInfoBase::filepath() const
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
RepoInfoBase.h
RepoVariables.h
RepoVariablesReplacedString
base::ValueTransform< std::string, repo::RepoVariablesStringReplacer > RepoVariablesReplacedString
Helper managing repo variables replaced strings.
Definition RepoVariables.h:127
ZConfig.h
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:940
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::repo::RepoInfoBase::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Write a human-readable representation of this RepoInfoBase object into the str stream.
Definition RepoInfoBase.cc:131
zypp::repo::RepoInfoBase::label
std::string label() const
Label for use in messages for the user interface.
Definition RepoInfoBase.cc:120
zypp::repo::RepoInfoBase::setAutorefresh
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition RepoInfoBase.cc:86
zypp::repo::RepoInfoBase::escaped_alias
std::string escaped_alias() const
Same as alias(), just escaped in a way to be a valid file name.
Definition RepoInfoBase.cc:107
zypp::repo::RepoInfoBase::dumpAsIniOn
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfoBase object into str in a .repo (ini) file format.
Definition RepoInfoBase.cc:143
zypp::repo::RepoInfoBase::setFilepath
void setFilepath(const Pathname &filename)
set the path to the .repo file
Definition RepoInfoBase.cc:95
zypp::repo::RepoInfoBase::setAlias
void setAlias(const std::string &alias)
set the repository alias
Definition RepoInfoBase.cc:89
zypp::repo::RepoInfoBase::RepoInfoBase
RepoInfoBase()
Definition RepoInfoBase.cc:72
zypp::repo::RepoInfoBase::filepath
Pathname filepath() const
File where this repo was read from.
Definition RepoInfoBase.cc:127
zypp::repo::RepoInfoBase::setName
void setName(const std::string &name)
set the repository name
Definition RepoInfoBase.cc:92
zypp::repo::RepoInfoBase::autorefresh
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
Definition RepoInfoBase.cc:101
zypp::repo::RepoInfoBase::name
std::string name() const
Repository name.
Definition RepoInfoBase.cc:110
zypp::repo::RepoInfoBase::rawName
std::string rawName() const
The raw metadata name (no default, no variables replaced).
Definition RepoInfoBase.cc:117
zypp::repo::RepoInfoBase::~RepoInfoBase
virtual ~RepoInfoBase()
Definition RepoInfoBase.cc:80
zypp::repo::RepoInfoBase::dumpAsXmlOn
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this object with content (if available).
Definition RepoInfoBase.cc:155
zypp::repo::RepoInfoBase::enabled
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
zypp::repo::RepoInfoBase::setEnabled
void setEnabled(bool enabled)
enable or disable the repository
Definition RepoInfoBase.cc:83
zypp::repo::RepoInfoBase::_pimpl
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition RepoInfoBase.h:168
zypp::repo::RepoInfoBase::alias
std::string alias() const
unique identifier for this source.
Definition RepoInfoBase.cc:104
str
String related utilities and Regular expression matching.
zypp::repo
Definition DeltaCandidates.cc:30
zypp::repo::operator<<
std::ostream & operator<<(std::ostream &str, const DeltaCandidates &obj)
Definition DeltaCandidates.cc:108
zypp::str::replaceAll
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
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::repo::RepoInfoBase::Impl
RepoInfoBase data.
Definition RepoInfoBase.cc:34
zypp::repo::RepoInfoBase::Impl::setAlias
void setAlias(const std::string &alias_r)
Definition RepoInfoBase.cc:51
zypp::repo::RepoInfoBase::Impl::Impl
Impl()
Definition RepoInfoBase.cc:35
zypp::repo::RepoInfoBase::Impl::Impl
Impl(const std::string &alias_r)
Definition RepoInfoBase.cc:38
zypp::repo::RepoInfoBase::Impl::_enabled
bool _enabled
Definition RepoInfoBase.cc:42
zypp::repo::RepoInfoBase::Impl::rwcowClone
friend Impl * rwcowClone(const Impl *rhs)
zypp::repo::RepoInfoBase::Impl::_alias
std::string _alias
Definition RepoInfoBase.cc:44
zypp::repo::RepoInfoBase::Impl::_name
RepoVariablesReplacedString _name
Definition RepoInfoBase.cc:46
zypp::repo::RepoInfoBase::Impl::_filepath
Pathname _filepath
Definition RepoInfoBase.cc:47
zypp::repo::RepoInfoBase::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition RepoInfoBase.cc:61
zypp::repo::RepoInfoBase::Impl::_autorefresh
bool _autorefresh
Definition RepoInfoBase.cc:43
zypp::repo::RepoInfoBase::Impl::_escaped_alias
std::string _escaped_alias
Definition RepoInfoBase.cc:45
zypp::repo::RepoVariablesStringReplacer
Functor replacing repository variables.
Definition RepoVariables.h:106
Pathname.h