1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
10 /** \file zypp/HistoryLogData.cc
15 #include "zypp/base/PtrTypes.h"
16 #include "zypp/base/String.h"
17 #include "zypp/base/Logger.h"
18 #include "zypp/parser/ParseException.h"
20 #include "zypp/HistoryLogData.h"
26 using parser::ParseException;
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : HistoryActionID
33 ///////////////////////////////////////////////////////////////////
35 static std::map<std::string,HistoryActionID::ID> _table;
37 const HistoryActionID HistoryActionID::NONE(HistoryActionID::NONE_e);
38 const HistoryActionID HistoryActionID::INSTALL(HistoryActionID::INSTALL_e);
39 const HistoryActionID HistoryActionID::REMOVE(HistoryActionID::REMOVE_e);
40 const HistoryActionID HistoryActionID::REPO_ADD(HistoryActionID::REPO_ADD_e);
41 const HistoryActionID HistoryActionID::REPO_REMOVE(HistoryActionID::REPO_REMOVE_e);
42 const HistoryActionID HistoryActionID::REPO_CHANGE_ALIAS(HistoryActionID::REPO_CHANGE_ALIAS_e);
43 const HistoryActionID HistoryActionID::REPO_CHANGE_URL(HistoryActionID::REPO_CHANGE_URL_e);
45 HistoryActionID::HistoryActionID(const std::string & strval_r)
46 : _id(parse(strval_r))
49 HistoryActionID::ID HistoryActionID::parse(const std::string & strval_r)
54 _table["install"] = INSTALL_e;
55 _table["remove"] = REMOVE_e;
56 _table["radd"] = REPO_ADD_e;
57 _table["rremove"] = REPO_REMOVE_e;
58 _table["ralias"] = REPO_CHANGE_ALIAS_e;
59 _table["rurl"] = REPO_CHANGE_URL_e;
60 _table["NONE"] = _table["none"] = HistoryActionID::NONE_e;
63 std::map<std::string,HistoryActionID::ID>::const_iterator it =
64 _table.find(strval_r);
66 if (it == _table.end())
67 WAR << "Unknown history action ID '" + strval_r + "'";
73 const std::string & HistoryActionID::asString(bool pad) const
75 static std::map<ID, std::string> _table;
79 _table[INSTALL_e] = "install";
80 _table[REMOVE_e] = "remove";
81 _table[REPO_ADD_e] = "radd";
82 _table[REPO_REMOVE_e] = "rremove";
83 _table[REPO_CHANGE_ALIAS_e] = "ralias";
84 _table[REPO_CHANGE_URL_e] = "rurl";
85 _table[NONE_e] = "NONE";
87 // add spaces so that the size of the returned string is always 7 (for now)
89 return _table[_id].append(7 - _table[_id].size(), ' ');
93 std::ostream & operator << (std::ostream & str, const HistoryActionID & id)
94 { return str << id.asString(); }
96 ///////////////////////////////////////////////////////////////////
99 /////////////////////////////////////////////////////////////////////
101 // CLASS NAME: HistoryItem
103 /////////////////////////////////////////////////////////////////////
105 HistoryItem::HistoryItem(FieldVector & fields)
107 if (fields.size() <= 2)
108 ZYPP_THROW(ParseException(
109 str::form("Bad number of fields. Got %zd, expected more than %d.",
112 date = Date(fields[0], HISTORY_LOG_DATE_FORMAT);
113 action = HistoryActionID(str::trim(fields[1]));
116 void HistoryItem::dumpTo(ostream & str) const
118 str << date.form(HISTORY_LOG_DATE_FORMAT) << "|" << action.asString();
121 ostream & operator<<(ostream & str, const HistoryItem & obj)
128 /////////////////////////////////////////////////////////////////////
130 // CLASS NAME: HistoryItemInstall
132 /////////////////////////////////////////////////////////////////////
134 HistoryItemInstall::HistoryItemInstall(FieldVector & fields)
135 : HistoryItem(fields)
137 if (fields.size() != 8)
138 ZYPP_THROW(ParseException(
139 str::form("Bad number of fields. Got %zu, expected %u.",
143 edition = Edition(fields[3]);
144 arch = Arch(fields[4]);
146 repoalias = fields[6];
147 checksum = CheckSum::sha(fields[7]);
150 void HistoryItemInstall::dumpTo(ostream & str) const
152 HistoryItem::dumpTo(str);
162 ostream & operator<<(ostream & str, const HistoryItemInstall & obj)
169 /////////////////////////////////////////////////////////////////////
171 // CLASS NAME: HistoryItemRemove
173 /////////////////////////////////////////////////////////////////////
175 HistoryItemRemove::HistoryItemRemove(FieldVector & fields)
176 : HistoryItem(fields)
178 if (fields.size() != 6)
179 ZYPP_THROW(ParseException(
180 str::form("Bad number of fields. Got %zu, expected %u.",
184 edition = Edition(fields[3]);
185 arch = Arch(fields[4]);
189 void HistoryItemRemove::dumpTo(ostream & str) const
191 HistoryItem::dumpTo(str);
199 ostream & operator<<(ostream & str, const HistoryItemRemove & obj)
206 /////////////////////////////////////////////////////////////////////
208 // CLASS NAME: HistoryItemRepoAdd
210 /////////////////////////////////////////////////////////////////////
212 HistoryItemRepoAdd::HistoryItemRepoAdd(FieldVector & fields)
213 : HistoryItem(fields)
215 if (fields.size() != 4)
216 ZYPP_THROW(ParseException(
217 str::form("Bad number of fields. Got %zu, expected %u.",
221 url = Url(fields[3]);
224 void HistoryItemRepoAdd::dumpTo(ostream & str) const
226 HistoryItem::dumpTo(str);
232 ostream & operator<<(ostream & str, const HistoryItemRepoAdd & obj)
239 /////////////////////////////////////////////////////////////////////
241 // CLASS NAME: HistoryItemRepoRemove
243 /////////////////////////////////////////////////////////////////////
245 HistoryItemRepoRemove::HistoryItemRepoRemove(FieldVector & fields)
246 : HistoryItem(fields)
248 if (fields.size() != 3)
249 ZYPP_THROW(ParseException(
250 str::form("Bad number of fields. Got %zu, expected %u.",
256 void HistoryItemRepoRemove::dumpTo(ostream & str) const
258 HistoryItem::dumpTo(str);
262 ostream & operator<<(ostream & str, const HistoryItemRepoRemove & obj)
269 /////////////////////////////////////////////////////////////////////
271 // CLASS NAME: HistoryItemRepoAliasChange
273 /////////////////////////////////////////////////////////////////////
275 HistoryItemRepoAliasChange::HistoryItemRepoAliasChange(FieldVector & fields)
276 : HistoryItem(fields)
278 if (fields.size() != 4)
279 ZYPP_THROW(ParseException(
280 str::form("Bad number of fields. Got %zu, expected %u.",
283 oldalias = fields[2];
284 newalias = fields[3];
287 void HistoryItemRepoAliasChange::dumpTo(ostream & str) const
289 HistoryItem::dumpTo(str);
290 str << "|" << oldalias << "|" << newalias;
293 ostream & operator<<(ostream & str, const HistoryItemRepoAliasChange & obj)
300 /////////////////////////////////////////////////////////////////////
302 // CLASS NAME: HistoryItemRepoUrlChange
304 /////////////////////////////////////////////////////////////////////
306 HistoryItemRepoUrlChange::HistoryItemRepoUrlChange(FieldVector & fields)
307 : HistoryItem(fields)
309 if (fields.size() != 4)
310 ZYPP_THROW(ParseException(
311 str::form("Bad number of fields. Got %zu, expected %u.",
315 newurl = Url(fields[3]);
318 void HistoryItemRepoUrlChange::dumpTo(ostream & str) const
320 HistoryItem::dumpTo(str);
321 str << "|" << alias << "|" << newurl;
324 ostream & operator<<(ostream & str, const HistoryItemRepoUrlChange & obj)