Class: Yast::MiscClass
- Inherits:
-
Module
- Object
- Module
- Yast::MiscClass
- Defined in:
- library/general/src/modules/Misc.rb
Instance Method Summary collapse
-
#CustomSysconfigRead(key, defval, location) ⇒ Object
Try to read value from sysconfig file and return the result if successful.
-
#hardware_name(hardware_entry) ⇒ String
common function to extract 'name' of hardware.
- #main ⇒ Object
-
#ReadAlternateFile(first, second) ⇒ Object
try to read first file, if it doesn't exist, read second files must reside below /usr/lib/YaST2 files must have ycp syntax.
-
#SplitOptions(options, optmap) ⇒ Hash
MergeOptions Merges "opt1=val1 opt2=val2 ..." and $["opta":"vala", ..."] to $["opt1":"val1", "opt2":"val2", "opta":"vala", ...] as needed by modules.conf agent.
-
#SysconfigRead(sysconfig_path, defaultv) ⇒ Object
SysconfigRead().
-
#SysconfigWrite(level, values) ⇒ Boolean
SysconfigWrite() write list of sysyconfig entries via rcconfig agent.
-
#translate(lmap, lang) ⇒ String
Define a macro that looks up a localized string in a language map of the form $[ "default" : "Defaultstring", "de" : "German....", ...].
Instance Method Details
#CustomSysconfigRead(key, defval, location) ⇒ Object
Try to read value from sysconfig file and return the result if successful. Function reads from arbitrary sysconfig file, for which the agent doesn't exist: e.g. from different partition like /mnt/etc/sysconfig/file.
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'library/general/src/modules/Misc.rb', line 200 def CustomSysconfigRead(key, defval, location) return defval if location == "" custom_path = Builtins.topath(location) SCR.RegisterAgent( custom_path, term(:ag_ini, term(:SysConfigFile, location)) ) ret = SysconfigRead(Builtins.add(custom_path, key), defval) SCR.UnregisterAgent(custom_path) ret end |
#hardware_name(hardware_entry) ⇒ String
common function to extract 'name' of hardware
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'library/general/src/modules/Misc.rb', line 64 def hardware_name(hardware_entry) hardware_entry = deep_copy(hardware_entry) sub_vendor = Ops.get_string(hardware_entry, "sub_vendor", "") sub_device = Ops.get_string(hardware_entry, "sub_device", "") return Ops.add(Ops.add(sub_vendor, "\n"), sub_device) if sub_vendor != "" && sub_device != "" vendor = Ops.get_string(hardware_entry, "vendor", "") Ops.add( Ops.add(vendor, (vendor != "") ? "\n" : ""), Ops.get_string(hardware_entry, "device", "") ) end |
#main ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'library/general/src/modules/Misc.rb', line 34 def main Yast.import "UI" Yast.import "Mode" # Message after finishing installation and before the system # boots for the first time. # @boot_msg = "" end |
#ReadAlternateFile(first, second) ⇒ Object
try to read first file, if it doesn't exist, read second files must reside below /usr/lib/YaST2 files must have ycp syntax
53 54 55 56 57 |
# File 'library/general/src/modules/Misc.rb', line 53 def ReadAlternateFile(first, second) result = SCR.Read(path(".target.yast2"), [first, nil]) result = SCR.Read(path(".target.yast2"), second) if result.nil? deep_copy(result) end |
#SplitOptions(options, optmap) ⇒ Hash
MergeOptions Merges "opt1=val1 opt2=val2 ..." and $["opta":"vala", ..."] to $["opt1":"val1", "opt2":"val2", "opta":"vala", ...] as needed by modules.conf agent
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'library/general/src/modules/Misc.rb', line 135 def SplitOptions(, optmap) optmap = deep_copy(optmap) # step 1: split "opt1=val1 opt2=val2 ..." # to ["opt1=val1", "opt2=val2", "..."] = Builtins.splitstring(, " ") Builtins.foreach() do || = Builtins.splitstring(, "=") if Builtins.size() == 1 && Ops.get_string(optmap, , "") == "" # single argument Ops.set(optmap, , "") elsif Builtins.size() == 2 # argument with value Ops.set( optmap, Ops.get_string(, 0, ""), Ops.get_string(, 1, "") ) end end deep_copy(optmap) end |
#SysconfigRead(sysconfig_path, defaultv) ⇒ Object
SysconfigRead()
Try an SCR::Read(...) and return the result if successful. On failure return the the second parameter (default value)
172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'library/general/src/modules/Misc.rb', line 172 def SysconfigRead(sysconfig_path, defaultv) local_ret = Convert.to_string(SCR.Read(sysconfig_path)) if local_ret.nil? Builtins.y2warning( "Failed reading '%1', using default value", sysconfig_path ) defaultv else Builtins.y2milestone("%1: '%2'", sysconfig_path, local_ret) local_ret end end |
#SysconfigWrite(level, values) ⇒ Boolean
SysconfigWrite() write list of sysyconfig entries via rcconfig agent
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'library/general/src/modules/Misc.rb', line 105 def SysconfigWrite(level, values) values = deep_copy(values) result = true level = if level == path(".") path(".sysconfig") else Ops.add(path(".sysconfig"), level) end Builtins.foreach(values) do |entry| if Builtins.size(entry) != 2 Builtins.y2error("bad entry in rc_write()") elsif !SCR.Write( Ops.add(level, Ops.get_path(entry, 0, path("."))), Ops.get_string(entry, 1, "") ) result = false end end result end |
#translate(lmap, lang) ⇒ String
Define a macro that looks up a localized string in a language map of the form $[ "default" : "Defaultstring", "de" : "German....", ...]
88 89 90 91 92 93 94 95 |
# File 'library/general/src/modules/Misc.rb', line 88 def translate(lmap, lang) lmap = deep_copy(lmap) t = Ops.get_string(lmap, lang, "") t = Ops.get_string(lmap, Builtins.substring(lang, 0, 2), "") if Builtins.size(t) == 0 && Ops.greater_than(Builtins.size(lang), 2) t = Ops.get_string(lmap, "default", "") if Builtins.size(t) == 0 t end |