Class: Yast::SourceManagerSLPClass

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

Overview

This module provides a complete set of functions that allows you to search and select a new SLP repository.

Instance Method Summary collapse

Instance Method Details

#AddSourceTypeSLPSymbol

Function scans for SLP installation servers on the network


579
580
581
582
583
584
# File 'src/modules/SourceManagerSLP.rb', line 579

def AddSourceTypeSLP
  url = SelectOneSLPService()
  Builtins.y2milestone("Selected URL: %1", url)

  url
end

#CloseSearchUIObject


58
59
60
61
62
# File 'src/modules/SourceManagerSLP.rb', line 58

def CloseSearchUI
  UI.CloseDialog

  nil
end

#CloseSLPListFoundDialogObject


473
474
475
476
477
# File 'src/modules/SourceManagerSLP.rb', line 473

def CloseSLPListFoundDialog
  UI.CloseDialog

  nil
end

#CreateSearchUIObject


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'src/modules/SourceManagerSLP.rb', line 37

def CreateSearchUI
  UI.OpenDialog(
    VBox(
      HBox(
        HSquash(MarginBox(0.5, 0.2, Icon("yast-you_server"))),
        # translators: popup heading (progress popup)
        Left(Heading(Id(:search_heading), _("SLP Search")))
      ),
      Left(
        # progress information
        ReplacePoint(
          Id(:search_rp),
          Label(_("Scanning network for installation services..."))
        )
      )
    )
  )

  nil
end

#CreateSLPListFoundDialog(services) ⇒ Object


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
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
# File 'src/modules/SourceManagerSLP.rb', line 86

def CreateSLPListFoundDialog(services)
  filter_dialog = Empty()
  show_filter = false

  # Show filter only for bigger amount of services
  if Ops.greater_than(Builtins.size(services.value), 15)
    show_filter = true
    filter_dialog = MarginBox(
      0.5,
      0.5,
      Frame(
        # frame label
        _("Filter Form"),
        VSquash(
          HBox(
            HSquash(MinWidth(22, TextEntry(Id(:filter_text), ""))),
            # push button
            PushButton(Id(:filter), _("&Filter")),
            HStretch()
          )
        )
      )
    )
  end

  # bugzilla #209426
  # window size (in ncurses) based on currently available space
  display_info = UI.GetDisplayInfo
  min_size_x = 76
  min_size_y = 19
  if Ops.get_boolean(display_info, "TextMode", true)
    min_size_x = Ops.divide(
      Ops.multiply(
        Builtins.tointeger(Ops.get_integer(display_info, "Width", 80)),
        3
      ),
      4
    )
    min_size_y = Ops.subtract(
      Ops.divide(
        Ops.multiply(
          Builtins.tointeger(Ops.get_integer(display_info, "Height", 25)),
          2
        ),
        3
      ),
      5
    )
    min_size_x = 76 if Ops.less_than(min_size_x, 76)
    min_size_y = 18 if Ops.less_than(min_size_y, 18)
    Builtins.y2milestone(
      "X/x Y/y %1/%2 %3/%4",
      Ops.get_integer(display_info, "Width", 80),
      min_size_x,
      Ops.get_integer(display_info, "Height", 25),
      min_size_y
    )
  end

  UI.OpenDialog(
    VBox(
      HBox(
        HSquash(MarginBox(0.5, 0.2, Icon("yast-you_server"))),
        # translators: popup heading
        Left(Heading(Id(:search_heading), _("Choose SLP Repository")))
      ),
      filter_dialog,
      MarginBox(
        0.5,
        0,
        MinSize(
          min_size_x,
          min_size_y,
          Tree(
            Id(:tree_of_services),
            Opt(:notify),
            # tree label (tree of available products)
            _("Available Installation &Products"),
            []
          )
        )
      ),
      PushButton(Id(:details), _("&Details...")),
      VSpacing(1),
      HBox(
        PushButton(Id(:ok), Opt(:default), Label.SelectButton),
        VSpacing(1),
        PushButton(Id(:cancel), Label.CancelButton)
      )
    )
  )

  UI.SetFocus(:filter_text) if show_filter

  nil
end

#firewalldObject


583
584
585
# File 'src/modules/SourceManagerSLP.rb', line 583

def firewalld
  Y2Firewall::Firewalld.instance
end

#GetCurrentlySelectedURL(services) ⇒ Object


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
# File 'src/modules/SourceManagerSLP.rb', line 387

