Module: Yast::AutoinstallDialogsInclude

Defined in:
../../src/include/autoinstall/dialogs.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) checkFileName(name)

Check validity of file name

Parameters:

  • string

    file name

Returns:

  • 0 if valid, -1 if not.



135
136
137
138
139
140
141
142
143
144
145
146
# File '../../src/include/autoinstall/dialogs.rb', line 135

def checkFileName(name)
  if name !=
      Builtins.filterchars(
        name,
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"
      ) ||
      Ops.greater_than(Builtins.size(name), 127)
    return -1
  end

  0
end

- (Symbol) cloneSystem

Clone running system

Returns:

  • (Symbol)


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
# File '../../src/include/autoinstall/dialogs.rb', line 211

def cloneSystem
  Yast.import "AutoinstClone"
  Yast.import "Profile"


  Wizard.CreateDialog
  Wizard.SetDesktopIcon("groups")


  # title
  title = _("Create a Reference Control File")
  items = AutoinstClone.createClonableList
  contents = VBox(
    MultiSelectionBox(Id(:res), _("Select Additional Resources:"), items)
  )

  Wizard.SetContents(
    title,
    contents,
    Ops.get_string(@HELPS, "clone", ""),
    true,
    true
  )
  Wizard.HideAbortButton
  Wizard.SetNextButton(:next, Label.CreateButton)

  ret = :none
  begin
    ret = Convert.to_symbol(UI.UserInput)
    if ret == :next
      AutoinstClone.additional = Convert.convert(
        UI.QueryWidget(Id(:res), :SelectedItems),
        :from => "any",
        :to   => "list <string>"
      )
      Popup.ShowFeedback(
        _("Collecting system data..."),
        _("This may take a while...")
      )
      AutoinstClone.Process
      Profile.changed = true
      Popup.ClearFeedback
    end
  end until ret == :next || ret == :back
  Wizard.CloseDialog
  ret
end

- (Object) initialize_autoinstall_dialogs(include_target)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File '../../src/include/autoinstall/dialogs.rb', line 10

def initialize_autoinstall_dialogs(include_target)
  Yast.import "UI"
  textdomain "autoinst"

  Yast.import "Label"
  Yast.import "Popup"
  Yast.import "Profile"
  Yast.import "Directory"
  Yast.import "Y2ModuleConfig"
  Yast.import "Wizard"
  Yast.import "AutoinstConfig"
  Yast.import "AutoinstClass"
  Yast.import "PackageSystem"
  Yast.include include_target, "autoinstall/helps.rb"
end

- (Object) invalidFileName

Return a message about invalid file names

Parameters:

  • -

Returns:

  • message



152
153
154
155
156
157
158
159
# File '../../src/include/autoinstall/dialogs.rb', line 152

def invalidFileName
  _(
    "Invalid file name.\n" +
      "Names can only contain letters, numbers, and underscore,\n" +
      "must begin with letter, and must be\n" +
      "127 characters long or less.\n"
  )
end

- (Object) kickstartDialog



261
262
263
264
265
266
267
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File '../../src/include/autoinstall/dialogs.rb', line 261

def kickstartDialog
  Yast.import "Progress"
  Yast.import "Kickstart"
  Yast.import "Report"


  caption = _("Importing Kickstart file...")
  Builtins.y2debug("Importing Kickstart data")
  Wizard.CreateDialog
  contents = Label(_("Initializing ..."))
  Wizard.SetContents(
    caption,
    contents,
    Ops.get_string(@HELPS, "kickstart", ""),
    false,
    false
  )
  steps = 2
  sl = 500

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    "",
    steps,
    [
      # progress stage
      _("Read Kickstart file"),
      _("Import data")
    ],
    [
      _("Reading Kickstart file..."),
      # progress step
      _("Importing data..."),
      # progress step
      _("Finished")
    ],
    ""
  )


  Progress.NextStage
  filename = nil
  filename = UI.AskForExistingFile(
    AutoinstConfig.Repository,
    "*",
    _("Select a kickstart file.")
  )
  if filename == nil || filename == ""
    Wizard.CloseDialog
    return :abort
  end

  Kickstart.ksfile = Convert.to_string(filename)
  Kickstart.Read

  Progress.NextStage
  ksay = Kickstart.KS2AY
  Progress.Finish


  if ksay == {}
    Report.Error(
      _(
        "Error while loading Kickstart file. Verify the syntax of\nfile and try again."
      )
    )
  else
    Profile.Import(ksay)

    Popup.ShowFeedback(
      _("Reading configuration data"),
      _("This may take a while")
    )
    Builtins.foreach(Profile.ModuleMap) do |p, d|
      # Set resource name, if not using default value
      resource = Ops.get_string(d, "X-SuSE-YaST-AutoInstResource", "")
      resource = p if resource == ""
      Builtins.y2debug("resource: %1", resource)
      tomerge = Ops.get_string(d, "X-SuSE-YaST-AutoInstMerge", "")
      module_auto = Ops.get_string(d, "X-SuSE-YaST-AutoInstClient", "none")
      rd = Y2ModuleConfig.getResourceData(d, resource)
      WFM.CallFunction(module_auto, ["Import", rd]) if rd != nil
    end
    Popup.ClearFeedback

    Report.Message(
      _(
        "Kickstart file was imported.\n" +
          "Check the imported syntax and make sure the package selection and partitioning\n" +
          "were imported correctly."
      )
    )
  end
  Wizard.CloseDialog
  :next
