Class: Yast::GfxMenuClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/GfxMenu.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) main



22
23
24
25
26
27
28
29
30
31
# File '../../src/modules/GfxMenu.rb', line 22

def main

  textdomain "bootloader"

  Yast.import "Mode"

  # FATE#305403: Bootloader beep configuration
  # enable/disable sounds signal during boot
  @enable_sound_signals = false
end

- (Object) ReadStatusAcousticSignal

FATE#305403: Bootloader beep configuration Read status of acoustic signals set global variable enable_sound_signals



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
66
67
# File '../../src/modules/GfxMenu.rb', line 37

def ReadStatusAcousticSignal
  ret = -1 # off

  command = "gfxboot --show-config | grep beep="
  out = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))

  Builtins.y2milestone("Comand: %1 return: %2", command, out)
  if Ops.get_integer(out, "exit", -1) == 0
    result = Ops.get_string(out, "stdout", "")
    l_result = Builtins.splitstring(result, "\n")
    if Ops.get(l_result, 1, "") == "beep=1"
      ret = 1
    else
      ret = 0
    end
  else
    Builtins.y2error("Calling command: %1 failed", command)
  end
  if ret == 1
    @enable_sound_signals = true
  else
    @enable_sound_signals = false
  end

  Builtins.y2milestone(
    "Status of acoustic signals is (on==true/off==false): %1",
    @enable_sound_signals
  )

  nil
end

- (Boolean) Update

Updates GFX menu without requiring any information, reads loader type from sysconfig

Returns:

  • (Boolean)

    true on success



223
224
225
226
227
228
# File '../../src/modules/GfxMenu.rb', line 223

def Update
  loader = Convert.to_string(
    SCR.Read(path(".sysconfig.bootloader.LOADER_TYPE"))
  )
  return UpdateGfxMenuContents(loader)
end

- (Boolean) UpdateGfxMenuContents(loader)

Update graphical bootloader to contain translations for section labels in the currently selected installation language (set in /etc/sysconfig/language, RC_LANG) And make the selected installation language default

Parameters:

  • loader (String)

    string bootloader type

Returns:

  • (Boolean)

    true on success



95
96
97
98
99
100
101
102
103
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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File '../../src/modules/GfxMenu.rb', line 95