def GetCurrentlySelectedURL(services)
  current = Convert.to_integer(
    UI.QueryWidget(Id(:tree_of_services), :CurrentItem)
  )

  if current.nil? || Ops.less_than(current, 0)
    # message popup
    Report.Message(
      _(
        "Select one of the offered options.\n" \
          "More repositories are available for this product.\n"
      )
    )

    nil
  else
    service_url = Builtins.substring(
      Ops.get_string(services.value, [current, "srvurl"], ""),
      21
    )

    if service_url.nil? || service_url == ""
      Builtins.y2error(
        "An internal error occurred, service ID %1, %2 has no URL!",
        current,
        Ops.get(services.value, current, {})
      )
      # popup error
      Report.Error(
        _(
          "An internal error occurred.\nThe selected repository has no URL."
        )
      )
      return nil
    end

    service_url
  end
end

#HandleSLPListDialog(services) ⇒ Object


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
# File 'src/modules/SourceManagerSLP.rb', line 427

def HandleSLPListDialog(services)
  services_ref = arg_ref(services.value)
  InitSLPListFoundDialog(services_ref, nil)
  services.value = services_ref.value

  dialog_ret = nil
  ret = nil

  loop do
    ret = UI.UserInput

    if ret == :cancel
      dialog_ret = nil
      break
    elsif ret == :ok
      dialog_ret = (
        services_ref = arg_ref(services.value)
        result = GetCurrentlySelectedURL(
          services_ref
        )
        services.value = services_ref.value
        result
      )
      Builtins.y2milestone("Selected URL: '%1'", dialog_ret)
      break if dialog_ret != "" && !dialog_ret.nil?
    elsif ret == :tree_of_services
      InitDetailsButton()
    elsif ret == :filter
      filter_string = UI.QueryWidget(Id(:filter_text), :Value)
      Builtins.y2milestone("filter_string: %1", filter_string)

      services_ref = arg_ref(services.value)
      InitSLPListFoundDialog(services_ref, filter_string)
      services.value = services_ref.value
    elsif ret == :details
      services_ref = arg_ref(services.value)
      ShowDetailsDialog(services_ref)
      services.value = services_ref.value
    else
      Builtins.y2error("Unknown ret: %1", ret)
    end
  end

  dialog_ret
end

#Icon(icon_name) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
# File 'src/modules/SourceManagerSLP.rb', line 25

def Icon(icon_name)
  ui_info = UI.GetDisplayInfo
  if Ops.get_boolean(ui_info, "HasLocalImageSupport", false) == false
    return Empty()
  end

  Image(
    Builtins.sformat("%1/22x22/apps/%2.png", Directory.icondir, icon_name),
    "[x]"
  )
end

#InitDetailsButtonObject


183
184
185
186
187
188
189
190
191
192
193
194
# File 'src/modules/SourceManagerSLP.rb', line 183

def InitDetailsButton
  current = Convert.to_integer(
    UI.QueryWidget(Id(:tree_of_services), :CurrentItem)
  )
  if current.nil? || Ops.less_than(current, 0)
    UI.ChangeWidget(Id(:details), :Enabled, false)
  else
    UI.ChangeWidget(Id(:details), :Enabled, true)
  end

  nil
end

#InitSLPListFoundDialog(services, filter_string) ⇒ Object

Initializes the listed SLP services.


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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'src/modules/SourceManagerSLP.rb', line 297

