[yast-commit] r62991 - in /branches/tmp/jsuchome/snapper/src: Snapper.ycp dialogs.ycp
Author: jsuchome Date: Tue Dec 14 18:10:19 2010 New Revision: 62991 URL: http://svn.opensuse.org/viewcvs/yast?rev=62991&view=rev Log: read the real data (WIP) Modified: branches/tmp/jsuchome/snapper/src/Snapper.ycp branches/tmp/jsuchome/snapper/src/dialogs.ycp Modified: branches/tmp/jsuchome/snapper/src/Snapper.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/jsuchome/snapper/src/Snapper.ycp?rev=62991&r1=62990&r2=62991&view=diff ============================================================================== --- branches/tmp/jsuchome/snapper/src/Snapper.ycp (original) +++ branches/tmp/jsuchome/snapper/src/Snapper.ycp Tue Dec 14 18:10:19 2010 @@ -34,15 +34,83 @@ module "Snapper"; textdomain "snapper"; +import "FileUtils"; import "Progress"; -import "Report"; -import "Summary"; -import "Message"; - global list<map> snapshots = []; +global string snapshots_path = "/snapshots"; // FIXME + +global map selected_snapshot = $[]; + +/** + * Return list of files modified in current snapshot + */ +global list<string> ReadModifiedFiles (string snapshot) { + + list<string> ret = []; + string dir = snapshots_path + "/" + snapshot; + + if (FileUtils::Exists (dir + "/files.txt")) + { + string files = (string) SCR::Read (.target.string, dir + "/files.txt"); + if (files == nil) files = ""; + ret = splitstring (files, "\n"); + } + return ret; +} + + +/** + * Read the list of snapshots + */ +global boolean ReadSnapshots () { + + map out = (map) SCR::Execute (.target.bash_output, "btrfs subvolume list /"); + y2internal ("out: %1", out); + + map snapshots_map = $[]; + snapshots = []; + + foreach (string line, splitstring (out["stdout"]:"", "\n"), { + if (line == "") return; + + list<string> l = splitstring (line, " \t"); + string sn_path = l [ size (l) - 1 ]:""; + if (sn_path != "") + sn_path = "/" + sn_path; + + // remove the last part of the path ('post', 'pre') + list<string> pl = splitstring (sn_path, "/"); + pl = remove (pl, size (pl) - 1); + + string name = pl[ size (pl) - 1 ]:""; + if (snapshots_map[name]:false) return; + snapshots_map[name] = true; + map snapshot = $[ + "name" : name + ]; + + string dir = mergestring (pl, "/"); + if (FileUtils::Exists (dir + "/description")) + { + string desc = (string) SCR::Read (.target.string, dir + "/description"); + if (desc == nil) desc = ""; + snapshot["description"] = deletechars(desc, "\n");// FIXME could description have more lines? + } + if (FileUtils::Exists (dir + "/date-pre")) + { + string date = (string) SCR::Read (.target.string, dir + "/date-pre"); + if (date == nil) date = ""; + snapshot["date"] = deletechars (date, "\n"); + } + snapshot["files"] = ReadModifiedFiles (name); + snapshots = add (snapshots, snapshot); + }); + return true; +} + /** * Read all snapper settings * @return true on success @@ -70,18 +138,7 @@ Progress::NextStage(); // read database - snapshots = [ - $[ - "name" : "first", - "description" : "description of first snapshot", - "date" : "2010-10-10", - ], - $[ - "name" : "second", - "description" : "YaST Users called", - "date" : "2010-11-11", - ] - ]; + ReadSnapshots (); Progress::NextStage(); return true; Modified: branches/tmp/jsuchome/snapper/src/dialogs.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/jsuchome/snapper/src/dialogs.ycp?rev=62991&r1=62990&r2=62991&view=diff ============================================================================== --- branches/tmp/jsuchome/snapper/src/dialogs.ycp (original) +++ branches/tmp/jsuchome/snapper/src/dialogs.ycp Tue Dec 14 18:10:19 2010 @@ -31,6 +31,7 @@ textdomain "snapper"; +import "Confirm"; import "Label"; import "Popup"; import "Wizard"; @@ -47,6 +48,10 @@ * @return `abort if aborted and `next otherwise */ symbol ReadDialog() { + + if (! Confirm::MustBeRoot ()) + return `abort; + Wizard::RestoreHelp(HELPS["read"]:""); boolean ret = Snapper::Read(); return ret ? `next : `abort; @@ -72,8 +77,10 @@ string caption = _("Snapshots"); list<map> snapshots = Snapper::snapshots; + integer i = -1; list snapshot_items = maplist (map s, snapshots, ``{ - return `item (`id (s["name"]:""), s["date"]:"", s["name"]:"", s["description"]:""); + i = i + 1; + return `item (`id (i), s["date"]:"", s["name"]:"", s["description"]:""); }); term contents = `VBox ( @@ -83,7 +90,6 @@ snapshot_items ), `HBox ( -// `PushButton (`id (`add), Label::NewButton ()), `PushButton (`id (`show), _("Show Changes")), `PushButton (`id (`edit), _("Edit Snapshot")), `Right (`PushButton (`id (`rollback), _("Rollback"))) @@ -106,6 +112,8 @@ else continue; } else if (ret == `add || ret == `show) { + integer selected = (integer) UI::QueryWidget (`id (`snapshots_table), `CurrentItem); + Snapper::selected_snapshot = snapshots[selected]:$[]; break; } else if(ret == `next) { @@ -146,10 +154,17 @@ // information about selected file map file_data = $[]; + list<string> file_list = Snapper::selected_snapshot["files"]:[]; + foreach (string file, file_list, { + // FIXME + }); + // FIXME how to get list of top directories? + /* tree_items = maplist (string dir, [ "/etc", "/opt", "/var", "/tmp"], { return `item (`id(dir), dir, false, []); }); + */ // helper for set_tree_term function: create new items for subtrees define list<term> update_items (list<term> its) { -- 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