HistoryLogData.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00013 #include <sstream>
00014
00015 #include "zypp/base/PtrTypes.h"
00016 #include "zypp/base/String.h"
00017 #include "zypp/base/Logger.h"
00018 #include "zypp/parser/ParseException.h"
00019
00020 #include "zypp/HistoryLogData.h"
00021
00022 using namespace std;
00023
00024 namespace zypp
00025 {
00026 using parser::ParseException;
00027
00028
00030
00031
00032
00034
00035 static std::map<std::string,HistoryActionID::ID> _table;
00036
00037 const HistoryActionID HistoryActionID::NONE(HistoryActionID::NONE_e);
00038 const HistoryActionID HistoryActionID::INSTALL(HistoryActionID::INSTALL_e);
00039 const HistoryActionID HistoryActionID::REMOVE(HistoryActionID::REMOVE_e);
00040 const HistoryActionID HistoryActionID::REPO_ADD(HistoryActionID::REPO_ADD_e);
00041 const HistoryActionID HistoryActionID::REPO_REMOVE(HistoryActionID::REPO_REMOVE_e);
00042 const HistoryActionID HistoryActionID::REPO_CHANGE_ALIAS(HistoryActionID::REPO_CHANGE_ALIAS_e);
00043 const HistoryActionID HistoryActionID::REPO_CHANGE_URL(HistoryActionID::REPO_CHANGE_URL_e);
00044
00045 HistoryActionID::HistoryActionID(const std::string & strval_r)
00046 : _id(parse(strval_r))
00047 {}
00048
00049 HistoryActionID::ID HistoryActionID::parse(const std::string & strval_r)
00050 {
00051 if (_table.empty())
00052 {
00053
00054 _table["install"] = INSTALL_e;
00055 _table["remove"] = REMOVE_e;
00056 _table["radd"] = REPO_ADD_e;
00057 _table["rremove"] = REPO_REMOVE_e;
00058 _table["ralias"] = REPO_CHANGE_ALIAS_e;
00059 _table["rurl"] = REPO_CHANGE_URL_e;
00060 _table["NONE"] = _table["none"] = HistoryActionID::NONE_e;
00061 }
00062
00063 std::map<std::string,HistoryActionID::ID>::const_iterator it =
00064 _table.find(strval_r);
00065
00066 if (it == _table.end())
00067 WAR << "Unknown history action ID '" + strval_r + "'";
00068
00069 return it->second;
00070 }
00071
00072
00073 const std::string & HistoryActionID::asString(bool pad) const
00074 {
00075 static std::map<ID, std::string> _table;
00076 if ( _table.empty() )
00077 {
00078
00079 _table[INSTALL_e] = "install";
00080 _table[REMOVE_e] = "remove";
00081 _table[REPO_ADD_e] = "radd";
00082 _table[REPO_REMOVE_e] = "rremove";
00083 _table[REPO_CHANGE_ALIAS_e] = "ralias";
00084 _table[REPO_CHANGE_URL_e] = "rurl";
00085 _table[NONE_e] = "NONE";
00086 }
00087
00088 if (pad)
00089 return _table[_id].append(7 - _table[_id].size(), ' ');
00090 return _table[_id];
00091 }
00092
00093 std::ostream & operator << (std::ostream & str, const HistoryActionID & id)
00094 { return str << id.asString(); }
00095
00097
00098
00100
00101
00102
00104
00105 HistoryItem::HistoryItem(FieldVector & fields)
00106 {
00107 if (fields.size() <= 2)
00108 ZYPP_THROW(ParseException(
00109 str::form("Bad number of fields. Got %zd, expected more than %d.",
00110 fields.size(), 2)));
00111
00112 date = Date(fields[0], HISTORY_LOG_DATE_FORMAT);
00113 action = HistoryActionID(str::trim(fields[1]));
00114 }
00115
00116 void HistoryItem::dumpTo(ostream & str) const
00117 {
00118 str << date.form(HISTORY_LOG_DATE_FORMAT) << "|" << action.asString();
00119 }
00120
00121 ostream & operator<<(ostream & str, const HistoryItem & obj)
00122 {
00123 obj.dumpTo(str);
00124 return str;
00125 }
00126
00127
00129
00130
00131
00133
00134 HistoryItemInstall::HistoryItemInstall(FieldVector & fields)
00135 : HistoryItem(fields)
00136 {
00137 if (fields.size() != 8)
00138 ZYPP_THROW(ParseException(
00139 str::form("Bad number of fields. Got %zu, expected %u.",
00140 fields.size(), 8)));
00141
00142 name = fields[2];
00143 edition = Edition(fields[3]);
00144 arch = Arch(fields[4]);
00145 reqby = fields[5];
00146 repoalias = fields[6];
00147 checksum = CheckSum::sha(fields[7]);
00148 }
00149
00150 void HistoryItemInstall::dumpTo(ostream & str) const
00151 {
00152 HistoryItem::dumpTo(str);
00153 str << "|"
00154 << name << "|"
00155 << edition << "|"
00156 << arch << "|"
00157 << reqby << "|"
00158 << repoalias << "|"
00159 << checksum;
00160 }
00161
00162 ostream & operator<<(ostream & str, const HistoryItemInstall & obj)
00163 {
00164 obj.dumpTo(str);
00165 return str;
00166 }
00167
00168
00170
00171
00172
00174
00175 HistoryItemRemove::HistoryItemRemove(FieldVector & fields)
00176 : HistoryItem(fields)
00177 {
00178 if (fields.size() != 6)
00179 ZYPP_THROW(ParseException(
00180 str::form("Bad number of fields. Got %zu, expected %u.",
00181 fields.size(), 6)));
00182
00183 name = fields[2];
00184 edition = Edition(fields[3]);
00185 arch = Arch(fields[4]);
00186 reqby = fields[5];
00187 }
00188
00189 void HistoryItemRemove::dumpTo(ostream & str) const
00190 {
00191 HistoryItem::dumpTo(str);
00192 str << "|"
00193 << name << "|"
00194 << edition << "|"
00195 << arch << "|"
00196 << reqby;
00197 }
00198
00199 ostream & operator<<(ostream & str, const HistoryItemRemove & obj)
00200 {
00201 obj.dumpTo(str);
00202 return str;
00203 }
00204
00205
00207
00208
00209
00211
00212 HistoryItemRepoAdd::HistoryItemRepoAdd(FieldVector & fields)
00213 : HistoryItem(fields)
00214 {
00215 if (fields.size() != 4)
00216 ZYPP_THROW(ParseException(
00217 str::form("Bad number of fields. Got %zu, expected %u.",
00218 fields.size(), 4)));
00219
00220 alias = fields[2];
00221 url = Url(fields[3]);
00222 }
00223
00224 void HistoryItemRepoAdd::dumpTo(ostream & str) const
00225 {
00226 HistoryItem::dumpTo(str);
00227 str << "|"
00228 << alias << "|"
00229 << url;
00230 }
00231
00232 ostream & operator<<(ostream & str, const HistoryItemRepoAdd & obj)
00233 {
00234 obj.dumpTo(str);
00235 return str;
00236 }
00237
00238
00240
00241
00242
00244
00245 HistoryItemRepoRemove::HistoryItemRepoRemove(FieldVector & fields)
00246 : HistoryItem(fields)
00247 {
00248 if (fields.size() != 3)
00249 ZYPP_THROW(ParseException(
00250 str::form("Bad number of fields. Got %zu, expected %u.",
00251 fields.size(), 3)));
00252
00253 alias = fields[2];
00254 }
00255
00256 void HistoryItemRepoRemove::dumpTo(ostream & str) const
00257 {
00258 HistoryItem::dumpTo(str);
00259 str << "|" << alias;
00260 }
00261
00262 ostream & operator<<(ostream & str, const HistoryItemRepoRemove & obj)
00263 {
00264 obj.dumpTo(str);
00265 return str;
00266 }
00267
00268
00270
00271
00272
00274
00275 HistoryItemRepoAliasChange::HistoryItemRepoAliasChange(FieldVector & fields)
00276 : HistoryItem(fields)
00277 {
00278 if (fields.size() != 4)
00279 ZYPP_THROW(ParseException(
00280 str::form("Bad number of fields. Got %zu, expected %u.",
00281 fields.size(), 4)));
00282
00283 oldalias = fields[2];
00284 newalias = fields[3];
00285 }
00286
00287 void HistoryItemRepoAliasChange::dumpTo(ostream & str) const
00288 {
00289 HistoryItem::dumpTo(str);
00290 str << "|" << oldalias << "|" << newalias;
00291 }
00292
00293 ostream & operator<<(ostream & str, const HistoryItemRepoAliasChange & obj)
00294 {
00295 obj.dumpTo(str);
00296 return str;
00297 }
00298
00299
00301
00302
00303
00305
00306 HistoryItemRepoUrlChange::HistoryItemRepoUrlChange(FieldVector & fields)
00307 : HistoryItem(fields)
00308 {
00309 if (fields.size() != 4)
00310 ZYPP_THROW(ParseException(
00311 str::form("Bad number of fields. Got %zu, expected %u.",
00312 fields.size(), 4)));
00313
00314 alias = fields[2];
00315 newurl = Url(fields[3]);
00316 }
00317
00318 void HistoryItemRepoUrlChange::dumpTo(ostream & str) const
00319 {
00320 HistoryItem::dumpTo(str);
00321 str << "|" << alias << "|" << newurl;
00322 }
00323
00324 ostream & operator<<(ostream & str, const HistoryItemRepoUrlChange & obj)
00325 {
00326 obj.dumpTo(str);
00327 return str;
00328 }
00329
00330
00331 }