def InitSLPListFoundDialog(services, filter_string)
  filter_string = nil if filter_string == ""

  inst_products = {}
  service_label = nil

  # index in the list of 'services'
  service_counter = -1

  Builtins.foreach(services.value) do |one_service|
    # always increase the service ID, must be consistent for all turns
    service_counter = Ops.add(service_counter, 1)
    service_label = Ops.get_string(one_service, "label", "")
    # bugzilla #219759
    # service label can be empty (not defined)
    if service_label == ""
      if Ops.get_string(one_service, "srvurl", "") != ""
        service_label = Builtins.sformat(
          "%1: %2",
          _("Repository URL"),
          Builtins.substring(Ops.get_string(one_service, "srvurl", ""), 21)
        )
      else
        Builtins.y2error(
          "Wrong service definition: %1, key \"srvurl\" must not be empty.",
          one_service
        )
      end
    end
    # search works in "label" or in "srvurl" as a fallback
    if !filter_string.nil?
      # filter out all services that don't match the filter
      next if !service_label.downcase.include?(filter_string.downcase)
    end
    # define an empty list if it is not defined at all
    if Ops.get(inst_products, service_label).nil?
      Ops.set(inst_products, service_label, [])
    end
    Ops.set(
      inst_products,
      service_label,
      Builtins.add(
        Ops.get(inst_products, service_label, []),
        service_counter
      )
    )
  end

  tree_of_services = []
  urls_for_product = nil
  product_counter = -1
  service_url = nil

  # "SUSE Linux 10.2 x86_64":[10, 195]
  Builtins.foreach(inst_products) do |one_product, service_ids|
    product_counter = Ops.add(product_counter, 1)
    if Builtins.size(service_ids) == 1
      Ops.set(
        tree_of_services,
        product_counter,
        Item(Id(Ops.get(service_ids, 0)), one_product)
      )
    else
      urls_for_product = []
      Builtins.foreach(service_ids) do |service_id|
        # removing "install.suse..."
        service_url = Builtins.substring(
          Ops.get_string(services.value, [service_id, "srvurl"], ""),
          21
        )
        urls_for_product = Builtins.add(
          urls_for_product,
          Item(Id(service_id), service_url)
        )
      end
      # -1 for a product name without url (URLs are hidden below)
      Ops.set(
        tree_of_services,
        product_counter,
        Item(Id(-1), one_product, urls_for_product)
      )
    end
  end

  UI.ChangeWidget(Id(:tree_of_services), :Items, tree_of_services)
  InitDetailsButton()

  nil
end

#mainObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'src/modules/SourceManagerSLP.rb', line 9

def main
  Yast.import "UI"
  Yast.import "SLP"
  Yast.import "Wizard"
  Yast.import "Directory"
  Yast.import "Stage"
  Yast.import "SuSEFirewall"
  Yast.import "Report"
  Yast.import "Label"
  #    import "IP";
  #    import "String";
  #    import "FileUtils";

  textdomain "packager"
end

#SearchForSLPServices(services) ⇒ Object


71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'src/modules/SourceManagerSLP.rb', line 71

def SearchForSLPServices(services)
  # progress information
  SetSearchUI(Label(_("Scanning network for installation services...")))
  Builtins.y2milestone(
    "scanning network: SLP::FindSrvs(\"install.suse\", \"\")"
  )
  services.value = SLP.FindSrvs("install.suse", "")
  Builtins.y2milestone(
    "Done, found %1 repositories",
    Builtins.size(services.value)
  )

  nil
end

#SearchForSLPServicesInfo(services) ⇒ Object


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
# File 'src/modules/SourceManagerSLP.rb', line 479

def SearchForSLPServicesInfo(services)
  number_of_services = Builtins.size(services.value)

  SetSearchUI(
    Label(
      Builtins.sformat(
        # progress information, %1 stands for number of services
        _("Collecting information of %1 services found..."),
        number_of_services
      )
    )
  )

  Builtins.y2milestone(
    "Collecting data about %1 services",
    number_of_services
  )

  new_services = []

  counter = -1
  Builtins.foreach(services.value) do |slp_service|
    counter = Ops.add(counter, 1)
    server_ip = Ops.get_string(slp_service, "ip", "")
    service_url = Ops.get_string(slp_service, "srvurl", "")
    # empty server_ip
    if service_url != "" && server_ip != ""
      attrs = SLP.GetUnicastAttrMap(service_url, server_ip)

      if !attrs.nil? && attrs != {}
        slp_service = Builtins.union(slp_service, attrs)
      end
    end
    Ops.set(new_services, counter, slp_service)
  end

  Builtins.y2milestone("Done")

  services.value = deep_copy(new_services)

  nil
end

#SelectOneSLPServiceString

Function searches the SLP services on the current network. If there are some SLP services, opens up a dialog containing them and user has to select one or cancel the operation. Selected URL is returned as string, otherwise a nil is returned.


528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
# File 'src/modules/SourceManagerSLP.rb', line 528

