Class: Yast::CrashClass

Inherits:
Module
  • Object
show all
Defined in:
library/general/src/modules/Crash.rb

Instance Method Summary collapse

Instance Method Details

#AskRun(operation, question) ⇒ Boolean

Check whether operation was last run in moment of last fail. Return whether operation shall be run If not, return true (no reason to think that operation is unsafe), Otherwise ask user

Parameters:

  • operation (String)

    name

  • question (String)

    string question to ask when was unsuccessfull last time

Returns:

  • (Boolean)

    true if operation shall be started



145
146
147
148
149
150
# File 'library/general/src/modules/Crash.rb', line 145

def AskRun(operation, question)
  ret = true
  Read()
  ret = Popup.YesNo(question) if FailedLast(operation)
  ret
end

#Failed(operation) ⇒ Boolean

Check whether operation failed

Parameters:

  • operation (String)

    to check

Returns:

  • (Boolean)

    true if yes



118
119
120
121
# File 'library/general/src/modules/Crash.rb', line 118

def Failed(operation)
  Read()
  Builtins.contains(@all_failed, operation)
end

#FailedLast(operation) ⇒ Boolean

Check whether operation was last started when failed

Parameters:

  • operation (String)

    to check

Returns:

  • (Boolean)

    true if yes



126
127
128
129
# File 'library/general/src/modules/Crash.rb', line 126

def FailedLast(operation)
  Read()
  Builtins.contains(@last_failed, operation)
end

#Finish(operation) ⇒ Object

Finish operation

Parameters:

  • operation (String)

    to finish



103
104
105
106
107
108
109
110
111
112
113
# File 'library/general/src/modules/Crash.rb', line 103

def Finish(operation)
  Read()
  @all_failed = Builtins.filter(@all_failed) { |f| f != operation }
  @this_run_active = Builtins.filter(@this_run_active) { |f| f != operation }
  @last_failed = Builtins.filter(@last_failed) { |f| f != operation }
  @last_failed = Builtins.add(@last_failed, Ops.get(@this_run_active, 0)) if Ops.greater_than(Builtins.size(@this_run_active), 0)
  @last_done = operation
  Write()

  nil
end

#LastFinishedString

Get last finished operation

Returns:



133
134
135
136
# File 'library/general/src/modules/Crash.rb', line 133

def LastFinished
  Read()
  @last_done
end

#mainObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'library/general/src/modules/Crash.rb', line 33

def main
  Yast.import "Popup"

  # All operations that failed when were running last time
  @all_failed = []

  # All operations that were the last started when crashed
  # when running last time
  @last_failed = []

  # Last successfully finished operation
  @last_done = nil

  # List of operations which are active during this YaST2 session
  @this_run_active = []

  # Filename of file storing crash settings
  @filename = "/var/lib/YaST2/crash"
end

#ReadObject

Read settings from data file to variables



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'library/general/src/modules/Crash.rb', line 54

def Read
  if SCR.Read(path(".target.size"), @filename) != -1
    settings = Convert.convert(
      SCR.Read(path(".target.ycp"), @filename),
      from: "any",
      to:   "map <string, any>"
    )
    Builtins.y2milestone("Read settings: %1", settings)
    @all_failed = Ops.get_list(settings, "all_failed", [])
    @last_failed = Ops.get_list(settings, "last_failed", [])
    @last_done = Ops.get_string(settings, "last_done")
  end

  nil
end

#Run(operation) ⇒ Object

Start operation

Parameters:

  • operation (String)

    to start



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'library/general/src/modules/Crash.rb', line 86

def Run(operation)
  Read()
  @all_failed = Builtins.add(@all_failed, operation) if !Builtins.contains(@all_failed, operation)
  if Ops.greater_than(Builtins.size(@this_run_active), 0)
    @last_failed = Builtins.filter(@last_failed) do |f|
      f != Ops.get(@this_run_active, 0)
    end
  end
  @this_run_active = Builtins.prepend(@this_run_active, operation)
  @last_failed = Builtins.add(@last_failed, operation) if !Builtins.contains(@last_failed, operation)
  Write()

  nil
end

#WriteObject

Write data stored in variables to data files



71
72
73
74
75
76
77
78
79
80
81
82
# File 'library/general/src/modules/Crash.rb', line 71

def Write
  settings = {
    "all_failed"  => @all_failed,
    "last_failed" => @last_failed,
    "last_done"   => @last_done
  }
  SCR.Write(path(".target.ycp"), @filename, settings)
  Builtins.y2milestone("Written settings: %1", settings)
  SCR.Execute(path(".target.bash"), "/bin/sync")

  nil
end