[yast-commit] r66305 - in /branches/SuSE-Code-11-SP2-Branch/snapper: VERSION agent-snapper/src/SnapperAgent.cc agent-snapper/src/SnapperAgent.h package/yast2-snapper.changes src/Snapper.ycp src/dialogs.ycp
Author: jsuchome Date: Thu Oct 6 16:10:29 2011 New Revision: 66305 URL: http://svn.opensuse.org/viewcvs/yast?rev=66305&view=rev Log: - support more snapper configurations (bnc#719482) - 2.17.5 Modified: branches/SuSE-Code-11-SP2-Branch/snapper/VERSION branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.cc branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.h branches/SuSE-Code-11-SP2-Branch/snapper/package/yast2-snapper.changes branches/SuSE-Code-11-SP2-Branch/snapper/src/Snapper.ycp branches/SuSE-Code-11-SP2-Branch/snapper/src/dialogs.ycp Modified: branches/SuSE-Code-11-SP2-Branch/snapper/VERSION URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/snapper/VERSION?rev=66305&r1=66304&r2=66305&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/snapper/VERSION (original) +++ branches/SuSE-Code-11-SP2-Branch/snapper/VERSION Thu Oct 6 16:10:29 2011 @@ -1 +1 @@ -2.17.4 +2.17.5 Modified: branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.cc?rev=66305&r1=66304&r2=66305&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.cc (original) +++ branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.cc Thu Oct 6 16:10:29 2011 @@ -18,13 +18,13 @@ /* * search the map for value of given key; both key and value have to be strings */ -string SnapperAgent::getValue (const YCPMap map, const string key) +string SnapperAgent::getValue (const YCPMap map, const string key, string deflt) { if (!map->value(YCPString(key)).isNull() && map->value(YCPString(key))->isString()) return map->value(YCPString(key))->asString()->value(); else - return ""; + return deflt; } /** @@ -132,14 +132,14 @@ */ YCPValue SnapperAgent::Read(const YCPPath &path, const YCPValue& arg, const YCPValue& opt) { - y2debug ("path in Read: '%s'.", path->toString().c_str()); + y2internal ("path in Read: '%s'.", path->toString().c_str()); YCPValue ret = YCPVoid(); YCPMap argmap; if (!arg.isNull() && arg->isMap()) argmap = arg->asMap(); - if (!snapper_initialized && PC(0) != "error") { + if (!snapper_initialized && PC(0) != "error" && PC(0) != "configs") { y2error ("snapper not initialized: use Execute (.snapper) first!"); snapper_error = "not_initialized"; return YCPVoid(); @@ -147,6 +147,24 @@ if (path->length() == 1) { + if (PC(0) == "configs") { + YCPList retlist; + + try { + list<ConfigInfo> configs = Snapper::getConfigs(); + for (list<ConfigInfo>::const_iterator it = configs.begin(); it != configs.end(); ++it) + { + retlist->add (YCPString (it->config_name)); + } + } + catch (const ListConfigsFailedException& e) + { + y2error ("sysconfig file not found."); + snapper_error = "sysconfig_not_found"; + return YCPVoid(); + } + return retlist; + } /** * Read (.snapper.error) -> returns last error message */ @@ -201,7 +219,7 @@ s->add (YCPString ("pre_num"), YCPInteger (it->getPreNum())); } - y2debug ("snapshot %s", s.toString().c_str()); + y2internal ("snapshot %s", s.toString().c_str()); retlist->add (s); } return retlist; @@ -242,7 +260,10 @@ for (Files::const_iterator it = files.begin(); it != files.end(); ++it) { - retmap->add (YCPString (it->getName()), YCPString (statusToString (it->getPreToPostStatus()))); + YCPMap file_map; + file_map->add (YCPString ("status"), YCPString (statusToString (it->getPreToPostStatus()))); + file_map->add (YCPString ("full_path"), YCPString (it->getAbsolutePath (LOC_SYSTEM))); + retmap->add (YCPString (it->getName()), file_map); } return retmap; } @@ -294,7 +315,7 @@ YCPBoolean SnapperAgent::Write(const YCPPath &path, const YCPValue& arg, const YCPValue& arg2) { - y2debug ("path in Write: '%s'.", path->toString().c_str()); + y2internal ("path in Write: '%s'.", path->toString().c_str()); YCPBoolean ret = YCPBoolean(true); return ret; @@ -306,7 +327,7 @@ YCPValue SnapperAgent::Execute(const YCPPath &path, const YCPValue& arg, const YCPValue& arg2) { - y2debug ("path in Execute: '%s'.", path->toString().c_str()); + y2internal ("path in Execute: '%s'.", path->toString().c_str()); YCPValue ret = YCPBoolean (true); YCPMap argmap; @@ -317,9 +338,17 @@ * Execute (.snapper) call: Initialize snapper object */ if (path->length() == 0) { + + snapper_initialized = false; + if (sh) + { + y2milestone ("deleting existing snapper object"); + deleteSnapper(sh); + } + string config_name = getValue (argmap, "config", "root"); try { - sh = createSnapper(); + sh = createSnapper (config_name); } catch (const ConfigNotFoundException& e) { @@ -363,7 +392,7 @@ if (selected.value(i)->isString()) { string name = selected->value(i)->asString()->value(); - y2debug ("file to rollback: %s", name.c_str()); + y2internal ("file to rollback: %s", name.c_str()); Files::iterator it = files.find(name); if (it == files.end()) { Modified: branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.h?rev=66305&r1=66304&r2=66305&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.h (original) +++ branches/SuSE-Code-11-SP2-Branch/snapper/agent-snapper/src/SnapperAgent.h Thu Oct 6 16:10:29 2011 @@ -35,9 +35,9 @@ /** * search the map for value of given key; both key and value have to be strings - * when key is not present, empty string is returned + * when key is not present, default value is returned */ - string getValue (const YCPMap map, const string key); + string getValue (const YCPMap map, const string key, string deflt); /** * Search the map for value of given key Modified: branches/SuSE-Code-11-SP2-Branch/snapper/package/yast2-snapper.changes URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/snapper/package/yast2-snapper.changes?rev=66305&r1=66304&r2=66305&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/snapper/package/yast2-snapper.changes (original) +++ branches/SuSE-Code-11-SP2-Branch/snapper/package/yast2-snapper.changes Thu Oct 6 16:10:29 2011 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Wed Sep 21 16:07:48 CEST 2011 - jsuchome@suse.cz + +- support more snapper configurations (bnc#719482) +- 2.17.5 + +------------------------------------------------------------------- Tue Aug 30 11:40:52 CEST 2011 - jsuchome@suse.cz - added icon (bnc#711193) Modified: branches/SuSE-Code-11-SP2-Branch/snapper/src/Snapper.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/snapper/src/Snapper.ycp?rev=66305&r1=66304&r2=66305&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/snapper/src/Snapper.ycp (original) +++ branches/SuSE-Code-11-SP2-Branch/snapper/src/Snapper.ycp Thu Oct 6 16:10:29 2011 @@ -51,12 +51,17 @@ // index to snapshots list global integer selected_snapshot_index = 0; +// list of configurations +global list<string> configs = [ "root" ]; + +global string current_config = "root"; + /** * Return map of files modified between given snapshots * Return structure has just one level, and maps each modified file to it's modification map */ -global map<string,string> ReadModifiedFilesIndex (integer from, integer to) { - return (map<string,string>) SCR::Read (.snapper.diff_index, $[ "from" : from, "to" : to]); +global map<string,map> ReadModifiedFilesIndex (integer from, integer to) { + return (map<string,map>) SCR::Read (.snapper.diff_index, $[ "from" : from, "to" : to]); } /** @@ -91,7 +96,9 @@ string file1 = sformat ("%1%2", GetSnapshotPath (old), file); string file2 = sformat ("%1%2", GetSnapshotPath (new), file); if (new == 0) - file2 = file; + { + file2 = snapshots[selected_snapshot_index,"files_index",file,"full_path"]:file; + } y2milestone ("comparing '%1' and '%2'", file1, file2); @@ -157,7 +164,7 @@ */ global boolean ReadSnapshots () { - + snapshots = []; list<map> snapshot_maps = (list<map>) SCR::Read (.snapper.snapshots); if (snapshot_maps == nil) snapshot_maps = []; integer i = 0; @@ -170,8 +177,6 @@ id2index[id] = i; i = i + 1; }); - - return true; } @@ -180,13 +185,28 @@ return (map) SCR::Read (.snapper.error); } + +global list<string> ReadConfigs () { + + configs = (list<string>) SCR::Read (.snapper.configs); + if (configs == nil) + { + // error popup + Report::Error (_("File /etc/sysconfig/snapper is not available")); + configs = [ "root" ]; + } + return configs; +} + + + /** * Initialize snapper agent * Return true on success */ -global boolean InitializeSnapper () { +global boolean InitializeSnapper (string config) { - boolean init = (boolean) SCR::Execute (.snapper); + boolean init = (boolean) SCR::Execute (.snapper, $[ "config" : config ]); if (!init) { map err_map = LastSnapperErrorMap (); @@ -236,7 +256,9 @@ Progress::NextStage(); - if (!InitializeSnapper ()) + ReadConfigs (); + + if (!InitializeSnapper (current_config)) { return false; } @@ -282,8 +304,9 @@ UI::ChangeWidget (`id (`progress ), `Value, progress); string orig = GetSnapshotPath (snapshot_num) + file; + string full_path= snapshots[selected_snapshot_index,"files_index",file,"full_path"]:file; + string dir = substring (full_path, 0, findlastof (full_path, "/")); - string dir = substring (file, 0, findlastof (file, "/")); if (!FileUtils::Exists (orig)) { // log entry (%1 is file name) @@ -295,24 +318,24 @@ if (FileUtils::IsDirectory (orig) == true) { map stat = (map) SCR::Read (.target.stat, orig); - if (!FileUtils::Exists (file)) + if (!FileUtils::Exists (full_path)) { - SCR::Execute (.target.mkdir, file); + SCR::Execute (.target.mkdir, full_path); } - SCR::Execute (.target.bash, sformat ("/bin/chown %1:%2 '%3'", stat["uid"]:0, stat["gid"]:0, file)); - SCR::Execute (.target.bash, sformat ("/bin/chmod %1 '%2'", GetFileMode (orig), file)); + SCR::Execute (.target.bash, sformat ("/bin/chown %1:%2 '%3'", stat["uid"]:0, stat["gid"]:0, full_path)); + SCR::Execute (.target.bash, sformat ("/bin/chmod %1 '%2'", GetFileMode (orig), full_path)); } else { - SCR::Execute (.target.bash, sformat ("/bin/cp -a '%1' '%2'", orig, file)); + SCR::Execute (.target.bash, sformat ("/bin/cp -a '%1' '%2'", orig, full_path)); } - UI::ChangeWidget (`id (`log), `LastLine, file + "\n"); + UI::ChangeWidget (`id (`log), `LastLine, full_path + "\n"); } else { - y2milestone ("failed to copy file '%1' to '%2' (dir: %3)", orig, file, dir); + y2milestone ("failed to copy file '%1' to '%2' (dir: %3)", orig, full_path, dir); // log entry (%1 is file name) - UI::ChangeWidget (`id (`log), `LastLine, sformat (_("%1 skipped\n"), file)); + UI::ChangeWidget (`id (`log), `LastLine, sformat (_("%1 skipped\n"), full_path)); } sleep (100); progress = progress + 1; Modified: branches/SuSE-Code-11-SP2-Branch/snapper/src/dialogs.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/snapper/src/dialogs.ycp?rev=66305&r1=66304&r2=66305&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/snapper/src/dialogs.ycp (original) +++ branches/SuSE-Code-11-SP2-Branch/snapper/src/dialogs.ycp Thu Oct 6 16:10:29 2011 @@ -67,12 +67,16 @@ /* summary dialog caption */ string caption = _("Snapshots"); - list<map> snapshots = Snapper::snapshots; - integer i = -1; + list<map> snapshots = Snapper::snapshots; + list<string> configs = Snapper::configs; list snapshot_items = []; - foreach (map s, snapshots, { + list get_snapshot_items () { + + integer i = -1; + snapshot_items = []; + foreach (map s, snapshots, { i = i + 1; integer num = s["num"]:0; @@ -103,13 +107,23 @@ { y2milestone ("skipping pre snapshot: %1", num); } - }); + }); + return snapshot_items; + } term contents = `VBox ( + `HBox ( + // combo box label + `Label (_("Current Configuration")), + `ComboBox (`id (`configs), `opt (`notify), "", maplist (string config, configs, { + return `item (`id (config), config, config == Snapper::current_config); + })), + `HStretch () + ), `Table (`id (`snapshots_table), `opt(`notify, `keepSorting), `header ( // table header _("ID"), _("Type"), _("Start Date"), _("End Date"), _("Description")), - snapshot_items + get_snapshot_items () ), `HBox ( `PushButton (`id (`show_c), `opt (`default), _("Show Changes")), @@ -127,6 +141,7 @@ { UI::ChangeWidget (`id (`show_c), `Enabled, false); } + UI::ChangeWidget (`id (`configs), `Enabled, size (configs) > 1); any ret = nil; while(true) { @@ -150,8 +165,25 @@ Snapper::selected_snapshot_index = selected; break; } - else if(ret == `next) { - // TODO check if something needs to be written (description) + else if (ret == `configs) { + string config = (string) UI::QueryWidget (`id (ret), `Value); + if (config != Snapper::current_config) + { + Snapper::current_config = config; + + // busy popup message + Popup::ShowFeedback ("", _("Reading list of snapshots...")); + + Snapper::InitializeSnapper (config); + Snapper::ReadSnapshots (); + snapshots = Snapper::snapshots; + Popup::ClearFeedback (); + + UI::ChangeWidget (`id (`snapshots_table), `Items, get_snapshot_items ()); + continue; + } + } + else if (ret == `next) { break; } else { @@ -225,7 +257,7 @@ tree_map = snapshot["tree_map"]:$[]; } // full paths of files marked as modified, mapping to changes string - map<string,string> files_index = $[]; + map<string,map> files_index = $[]; if (!haskey (snapshot, "files_index")) { snapshot["files_index"] = Snapper::ReadModifiedFilesIndex (from, to); @@ -242,10 +274,10 @@ map<string,boolean> selected_items = $[]; boolean file_was_created (string file) { - return (substring (files_index[file]:"", 0, 1) == "+"); + return (substring (files_index[file,"status"]:"", 0, 1) == "+"); } boolean file_was_removed (string file) { - return (substring (files_index[file]:"", 0, 1) == "-"); + return (substring (files_index[file,"status"]:"", 0, 1) == "-"); } // go through the map defining filesystem tree and create the widget items -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
jsuchome@svn2.opensuse.org