def SelectOneSLPService
  CreateSearchUI()
  slp_services_found = []
  slp_services_found_ref = arg_ref(slp_services_found)
  SearchForSLPServices(slp_services_found_ref)
  slp_services_found = slp_services_found_ref.value

  if slp_services_found.nil? || Builtins.size(slp_services_found).zero?
    Builtins.y2warning("No SLP repositories found")
  else
    slp_services_found_ref = arg_ref(slp_services_found)
    SearchForSLPServicesInfo(slp_services_found_ref)
    slp_services_found = slp_services_found_ref.value
  end
  CloseSearchUI()

  # no servers found
  if slp_services_found.nil? || Builtins.size(slp_services_found).zero?
    Builtins.y2warning("No SLP repositories were found")
    if !Stage.initial && SuSEFirewall.IsStarted
      Report.Message(
        # error popup
        _(
          "No SLP repositories have been found on your network.\n" \
            "This could be caused by a running SuSEfirewall2,\n" \
            "which probably blocks the network scanning."
        )
      )
    else
      Report.Message(
        # error popup
        _("No SLP repositories have been found on your network.")
      )
    end
    return nil
  end

  slp_services_found_ref = arg_ref(slp_services_found)
  CreateSLPListFoundDialog(slp_services_found_ref)
  slp_services_found = slp_services_found_ref.value
  selected_service = (
    slp_services_found_ref = arg_ref(slp_services_found)
    HandleSLPListDialog(slp_services_found_ref)
  )
  CloseSLPListFoundDialog()

  selected_service
end

#SetSearchUI(content) ⇒ Object


64
65
66
67
68
69
# File 'src/modules/SourceManagerSLP.rb', line 64

def SetSearchUI(content)
  content = deep_copy(content)
  UI.ReplaceWidget(Id(:search_rp), content)

  nil
end

#ShowDetailsDialog(services) ⇒ Object


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
259
260
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
# File 'src/modules/SourceManagerSLP.rb', line 196

def ShowDetailsDialog(services)
  current = Convert.to_integer(
    UI.QueryWidget(Id(:tree_of_services), :CurrentItem)
  )
  if current.nil? || Ops.less_than(current, 0)
    Builtins.y2error("No service selected, no details")
    # error popup
    Report.Error(_("No details are available."))
  else
    service_details = Ops.get(services.value, current, {})

    if service_details == {}
      # message popup
      Report.Message(_("No details are available."))
    else
      # maximal size allowed by UI (with a fallback)
      display_information = UI.GetDisplayInfo
      max_width = Ops.get_integer(display_information, "Width", 1200)
      max_heigth = Ops.get_integer(display_information, "Height", 500)
      # Graphical UI returns 1280x1024, textmode 80x25
      if !Ops.get_boolean(display_information, "TextMode", false)
        max_width = Ops.divide(max_width, 15)
        max_heigth = Ops.divide(max_heigth, 18)
      end

      # maximal length of key and val found
      max_len_key = 0
      max_len_val = 0

      details = []
      curr_len_key = 0
      curr_len_val = 0

      Builtins.foreach(service_details) do |key, value|
        details = Builtins.add(
          details,
          Item(Id(nil), Builtins.tostring(key), Builtins.tostring(value))
        )
        curr_len_key = Builtins.size(Builtins.tostring(key))
        curr_len_val = Builtins.size(Builtins.tostring(value))
        if !curr_len_key.nil? &&
            Ops.greater_than(curr_len_key, max_len_key)
          max_len_key = curr_len_key
        end
        if !curr_len_val.nil? &&
            Ops.greater_than(curr_len_val, max_len_val)
          max_len_val = curr_len_val
        end
      end
      # maximal key + maximal val (presented in table)
      max_len_total = Ops.add(max_len_key, max_len_val)

      # min X in UI
      min_size_x = max_len_total
      min_size_x = max_width if Ops.greater_than(min_size_x, max_width)
      min_size_x = 60 if Ops.less_than(min_size_x, 60)

      # min Y in UI
      min_size_y = Ops.add(Builtins.size(details), 4)
      min_size_y = max_heigth if Ops.greater_than(min_size_y, max_heigth)
      min_size_y = 14 if Ops.less_than(min_size_y, 14)

      Builtins.y2milestone(
        "Details min size: %1 x %2",
        min_size_x,
        min_size_y
      )

      UI.OpenDialog(
        VBox(
          Left(Heading(Id(:details_heading), _("Repository Details"))),
          MinSize(
            min_size_x,
            min_size_y,
            Table(
              Header(
                # table header item
                _("Key"),
                # table header item
                _("Value")
              ),
              details
            )
          ),
          VSpacing(1),
          PushButton(Id(:ok), Label.OKButton)
        )
      )
      UI.UserInput
      UI.CloseDialog
    end
  end

  nil
end