def UpdateGfxMenuContents(loader)
  Builtins.y2milestone("Updating GFX boot menu")

  # FATE#305403: Bootloader beep configuration
  WriteAcousticSignal(@enable_sound_signals)
  # if the boot menu does not exist, return without updating it
  return true if SCR.Read(path(".target.size"), "/boot/message") == -1
  if SCR.Read(path(".target.size"), "/etc/sysconfig/bootsplash") == -1
    return true
  end

  # get a list containing the system default language and the installed languages
  # get the current language
  main_lang = Convert.to_string(
    SCR.Read(path(".sysconfig.language.RC_LANG"))
  )
  langs = Convert.to_string(
    SCR.Read(path(".sysconfig.language.INSTALLED_LANGUAGES"))
  )
  langs = "" if langs == nil
  languages = Builtins.splitstring(langs, ",")
  languages = Builtins.prepend(languages, main_lang)
  languages = Builtins.filter(languages) { |l| l != nil }
  # if no languages are installed and no main language is defined, we can do
  # nothing: simply return
  return true if Builtins.size(languages) == 0

  # if no boot theme is defined, we cannot create the GfxMenu: just leave
  boot_theme = Convert.to_string(
    SCR.Read(path(".sysconfig.bootsplash.THEME"))
  )
  return true if boot_theme == nil


  # in the list of the system default language and the installed languages
  # find the subset that is supported by either a help text or a translation
  # file (for the GUI messages) or both
  # results:
  # selected    -- list of supported languages (both long form (de_DE) and short form (de))
  # lang_params -- string of supported languages (both long form (de_DE) and short form (de))

  # get names of available languages
  data_dir = Builtins.sformat(
    "/etc/bootsplash/themes/%1/bootloader",
    boot_theme
  )
  files = Convert.convert(
    SCR.Read(path(".target.dir"), data_dir),
    :from => "any",
    :to   => "list <string>"
  )
  helps = Builtins.filter(files) { |f| Builtins.regexpmatch(f, '\.hlp$') }
  texts = Builtins.filter(files) { |f| Builtins.regexpmatch(f, '\.tr$') }
  helps = Builtins.maplist(helps) { |h| Builtins.substring(h, 0, 2) }
  texts = Builtins.maplist(texts) { |t| Builtins.substring(t, 0, 2) }
  Builtins.y2milestone("Texts available for %1", Builtins.sort(texts))
  Builtins.y2milestone("Helps available for %1", Builtins.sort(helps))

  tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir")))
  lang_params = ""
  lang_supported = true

  selected = []
  Builtins.foreach(languages) do |lang|
    l = Builtins.splitstring(lang, ".")
    lang = Ops.get(l, 0, "")
    Builtins.y2milestone("Selected language for booting menu: %1", lang)
    l = Builtins.splitstring(lang, "_")
    lang_short = Ops.get(l, 0, "")
    # check if lang is supported by a help text and/or a GUI message
    # translation file
    if !(Builtins.contains(helps, lang_short) ||
        Builtins.contains(texts, lang_short))
      Builtins.y2milestone(
        "Language %1 is not supported by gfxmenu",
        lang_short
      )
      # rather avoid all translations; non-supported characters don't show
      # in the future, the menu should be translated into selected language,
      # not only into the system language
      lang_supported = false
    elsif !(Builtins.contains(selected, lang) ||
        Builtins.contains(selected, lang_short))
      lang_params = Builtins.sformat(
        "%1 %2 %3",
        lang_params,
        lang,
        lang_short
      )
      selected = Builtins.add(selected, lang)
      selected = Builtins.add(selected, lang_short)
    end
  end

  trans_file = tmpdir + "/boot_translations"
  # do not create translation of section (bnc#875819)
  trans_str = ""
  SCR.Write(path(".target.string"), trans_file, trans_str)
  lang_params = "en_EN en" if lang_params == ""

  # update the boot message (/boot/message cpio archive) with menu entry
  # translation file (trans_file) and translation files for help texts and
  # UI texts
  #  - currently (2006/09) update_gfxmenu includes the hlp and tr files only
  #    for the first language (e.g. "de_DE de") from lang_params, the others
  #    are ignored
  #  - tr and hlp files that match the long language name ("de_DE") are
  #    preferred over files that contain only the short language name
  #  - English ("en") is always included in the list of selectable
  #    languages, and the English tr and hlp files are never removed from
  #    the message archive
  command = Builtins.sformat(
    "/usr/lib/YaST2/bin/update_gfxmenu %1 %2 %3 %4",
    tmpdir,
    data_dir,
    trans_file,
    lang_params
  )

  Builtins.y2milestone("Running command %1", command)
  ret = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))
  Builtins.y2milestone("GFXMenu update result: %1", ret)
  Ops.get_integer(ret, "exit", 0) == 0
end

- (Object) WriteAcousticSignal(enable)

FATE#305403: Bootloader beep configuration Write settings for acoustic signals

Parameters:

  • boolean

    true -> enable acoustic signals or disable



74
75
76
77
78
79
80
81
82
83
84
85
86
# File '../../src/modules/GfxMenu.rb', line 74

def WriteAcousticSignal(enable)
  command = "gfxboot --change-config boot::beep=0"
  if enable
    Builtins.y2milestone("Enable acoustic signals for boot menu")
    command = "gfxboot --change-config boot::beep=1"
  else
    Builtins.y2milestone("Disable acoustic signals for boot menu")
  end
  ret = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))
  Builtins.y2milestone("Result of command: %1 result: %2", command, ret)

  nil
end