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 %ld, expected more than %d.",
112 date = Date(fields[0], HISTORY_LOG_DATE_FORMAT);
113 action = HistoryActionID(str::trim(fields[1]));
116 /////////////////////////////////////////////////////////////////////
118 // CLASS NAME: HistoryItemInstall
120 /////////////////////////////////////////////////////////////////////
122 HistoryItemInstall::HistoryItemInstall(FieldVector & fields)
123 : HistoryItem(fields)
125 if (fields.size() != 8)
126 ZYPP_THROW(ParseException(
127 str::form("Bad number of fields. Got %lu, expected %u.",
131 edition = Edition(fields[3]);
132 arch = Arch(fields[4]);
134 repoalias = fields[6];
135 checksum = CheckSum::sha(fields[7]);
138 const std::string HistoryItemInstall::asString() const
142 << date.form(HISTORY_LOG_DATE_FORMAT) << "|"
143 << action.asString() << "|"
153 std::ostream & operator<<(std::ostream & str, const HistoryItemInstall & obj)
155 return str << obj.asString();
159 /////////////////////////////////////////////////////////////////////
161 // CLASS NAME: HistoryItemRemove
163 /////////////////////////////////////////////////////////////////////
165 HistoryItemRemove::HistoryItemRemove(FieldVector & fields)
166 : HistoryItem(fields)
168 if (fields.size() != 6)
169 ZYPP_THROW(ParseException(
170 str::form("Bad number of fields. Got %lu, expected %u.",
174 edition = Edition(fields[3]);
175 arch = Arch(fields[4]);
180 /////////////////////////////////////////////////////////////////////
182 // CLASS NAME: HistoryItemRepoAdd
184 /////////////////////////////////////////////////////////////////////
186 HistoryItemRepoAdd::HistoryItemRepoAdd(FieldVector & fields)
187 : HistoryItem(fields)
189 if (fields.size() != 4)
190 ZYPP_THROW(ParseException(
191 str::form("Bad number of fields. Got %lu, expected %u.",
195 url = Url(fields[3]);
199 /////////////////////////////////////////////////////////////////////
201 // CLASS NAME: HistoryItemRepoRemove
203 /////////////////////////////////////////////////////////////////////
205 HistoryItemRepoRemove::HistoryItemRepoRemove(FieldVector & fields)
206 : HistoryItem(fields)
208 if (fields.size() != 3)
209 ZYPP_THROW(ParseException(
210 str::form("Bad number of fields. Got %lu, expected %u.",
217 /////////////////////////////////////////////////////////////////////
219 // CLASS NAME: HistoryItemRepoAliasChange
221 /////////////////////////////////////////////////////////////////////
223 HistoryItemRepoAliasChange::HistoryItemRepoAliasChange(FieldVector & fields)
224 : HistoryItem(fields)
226 if (fields.size() != 4)
227 ZYPP_THROW(ParseException(
228 str::form("Bad number of fields. Got %lu, expected %u.",
231 oldalias = fields[2];
232 newalias = fields[3];
236 /////////////////////////////////////////////////////////////////////
238 // CLASS NAME: HistoryItemRepoUrlChange
240 /////////////////////////////////////////////////////////////////////
242 HistoryItemRepoUrlChange::HistoryItemRepoUrlChange(FieldVector & fields)
243 : HistoryItem(fields)
245 if (fields.size() != 4)
246 ZYPP_THROW(ParseException(
247 str::form("Bad number of fields. Got %lu, expected %u.",
251 newurl = Url(fields[3]);