Author: aschnell
Date: Tue Mar 18 20:32:55 2008
New Revision: 45571
URL: http://svn.opensuse.org/viewcvs/yast?rev=45571&view=rev
Log:
- faster, simpler and bugfree
Modified:
trunk/yast2/library/log/src/LogViewCore.ycp
Modified: trunk/yast2/library/log/src/LogViewCore.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/yast2/library/log/src/LogViewCore.ycp?rev=45571&r1=45570&r2=45571&view=diff
==============================================================================
--- trunk/yast2/library/log/src/LogViewCore.ycp (original)
+++ trunk/yast2/library/log/src/LogViewCore.ycp Tue Mar 18 20:32:55 2008
@@ -13,9 +13,6 @@
textdomain "base";
- import "Report";
-
-
/**
* default value of maximum displayed lines
*/
@@ -29,7 +26,7 @@
/**
- * data describing log: file, grep, command, max_lines etc.
+ * data describing log: widget, file, max_lines etc.
*/
map data = $[];
@@ -40,6 +37,23 @@
integer id = 0;
+ list<string> GetNewLines()
+ {
+ list<string> new_lines = [];
+
+ while(true)
+ {
+ string line = (string) SCR::Read(.process.read_line, id);
+ if (line == nil)
+ break;
+
+ new_lines = add(new_lines, line);
+ }
+
+ return new_lines;
+ }
+
+
/**
* Remove unneeded items from a list of lines
* If max_lines is 0, then don't remove anything
@@ -47,16 +61,15 @@
void DeleteOldLines()
{
integer max_lines = data["max_lines"]:max_lines_default;
-
if (max_lines == 0)
return;
- integer sl = size (lines);
+ integer sl = size(lines);
if (sl > max_lines)
{
- lines = filter (string l, lines, {
- sl = sl - 1;
- return sl < max_lines;
+ lines = filter(string l, lines, {
+ sl = sl - 1;
+ return sl < max_lines;
});
}
}
@@ -66,86 +79,48 @@
* Starts the log reading command via process agent.
*
* The LogView widget must exist when calling this function.
+ *
+ * Note: This function has less functionality than InitLogReading in LogView.ycp.
+ * The extra functionality was removed here since it was broken (bnc #371983).
*/
global void Start(map d)
{
data = d;
- lines = [];
- integer max_lines = data["max_lines"]:max_lines_default;
+ list<string> args = [ "--retry", "-n", sformat("%1", data["max_lines"]:max_lines_default),
+ "-f", data["file"]:"" ];
+ id = (integer) SCR::Execute (.process.start, "/usr/bin/tail", $[ "args" : args ]);
+ y2debug("started tail with args %1", args);
- string command = (string) data["command"]:nil;
- if (command == nil || command == "")
- {
- string file = data["file"]:"";
- if (file == nil || file == "")
- {
- // error report
- Report::Error (_("Error occurred while reading the log."));
- return;
- }
-
- string grep = data["grep"]:"";
- if (grep != "" && grep != nil)
- grep = sformat ("| grep --line-buffered '%1'", grep);
- string lc_command = sformat ("cat '%1' %2 | wc -l", data["file"]:"", grep);
- map bash_output = (map) SCR::Execute (.target.bash_output, lc_command);
- command = sformat("tail -f -n +0 '%1'", data["file"]:"");
- string addon = "";
- if (bash_output["exit"]:1 == 0)
- {
- string lc = bash_output["stdout"]:"";
- lc = filterchars (lc, "1234567890");
- integer lines_count = tointeger (lc);
- lines_count = lines_count - 2 * max_lines;
- // don't know why without
- // doubling it discards more lines, out of YaST2
- // it works
- if (max_lines != 0 && lines_count > 0)
- addon = sformat ("| tail -n +%1", lines_count);
- }
- command = sformat ("%1 %2 %3", command, grep, addon);
- }
-
- y2milestone ("Calling background process with command %1", command);
- id = (integer) SCR::Execute (.process.start_shell, command);
-
- sleep (100);
-
- while(true)
- {
- string line = (string) SCR::Read(.process.read_line, id);
- if (line == nil)
- break;
-
- lines = add(lines, line);
- }
+ sleep(100);
+ lines = GetNewLines();
DeleteOldLines();
- UI::ChangeWidget(`id(data["widget"]:nil), `Value, mergestring (lines, "\n") + "\n");
+ UI::ChangeWidget(`id(data["widget"]:nil), `Value, mergestring(
+ maplist(string line, lines, { return line + "\n"; } ), ""));
}
global void Update()
{
- while(true)
+ // TODO: check status of process and report error depending on exit code
+
+ list<string> new_lines = GetNewLines();
+ if (size(new_lines) > 0)
{
- string line = (string) SCR::Read(.process.read_line, id);
- if (line == nil)
- break;
+ lines = (list<string>) merge(lines, new_lines);
+ DeleteOldLines();
- lines = add(lines, line);
- UI::ChangeWidget(`id(data["widget"]:nil), `LastLine, line + "\n");
+ UI::ChangeWidget(`id(data["widget"]:nil), `LastLine, mergestring(
+ maplist(string line, new_lines, { return line + "\n"; } ), ""));
}
-
- DeleteOldLines();
}
global void Stop()
{
- SCR::Execute(.process.kill, id);
+ SCR::Execute(.process.release, id);
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org