end

- (String) NewFileName(caption, textentry)

Popup for a new file name

Parameters:

  • caption (String)
  • textentry (String)

Returns:

  • (String)

    new file name



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
# File '../../src/include/autoinstall/dialogs.rb', line 166

def NewFileName(caption, textentry)
  con = HBox(
    HSpacing(1),
    VBox(
      VSpacing(0.2),
      # Translators: popup dialog heading
      Heading(caption),
      #  _("&New Profile Name") _("New Profile")
      # Translators: text entry label
      Left(TextEntry(Id(:newname), textentry, "")),
      VSpacing(0.2),
      ButtonBox(
        PushButton(Id(:ok), Opt(:default), Label.OKButton),
        PushButton(Id(:cancel), Label.CancelButton)
      ),
      VSpacing(0.2)
    ),
    HSpacing(1)
  )

  UI.OpenDialog(Opt(:decorated), con)
  UI.SetFocus(Id(:newname))
  f = ""
  ret = nil
  while true
    ret = UI.UserInput
    if ret == :cancel
      break
    elsif ret == :ok
      f = Convert.to_string(UI.QueryWidget(Id(:newname), :Value))
      if checkFileName(f) != 0 || f == ""
        Popup.Error(invalidFileName)
        next
      end
      break
    end
  end

  UI.CloseDialog

  ret == :ok ? f : ""
end

- (Symbol) Settings

Preferences Dialog

Returns:

  • (Symbol)


28
29
30
31
32
33
34
35
36
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
68
69
70
71
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
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
# File '../../src/include/autoinstall/dialogs.rb', line 28

def Settings
  Wizard.CreateDialog
  Wizard.SetDesktopIcon("autoyast")
  contents = HVSquash(
    VBox(
      VSquash(
        HBox(
          TextEntry(
            Id(:repository),
            _("&Profile Repository:"),
            AutoinstConfig.Repository
          ),
          VBox(
            VSpacing(),
            Bottom(PushButton(Id(:opendir), _("&Select Directory")))
          )
        )
      ),
      VSquash(
        HBox(
          TextEntry(
            Id(:classdir),
            _("&Class directory:"),
            AutoinstConfig.classDir
          ),
          VBox(
            VSpacing(),
            Bottom(PushButton(Id(:openclassdir), _("Select &Directory")))
          )
        )
      )
    )
  )


  help = _(
    "<P>\n" +
      "Enter the directory where all <em>control files</em> should be stored in\n" +
      "the <b>Repository</b> field.</P>"
  )

  help = Ops.add(
    help,
    _(
      "<P>If you are using the classes feature\n" +
        "of Autoyast, also enter the class directory. This is where\n" +
        "all class files are stored.</p>\n"
    )
  )

  Wizard.SetContents(_("Settings"), contents, help, true, true)

  Wizard.HideAbortButton
  Wizard.RestoreNextButton

  changed = false
  ret = :none
  begin
    ret = Convert.to_symbol(UI.UserInput)

    new_rep = Convert.to_string(UI.QueryWidget(Id(:repository), :Value))
    new_classdir = Convert.to_string(UI.QueryWidget(Id(:classdir), :Value))

    if ret == :opendir
      new_rep = UI.AskForExistingDirectory(
        AutoinstConfig.Repository,
        _("Select Directory")
      )
      UI.ChangeWidget(Id(:repository), :Value, new_rep) if new_rep != ""
      next
    elsif ret == :openclassdir
      new_classdir = UI.AskForExistingDirectory(
        AutoinstConfig.classDir,
        _("Select Directory")
      )
      if new_classdir != ""
        UI.ChangeWidget(Id(:classdir), :Value, new_classdir)
      end
      next
    elsif ret == :next
      if AutoinstConfig.Repository != new_rep
        changed = true
        AutoinstConfig.Repository = new_rep
      end
      if AutoinstConfig.classDir != new_classdir
        changed = true
        #AutoinstConfig::classDir = new_classdir;
        AutoinstClass.classDirChanged(new_classdir)
      end
    end
  end until ret == :back || ret == :next

  Wizard.RestoreScreenShotName
  if changed
    AutoinstConfig.Save
    changed = false
  end
  Wizard.CloseDialog
  ret
end

- (Object) UpdateValidDialog(summary, log)



360
361
362
363
364
365
# File '../../src/include/autoinstall/dialogs.rb', line 360

def UpdateValidDialog(summary, log)
  UI.ChangeWidget(Id(:richtext), :Value, summary)
  UI.ChangeWidget(Id(:log), :LastLine, log)

  nil
end

- (Symbol) ValidDialog

Validate Dialog

Returns:

  • (Symbol)


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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File '../../src/include/autoinstall/dialogs.rb', line 369

