Class: Yast::LogViewCoreClass
- Inherits:
-
Module
- Object
- Module
- Yast::LogViewCoreClass
- Defined in:
- ../../src/modules/LogViewCore.rb
Instance Method Summary (collapse)
-
- (Object) DeleteOldLines
Remove unneeded items from a list of lines If max_lines is 0, then don't remove anything.
- - (Object) GetLines
- - (Object) GetNewLines
- - (Object) main
-
- (Object) Start(widget, d)
Starts the log reading command via process agent.
- - (Object) Stop
- - (Object) Update(widget)
Instance Method Details
- (Object) DeleteOldLines
Remove unneeded items from a list of lines If max_lines is 0, then don't remove anything
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File '../../src/modules/LogViewCore.rb', line 91 def DeleteOldLines max_lines = Ops.get_integer(@data, "max_lines", @max_lines_default) return if max_lines == 0 if Ops.greater_than( Ops.subtract(Ops.subtract(Builtins.size(@lines), max_lines), 1), 0 ) @lines = Builtins.sublist( @lines, Ops.subtract(Ops.subtract(Builtins.size(@lines), max_lines), 1) ) end nil end |
- (Object) GetLines
234 235 236 |
# File '../../src/modules/LogViewCore.rb', line 234 def GetLines deep_copy(@lines) end |
- (Object) GetNewLines
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File '../../src/modules/LogViewCore.rb', line 67 def GetNewLines return [] if !@is_running if !Convert.to_boolean(SCR.Read(path(".process.running"), @id)) @is_running = false Report.Error(_("Error occurred while reading the log.")) return [] end new_lines = [] while true line = Convert.to_string(SCR.Read(path(".process.read_line"), @id)) break if line == nil new_lines = Builtins.add(new_lines, line) end deep_copy(new_lines) end |
- (Object) main
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File '../../src/modules/LogViewCore.rb', line 35 def main Yast.import "UI" textdomain "base" Yast.import "Report" # default value of maximum displayed lines @max_lines_default = 100 # lines of the log @lines = [] # data describing log: # file: filename to read from # grep: grep file with expression # command: command to run (use instead of file and grep) # max_lines: max lines to keep (0 -> infinite) @data = {} # id of background process @id = nil # flag indicating if background process is (or should be) running @is_running = false end |
- (Object) Start(widget, d)
Starts the log reading command via process agent.
The LogView widget must exist when calling this function. The `MaxLines parameter of the widget will be set.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File '../../src/modules/LogViewCore.rb', line 113 def Start(, d) = deep_copy() d = deep_copy(d) if @id != nil SCR.Execute(path(".process.release"), @id) @id = nil end @data = deep_copy(d) file = Ops.get_string(@data, "file", "") grep = Ops.get_string(@data, "grep", "") command = Ops.get_string(@data, "command", "") max_lines = Ops.get_integer(@data, "max_lines", @max_lines_default) if command == "" if grep == "" command = Builtins.sformat("tail -n %1 -f '%2'", max_lines, file) else command = Builtins.sformat( "tail -n +0 -f '%1' | grep --line-buffered '%2'", file, grep ) if max_lines != 0 lc_command = Builtins.sformat( "cat '%1' | grep '%2' | wc -l", file, grep ) bash_output = Convert.to_map( SCR.Execute(path(".target.bash_output"), lc_command) ) if Ops.get_integer(bash_output, "exit", 1) == 0 lc = Builtins.filterchars( Ops.get_string(bash_output, "stdout", ""), "1234567890" ) lines_count = Builtins.tointeger(lc) # don't know why without doubling it discards more lines, # out of YaST2 it works lines_count = Ops.subtract( lines_count, Ops.multiply(2, max_lines) ) lines_count = 0 if Ops.less_than(lines_count, 0) if Ops.greater_than(lines_count, 0) command = Ops.add( command, Builtins.sformat(" | tail -n +%1", lines_count) ) end end end end end Builtins.y2milestone("Calling process agent with command %1", command) @id = Convert.to_integer( SCR.Execute(path(".process.start_shell"), command, { "tty" => true }) ) @is_running = true Builtins.sleep(100) @lines = GetNewLines() DeleteOldLines() UI.ChangeWidget(, :MaxLines, max_lines) UI.ChangeWidget( , :Value, Builtins.mergestring(Builtins.maplist(@lines) do |line| Ops.add(line, "\n") end, "") ) nil end |
- (Object) Stop
224 225 226 227 228 229 230 231 |
# File '../../src/modules/LogViewCore.rb', line 224 def Stop if @id != nil SCR.Execute(path(".process.release"), @id) @id = nil end nil end |
- (Object) Update(widget)
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File '../../src/modules/LogViewCore.rb', line 198 def Update() = deep_copy() if @id != nil new_lines = GetNewLines() if Ops.greater_than(Builtins.size(new_lines), 0) @lines = Convert.convert( Builtins.merge(@lines, new_lines), :from => "list", :to => "list <string>" ) DeleteOldLines() UI.ChangeWidget( , :LastLine, Builtins.mergestring(Builtins.maplist(new_lines) do |line| Ops.add(line, "\n") end, "") ) end end nil end |