Author: jsuchome
Date: Mon Feb 7 16:26:22 2011
New Revision: 63365
URL: http://svn.opensuse.org/viewcvs/yast?rev=63365&view=rev
Log:
use agent to read snapshot diffs
differentiate between snapshot types
Modified:
branches/tmp/jsuchome/snapper/agent-snapper/src/SnapperAgent.cc
branches/tmp/jsuchome/snapper/src/Snapper.ycp
branches/tmp/jsuchome/snapper/src/dialogs.ycp
Modified: branches/tmp/jsuchome/snapper/agent-snapper/src/SnapperAgent.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/jsuchome/snapper/agent-snapper/src/SnapperAgent.cc?rev=63365&r1=63364&r2=63365&view=diff
==============================================================================
--- branches/tmp/jsuchome/snapper/agent-snapper/src/SnapperAgent.cc (original)
+++ branches/tmp/jsuchome/snapper/agent-snapper/src/SnapperAgent.cc Mon Feb 7 16:26:22 2011
@@ -161,9 +161,8 @@
for (Files::const_iterator it = files.begin(); it != files.end(); ++it)
{
YCPMap filemap;
- y2internal ("file :%s ", it->getName().c_str ());
- y2internal ("pre to post status: %d", it->getPreToPostStatus());
filemap->add (YCPString ("name"), YCPString (it->getName()));
+ // FIXME it's PreToPostStatus!
filemap->add (YCPString ("changes"), YCPString (statusToString (it->getPreToPostStatus())));
retlist->add (filemap);
}
Modified: branches/tmp/jsuchome/snapper/src/Snapper.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/jsuchome/snapper/src/Snapper.ycp?rev=63365&r1=63364&r2=63365&view=diff
==============================================================================
--- branches/tmp/jsuchome/snapper/src/Snapper.ycp (original)
+++ branches/tmp/jsuchome/snapper/src/Snapper.ycp Mon Feb 7 16:26:22 2011
@@ -45,42 +45,25 @@
global map selected_snapshot = $[];
/**
- * Return list of files modified in current snapshot
+ * Return list of files modified between given snapshots
* File is a map with name (path) and some parameters
*/
-global list<map> ReadModifiedFiles (string snapshot) {
+global list<map> ReadModifiedFiles (integer from, integer to) {
- list<map> 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 = "";
- foreach (string file, splitstring (files, "\n"), {
- if (file == "") return;
- list<string> parts = splitstring (file, " \t");
- ret = add (ret, $[
- "name" : parts[1]:"",
- "changes" : parts[0]:""
- ]);
- });
- }
- return ret;
+ return (list<map>) SCR::Read (.snapper.diff, $[ "from" : from, "to" : to]);
}
/**
- * Describe what was done with given file in given snapshot
- FIXME compare arbitrary snapshots
- * - when new is "", meaning is 'current system'
+ * Describe what was done with given file between given snapshots
+ * - when new is 0, meaning is 'current system'
*/
-global map GetFileModification (string file, string old, string new) {
+global map GetFileModification (string file, integer old, integer new) {
map ret = $[];
- string file1 = sformat ("%1/%2%3", snapshots_path, old, file);
- string file2 = sformat ("%1/%2%3", snapshots_path, new, file);
- if (new == "")
+ string file1 = sformat ("%1/%2/snapshot/%3", snapshots_path, old, file);
+ string file2 = sformat ("%1/%2/snapshot/%3", snapshots_path, new, file);
+ if (new == 0)
file2 = file;
if (FileUtils::Exists (file1) && FileUtils::Exists (file2))
@@ -119,55 +102,18 @@
global boolean ReadSnapshots () {
- /*
- map out = (map) SCR::Execute (.target.bash_output, "btrfs subvolume list /");
-
- 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);
- });
- */
-
list<map> snapshot_maps = (list<map>) SCR::Read (.snapper.snapshots);
foreach (map snapshot, snapshot_maps, {
- y2internal ("current snapshot: %1", snapshot);
- snapshot["name"] = tostring (snapshot["num"]:0);
- // FIXME files are missing...
+ integer id = snapshot["num"]:0;
+ if (id == 0) return; // ignore the 'current system'
+ snapshot["name"] = tostring (id);
+ if (snapshot["type"]:`NONE == `POST)
+ {
+ integer pre = snapshot["pre_num"]:0;
+ snapshot["files"] = ReadModifiedFiles (pre, id);
+ }
+ y2internal ("snapshot data: %1", snapshot);
snapshots = add (snapshots, snapshot);
});
Modified: branches/tmp/jsuchome/snapper/src/dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/jsuchome/snapper/src/dialogs.ycp?rev=63365&r1=63364&r2=63365&view=diff
==============================================================================
--- branches/tmp/jsuchome/snapper/src/dialogs.ycp (original)
+++ branches/tmp/jsuchome/snapper/src/dialogs.ycp Mon Feb 7 16:26:22 2011
@@ -78,25 +78,50 @@
list<map> snapshots = Snapper::snapshots;
integer i = -1;
- list snapshot_items = maplist (map s, snapshots, ``{
- i = i + 1;
+ list single_snapshot_items = [];
+ list coupled_snapshot_items = [];
+
+ foreach (map s, snapshots, ``{
+ i = i + 1;
string date = "";
if (s["num"]:0 != 0)
date = timestring("%c", s["date"]:0, false);
- return `item (`id (i), date, s["name"]:"", s["description"]:"");
+ if (s["type"]:`none == `SINGLE)
+ single_snapshot_items = add (single_snapshot_items,
+ `item (`id (i), date, s["name"]:"", s["description"]:""));
+ else
+ {
+ string pre = s["pre_num"]:0 != 0 ? tostring (s["pre_num"]:0) : "";
+ coupled_snapshot_items = add (coupled_snapshot_items,
+ `item (`id (i), date, s["name"]:"", pre, s["description"]:""));
+ }
});
term contents = `VBox (
- `Table (`id (`snapshots_table), `opt(`notify, `keepSorting), `header (
+ // label
+ `Left (`Label (_("Single Snapshots"))),
+ `Table (`id (`single_snapshots_table), `opt(`notify, `keepSorting), `header (
// table header
_("Date"), _("Number"), _("Description")),
- snapshot_items
+ single_snapshot_items
+ ),
+ `HBox (
+ `PushButton (`id (`show_s), _("Show Changes")),
+ `HStretch ()
+ ),
+ `VSpacing (0.5),
+ // label
+ `Left (`Label (_("Coupled Snapshots"))),
+ `Table (`id (`coupled_snapshots_table), `opt(`notify, `keepSorting), `header (
+ // table header
+ _("Date"), _("Number"), _("Previous"), _("Description")),
+ coupled_snapshot_items
),
`HBox (
- `PushButton (`id (`show), `opt (`default), _("Show Changes")),
- `PushButton (`id (`edit), _("Edit Snapshot")),
+ `PushButton (`id (`show_c), `opt (`default), _("Show Changes")),
+// `PushButton (`id (`edit), _("Edit Snapshot")),
`HStretch ()
)
);
@@ -106,22 +131,35 @@
Wizard::HideBackButton ();
Wizard::HideAbortButton ();
- UI::SetFocus (`id (`snapshots_table));
+ UI::SetFocus (`id (`coupled_snapshots_table));
+ if (coupled_snapshot_items == [] && single_snapshot_items != [])
+ UI::SetFocus (`id (`single_snapshots_table));
any ret = nil;
while(true) {
ret = UI::UserInput();
- if (ret == `snapshots_table) {
+ integer selected = 0;
+
+ if (ret == `single_snapshots_table || ret == `coupled_snapshots_table) {
+ selected = (integer) UI::QueryWidget (`id (ret), `CurrentItem);
ret = `show;
}
+ if (ret == `show_s) {
+ selected = (integer) UI::QueryWidget (`id (`single_snapshots_table), `CurrentItem);
+ ret = `show;
+ }
+ if (ret == `show_c) {
+ selected = (integer) UI::QueryWidget (`id (`coupled_snapshots_table), `CurrentItem);
+ ret = `show;
+ }
+
if(ret == `abort || ret == `cancel || ret == `back) {
if(ReallyAbort()) break;
else continue;
}
- else if (ret == `add || ret == `show) {
- integer selected = (integer) UI::QueryWidget (`id (`snapshots_table), `CurrentItem);
+ else if (ret == `show) {
Snapper::selected_snapshot = snapshots[selected]:$[];
break;
}
@@ -158,7 +196,10 @@
map open_items = $[];
list<map> file_list = Snapper::selected_snapshot["files"]:[];
- string snapshot_name = Snapper::selected_snapshot["name"]:"";
+ integer snapshot_num = Snapper::selected_snapshot["num"]:0;
+ // FIXME what to use for previous_num in non-post snapshots?
+ integer previous_num = Snapper::selected_snapshot["pre_num"]:snapshot_num;
+ string snapshot_name = tostring (snapshot_num);
map