def ValidDialog
  Yast.import "Summary"
  Yast.import "HTML"
  Wizard.CreateDialog
  contents = VBox(
    RichText(Id(:richtext), Opt(:autoScrollDown), ""),
    LogView(Id(:log), "", 5, 100)
  )
  Wizard.SetContents(
    _("Check profile validity"),
    contents,
    Ops.get_string(@HELPS, "valid", ""),
    true,
    true
  )
  Builtins.y2milestone("Checking validity")
  Wizard.HideAbortButton
  Wizard.HideBackButton
  UI.ChangeWidget(Id(:next), :Label, Label.FinishButton)



  sectionFiles = Profile.SaveSingleSections(AutoinstConfig.tmpDir)
  Builtins.y2debug("Got section map: %1", sectionFiles)

  html_ok = HTML.Colorize(_("OK"), "green")
  html_ko = HTML.Colorize(_("Error"), "red")
  html_warn = HTML.Colorize(_("Warning"), "yellow")
  summary = ""

  # some of these can be commented out for the release
  validators = [
    #     [
    # 	_("Checking XML without validation..."),
    # 	"/usr/bin/xmllint --noout",
    # 	],
    # 	    [
    # 		_("Checking XML with DTD validation..."),
    # 		"/usr/bin/xmllint --noout --valid"
    # 		],
    [
      _("Checking XML with RNG validation..."),
      Ops.add(
        Ops.add(
          "/usr/bin/xmllint --noout --relaxng ",
          # was: /usr/share/autoinstall/rng/profile.rng
          Directory.schemadir
        ),
        "/autoyast/rng/profile.rng"
      )
    ]
  ]

  # section wise validation
  Builtins.foreach(validators) do |i|
    header = Ops.get_string(i, 0, "")
    summary = Summary.AddHeader(summary, header)
    UpdateValidDialog(summary, "")
    summary = Summary.OpenList(summary)
    Builtins.foreach(sectionFiles) do |section, sectionFile|
      cmd = Ops.add(Ops.add(Ops.get_string(i, 1, ""), " "), sectionFile)
      summary = Ops.add(
        Ops.add(summary, "<li>"),
        Builtins.sformat(_("Section %1: "), section)
      )
      UpdateValidDialog(summary, Ops.add(Ops.add("\n", cmd), "\n"))
      o = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
      Builtins.y2debug("validation output: %1", o)
      summary = Ops.add(
        summary,
        Ops.get_integer(o, "exit", 1) != 0 ||
          Ops.get_string(i, 2, "") == "jing sucks" &&
            Ops.greater_than(
              Builtins.size(Ops.get_string(o, "stderr", "")),
              0
            ) ? html_ko : html_ok
      )
      UpdateValidDialog(summary, Ops.get_string(o, "stderr", ""))
    end
    summary = Summary.CloseList(summary)
  end

  # jing validation -- validates complete xml profile
  if PackageSystem.Installed("jing")
    complete_xml_file = Ops.add(
      Ops.add(AutoinstConfig.tmpDir, "/"),
      "valid.xml"
    )
    Profile.Save(complete_xml_file)
    validator = [
      _("Checking XML with RNC validation..."),
      Ops.add(
        Ops.add("/usr/bin/jing >&2 -c ", Directory.schemadir),
        "/autoyast/rnc/profile.rnc"
      ),
      "jing sucks"
    ]
    header = Ops.get_string(validator, 0, "")
    summary = Summary.AddHeader(summary, header)
    UpdateValidDialog(summary, "")
    cmd = Ops.add(
      Ops.add(Ops.get_string(validator, 1, ""), " "),
      complete_xml_file
    )
    UpdateValidDialog(summary, Ops.add(Ops.add("\n", cmd), "\n"))
    o = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
    Builtins.y2debug("validation output: %1", o)
    summary = Ops.add(
      summary,
      Ops.get_integer(o, "exit", 1) != 0 ||
        Ops.greater_than(Builtins.size(Ops.get_string(o, "stderr", "")), 0) ? html_ko : html_ok
    )
    UpdateValidDialog(summary, Ops.get_string(o, "stderr", ""))
  end

  logicOk = true
  rootOk = false
  if Builtins.haskey(Profile.current, "users")
    Builtins.foreach(Ops.get_list(Profile.current, "users", [])) do |u|
      if Ops.get_string(u, "username", "") == "root" &&
          Builtins.haskey(u, "user_password")
        rootOk = true
      end
    end
  end
  # the autoyast interface can check if the profile is logical or if important stuff is missing
  # the missing stuff is under the Label "Logic"
  summary = Summary.AddHeader(summary, _("Logic"))
  if !rootOk
    # the autoyast config frontend can check if a root password is configured
    # and can warn the user if it is missing
    summary = Ops.add(
      Ops.add(Ops.add(summary, html_warn), " "),
      _("No root password configured")
    )
    logicOk = false
  end

  summary = Ops.add(summary, html_ok) if logicOk
  UpdateValidDialog(summary, "")

  ret = nil
  while true
    ret = UI.UserInput
    if ret == :next || ret == :back
      break
    elsif ret == :abort
      break
    end
  end

  Wizard.CloseDialog
  Convert.to_symbol(ret)
end