Class: Yast::JoystickClass
- Inherits:
-
Module
- Object
- Module
- Yast::JoystickClass
- Defined in:
- ../../src/modules/Joystick.rb
Instance Method Summary (collapse)
-
- (Object) Changed
Return configuration status.
- - (Object) Detect
- - (Object) Detected
-
- (Object) Export
Dump the joystick settings to a single map (For use by autoinstallation.).
- - (Object) format_model_line(model, attached_to)
-
- (Object) Import(settings)
Get all joystick settings from the first parameter (For use by autoinstallation.).
- - (Object) main
- - (Object) parse_model_line(line)
-
- (Object) Read(abort)
Read all joystick settings from the SCR.
-
- (Array) RequiredKernelModules
Get list of all required joystick kernel modules.
-
- (Object) Revert
Reverts the internal joystick configuration to the original state read by Read() function.
-
- (Object) SaveOneJoystick(pos)
Update the SCR of the one joystick.
-
- (Object) StartAndEnable
Start joystick service and insserv it.
-
- (Object) Stop
Stop joystick service.
-
- (Object) Summary
Build a textual summary that can be used e.g.
-
- (Object) Write(abort)
Update the SCR according to joystick settings.
-
- (Object) WriteConfig
Write sysconfig values (flush).
Instance Method Details
- (Object) Changed
Return configuration status
262 263 264 |
# File '../../src/modules/Joystick.rb', line 262 def Changed @joystick != @joystick_backup end |
- (Object) Detect
51 52 53 54 55 56 57 58 59 |
# File '../../src/modules/Joystick.rb', line 51 def Detect @detected_joysticks = Convert.convert( SCR.Read(path(".probe.joystick")), :from => "any", :to => "list <map>" ) nil end |
- (Object) Detected
47 48 49 |
# File '../../src/modules/Joystick.rb', line 47 def Detected deep_copy(@detected_joysticks) end |
- (Object) Export
Dump the joystick settings to a single map (For use by autoinstallation.)
409 410 411 |
# File '../../src/modules/Joystick.rb', line 409 def Export deep_copy(@joystick) end |
- (Object) format_model_line(model, attached_to)
96 97 98 |
# File '../../src/modules/Joystick.rb', line 96 def format_model_line(model, attached_to) Builtins.sformat("# Model: %1, Attached to: %2\n", model, attached_to) end |
- (Object) Import(settings)
Get all joystick settings from the first parameter (For use by autoinstallation.)
400 401 402 403 404 |
# File '../../src/modules/Joystick.rb', line 400 def Import(settings) settings = deep_copy(settings) @joystick = deep_copy(settings) true end |
- (Object) main
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File '../../src/modules/Joystick.rb', line 11 def main textdomain "sound" Yast.import "Mode" Yast.import "Service" Yast.import "Directory" @joy_cmd = Ops.add(Directory.bindir, "/joystickdrivers") # joystick config datastructure (list of maps) @joystick = [] @vars = [ "GAMEPORT_MODULE", "JOYSTICK_MODULE", "JOYSTICK_MODULE_OPTION", "JOYSTICK_CONTROL", "JOYSTICK_CONTROL_PORT" ] @joystick_backup = [] @start = "" @modified = false # comment for JOYSTICK_MODULE section in sysconfig @module_comment = "" @generic_joystick = "Generic Analog Joystick" # database entry @generic_joystick_translated = _("Generic Analog Joystick") @detected_joysticks = [] end |
- (Object) parse_model_line(line)
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File '../../src/modules/Joystick.rb', line 100 def parse_model_line(line) regexp = "^#[ \t]*Model: (.*),[ \t]*Attached to:[ \t]*(.*)$" model = Builtins.regexpsub(line, regexp, "\\1") attached_to = Builtins.regexpsub(line, regexp, "\\2") model = "" if model == nil attached_to = "" if attached_to == nil Builtins.y2milestone( "Parsed model line: %1 -> model: %2, attached_to: %3", line, model, attached_to ) [model, attached_to] end |
- (Object) Read(abort)
Read all joystick settings from the SCR
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File '../../src/modules/Joystick.rb', line 124 def Read(abort) abort = deep_copy(abort) # values for test mode if Mode.test == true @joystick = [ { "GAMEPORT_MODULE" => "ns558", "JOYSTICK_CONTROL" => "Joystick", "JOYSTICK_CONTROL_PORT" => "", "JOYSTICK_MODULE" => "analog", "JOYSTICK_MODULE_OPTION" => "", "model" => "Generic Analog Joystick" }, { "GAMEPORT_MODULE" => "", "JOYSTICK_CONTROL" => "", "JOYSTICK_CONTROL_PORT" => "", "JOYSTICK_MODULE" => "", "JOYSTICK_MODULE_OPTION" => "", "model" => "" }, { "GAMEPORT_MODULE" => "", "JOYSTICK_CONTROL" => "", "JOYSTICK_CONTROL_PORT" => "", "JOYSTICK_MODULE" => "", "JOYSTICK_MODULE_OPTION" => "", "model" => "" }, { "GAMEPORT_MODULE" => "", "JOYSTICK_CONTROL" => "", "JOYSTICK_CONTROL_PORT" => "", "JOYSTICK_MODULE" => "", "JOYSTICK_MODULE_OPTION" => "", "model" => "" } ] @joystick_backup = deep_copy(@joystick) return true end pos = 0 @joystick = [] while Ops.less_than(pos, 4) j = {} # go thru 'vars' list and read all variable values Builtins.foreach(@vars) do |v| tmp = Convert.to_string( SCR.Read( Builtins.topath( Builtins.sformat(".sysconfig.joystick.%1_%2", v, pos) ) ) ) j = Builtins.add(j, v, tmp) if tmp != nil end # read model comment model = Convert.to_string( SCR.Read( Builtins.topath( Builtins.sformat( ".sysconfig.joystick.JOYSTICK_MODULE_%1.comment", pos ) ) ) ) attached_to = "" Builtins.y2debug("Read model comment: %1", model) # remove trailing newline character if Ops.greater_than(Builtins.size(model), 0) && Builtins.substring(model, Ops.subtract(Builtins.size(model), 1), 1) == "\n" model = Builtins.substring( model, 0, Ops.subtract(Builtins.size(model), 1) ) end # if comment has more lines get last line as model name lines = Builtins.splitstring(model, "\n") # select last line from comment if Ops.greater_than(Builtins.size(lines), 1) model = Ops.get(lines, Ops.subtract(Builtins.size(lines), 1), "") # store global comment for joystick modules - # - it is before first module if pos == 0 lines = Builtins.remove( lines, Ops.subtract(Builtins.size(lines), 1) ) @module_comment = Builtins.mergestring(lines, "\n") Builtins.y2debug("global comment: %1", @module_comment) end end # set model if SCR.Read( Builtins.topath( Builtins.sformat(".sysconfig.joystick.JOYSTICK_MODULE_%1", pos) ) ) == "" || model == nil model = "" else info = parse_model_line(model) model = Ops.get(info, 0, "") attached_to = Ops.get(info, 1, "") end Ops.set(j, "model", model) Ops.set(j, "attached_to", attached_to) @joystick = Builtins.add(@joystick, j) pos = Ops.add(pos, 1) end @joystick_backup = deep_copy(@joystick) Detect() true end |
- (Array) RequiredKernelModules
Get list of all required joystick kernel modules
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File '../../src/modules/Joystick.rb', line 75 def RequiredKernelModules ret = [] Builtins.foreach( Convert.convert(@joystick, :from => "list", :to => "list <map>") ) do |j| gport = Ops.get_string(j, "GAMEPORT_MODULE", "") jmod = Ops.get_string(j, "JOYSTICK_MODULE", "") ret = Builtins.add(ret, gport) if gport != nil && gport != "" ret = Builtins.add(ret, jmod) if jmod != nil && jmod != "" end # remove duplicates ret = Builtins.toset(ret) Builtins.y2milestone("Required joystick modules: %1", ret) deep_copy(ret) end |
- (Object) Revert
Reverts the internal joystick configuration to the original state read by Read() function
63 64 65 66 67 68 69 70 71 |
# File '../../src/modules/Joystick.rb', line 63 def Revert Builtins.y2milestone( "Reverting the joystick config back to: %1", @joystick_backup ) @joystick = deep_copy(@joystick_backup) nil end |
- (Object) SaveOneJoystick(pos)
Update the SCR of the one joystick
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File '../../src/modules/Joystick.rb', line 268 def SaveOneJoystick(pos) # first remove old settings Builtins.foreach(@vars) do |v| SCR.Write( Builtins.topath(Builtins.sformat(".sysconfig.joystick.%1_%2", v, pos)), "" ) end # delete old model SCR.Write( Builtins.topath( Builtins.sformat( ".sysconfig.joystick.JOYSTICK_MODULE_%1.comment", pos ) ), "" ) j = Ops.get_map(@joystick, pos, {}) Builtins.foreach(@vars) do |v| SCR.Write( Builtins.topath(Builtins.sformat(".sysconfig.joystick.%1_%2", v, pos)), Ops.get_string(j, v, "") ) if Ops.get_string(j, v, "") != "" # if there is variable with value != "" enable joystick service @start = "enable" end end # write model comment model = Ops.get_string(j, "model", "") attached_to = Ops.get_string(j, "attached_to", "") # add comment before first model if pos == 0 if Ops.greater_than(Builtins.size(model), 0) model = Ops.add( Ops.add(@module_comment, "\n"), format_model_line(model, attached_to) ) else model = Ops.add(@module_comment, "\n#\n") end else if Ops.greater_than(Builtins.size(model), 0) model = format_model_line(model, attached_to) end end Builtins.y2debug("Read model comment: %1", model) if Ops.greater_than(Builtins.size(model), 0) SCR.Write( Builtins.topath( Builtins.sformat( ".sysconfig.joystick.JOYSTICK_MODULE_%1.comment", pos ) ), model ) end true end |
- (Object) StartAndEnable
Start joystick service and insserv it
350 351 352 353 354 355 356 357 358 359 |
# File '../../src/modules/Joystick.rb', line 350 def StartAndEnable if @start == "enable" cmd = Ops.add(@joy_cmd, " load") Builtins.y2milestone("Executing: %1", cmd) SCR.Execute(path(".target.bash"), cmd) end Service.Adjust("joystick", @start) true end |
- (Object) Stop
Stop joystick service
338 339 340 341 342 |
# File '../../src/modules/Joystick.rb', line 338 def Stop cmd = Ops.add(@joy_cmd, " unload") Builtins.y2milestone("Executing: %1", cmd) SCR.Execute(path(".target.bash"), cmd) == 0 end |
- (Object) Summary
Build a textual summary that can be used e.g. in inst_hw_config () or something similar.
416 417 418 |
# File '../../src/modules/Joystick.rb', line 416 def Summary _("Summary of the joystick configuration...") end |
- (Object) Write(abort)
Update the SCR according to joystick settings
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File '../../src/modules/Joystick.rb', line 366 def Write(abort) abort = deep_copy(abort) # do not write anything in the test mode and if nothing was changed return true if Mode.test == true || !@modified pos = 0 @start = "disable" # stop joystick service Stop() while Ops.less_than(pos, 4) # update /etc/sysconfig/joystick file SaveOneJoystick(pos) pos = Ops.add(pos, 1) end # flush config to file WriteConfig() # start joystick service # enable/disable service StartAndEnable() Builtins.y2milestone("%1", "Joystick configuration was written.") true end |
- (Object) WriteConfig
Write sysconfig values (flush)
345 346 347 |
# File '../../src/modules/Joystick.rb', line 345 def WriteConfig SCR.Write(path(".sysconfig.joystick"), nil) end |