Class: Yast::DebugHooksClass

Inherits:
Module
  • Object
show all
Defined in:
library/control/src/modules/DebugHooks.rb

Instance Method Summary collapse

Instance Method Details

#Checkpoint(filename, at_entry) ⇒ void

This method returns an undefined value.

called whenever an inst_*.ycp file is called during installation. checks if /tmp/<filename> exists and pops up a “Entry: <filename>” or “Exit: <filename>” box

Parameters:

  • filename (String)

    name of .ycp file

  • at_entry (Boolean)

    true before call of file == false after call of file



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

def Checkpoint(filename, at_entry)
  if Ops.greater_or_equal(
    WFM.Read(path(".local.size"), Ops.add("/tmp/", filename)),
    0
  )
    if at_entry
      Popup.Message(Builtins.sformat("Entry: %1", filename))
    else
      Popup.Message(Builtins.sformat("Exit: %1", filename))
    end
  end
  nil
end

#ExecuteScript(script, type) ⇒ Object

Execute Script

Parameters:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'library/control/src/modules/DebugHooks.rb', line 72

def ExecuteScript(script, type)
  Builtins.y2milestone("Executing script: %1", script)
  # string message =  sformat(_("Executing user supplied script: %1"), scriptName);
  executionString = ""
  scriptPath = Builtins.sformat("%1/%2", @tmp_dir, script)
  if type == "shell"
    executionString = Builtins.sformat(
      "/bin/sh -x %1 2&> %2/%3.log",
      scriptPath,
      @log_dir,
      script
    )
    WFM.Execute(path(".local.bash"), executionString)
  elsif type == "perl"
    executionString = Builtins.sformat(
      "/usr/bin/perl %1 2&> %2/%3.log",
      scriptPath,
      @log_dir,
      script
    )
    WFM.Execute(path(".local.bash"), executionString)
  else
    Builtins.y2error("Unknown interpreter: %1", type)
  end
  Builtins.y2milestone("Script Execution command: %1", executionString)

  nil
end

#mainObject



34
35
36
37
38
39
40
41
42
43
44
# File 'library/control/src/modules/DebugHooks.rb', line 34

def main
  Yast.import "Popup"
  Yast.import "Directory"

  @tmp_dir = Convert.to_string(WFM.Read(path(".local.tmpdir"), []))
  @log_dir = Directory.logdir

  # script types, ycp does not make  sense, it can be added directly
  # to the workflow.
  @supported_types = ["sh", "pl"]
end

#Run(filename, at_entry) ⇒ Object

Run Script

Parameters:

  • filename (String)

    name of .ycp file

  • at_entry (Boolean)

    true before call of file == false after call of file



104
105
106
107
108
109
110
111
112
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
# File 'library/control/src/modules/DebugHooks.rb', line 104

def Run(filename, at_entry)
  Builtins.y2debug("Running debug hook: %1", filename)
  # do not run scripts twice
  if at_entry
    if Ops.greater_than(
      WFM.Read(
        path(".local.size"),
        Builtins.sformat("%1/%2_pre.sh", @tmp_dir, filename)
      ),
      0
    )
      ExecuteScript(Builtins.sformat("%1_pre.sh", filename), "shell")
    elsif Ops.greater_than(
      WFM.Read(
        path(".local.size"),
        Builtins.sformat("%1/%2_pre.pl", @tmp_dir, filename)
      ),
      0
    )
      ExecuteScript(Builtins.sformat("%1_pre.pl", filename), "perl")
    else
      Builtins.y2debug(
        "Debug hook not found: %1/%2_pre.{sh,pl}",
        @tmp_dir,
        filename
      )
    end
  elsif Ops.greater_than(
    WFM.Read(
      path(".local.size"),
      Builtins.sformat("%1/%2_post.sh", @tmp_dir, filename)
    ),
    0
  )
    ExecuteScript(Builtins.sformat("%1_post.sh", filename), "shell")
  elsif Ops.greater_than(
    WFM.Read(
      path(".local.size"),
      Builtins.sformat("%1/%2_post.pl", @tmp_dir, filename)
    ),
    0
  )
    ExecuteScript(Builtins.sformat("%1_post.pl", filename), "perl")
  else
    Builtins.y2debug(
      "Debug hook not found: %1/%2_post.{sh,pl}",
      @tmp_dir,
      filename
    )
  end
  nil
end