Class: Yast::SourceManagerSLPClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Symbol) AddSourceTypeSLP

Function scans for SLP installation servers on the network

Returns:

  • (Symbol)

    one of back,next



624
625
626
627
628
629
# File '../../src/modules/SourceManagerSLP.rb', line 624

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

  url
end

- (Object) CloseSearchUI



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

def CloseSearchUI
  UI.CloseDialog

  nil
end

- (Object) CloseSLPListFoundDialog



480
481
482
483
484
# File '../../src/modules/SourceManagerSLP.rb', line 480

def CloseSLPListFoundDialog
  UI.CloseDialog

  nil
end

- (Object) CreateSearchUI



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File '../../src/modules/SourceManagerSLP.rb', line 45

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

- (Object) CreateSLPListFoundDialog(services)



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
182
183
184
185
186
187
188
189
# File '../../src/modules/SourceManagerSLP.rb', line 94

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

- (Object) GetCurrentlySelectedURL(services)



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

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.\nMore repositories are available for this product.\n"
      )
    )

    return 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
    else
      return service_url
    end
  end
end

- (Object) HandleSLPListDialog(services)



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

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

  dialog_ret = nil
  ret = nil

  while true
    ret = UI.UserInput

    if ret == :cancel
      dialog_ret = nil
      break
    elsif ret == :ok
      dialog_ret = (
        services_ref = arg_ref(services.value);
        _GetCurrentlySelectedURL_result = GetCurrentlySelectedURL(
          services_ref
        );
        services.value = services_ref.value;
        _GetCurrentlySelectedURL_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

- (Object) Icon(icon_name)



33
34
35
36
37
38
39
40
41
42
43
# File '../../src/modules/SourceManagerSLP.rb', line 33

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

- (Object) InitDetailsButton



191
192
193
194
195
196
197
198
199
200
201
202
# File '../../src/modules/SourceManagerSLP.rb', line 191

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

- (Object) InitSLPListFoundDialog(services, filter_string)

Initializes the listed SLP services.

Parameters:

  • services (Yast::ArgRef)

    reference to services (Array<Hash>)

  • filter_string (String, nil)

    regexp for services that should be visible (nil or “” for all)



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
386
387
388
389
390
391
392
393
# File '../../src/modules/SourceManagerSLP.rb', line 304

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
      service_id = Ops.get(service_ids, 0)
      Ops.set(
        tree_of_services,
        product_counter,
        Item(Id(service_id), 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

- (Object) main



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File '../../src/modules/SourceManagerSLP.rb', line 17

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

- (Object) SearchForSLPServices(services)



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File '../../src/modules/SourceManagerSLP.rb', line 79

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

- (Object) SearchForSLPServicesInfo(services)



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
523
524
525
526
527
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
# File '../../src/modules/SourceManagerSLP.rb', line 486

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 = []

  dns_cache = {}

  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", "")
    # bugzilla #219759
    # /usr/bin/host not in inst-sys
    # Anyway, it's not needed - key "ip" defines the server which has sent this reply
    #
    #	    if (!IP::Check4(server_ip))
    #	    {
    #		if (haskey(dns_cache, server_ip))
    #		{
    #		    server_ip = dns_cache[server_ip]:"";
    #		}
    #		else if (FileUtils::Exists ("/usr/bin/host"))
    #		{
    #		    string server_ip_quoted = "'" + String::Quote (server_ip) + "'";
    #		    y2milestone ("Resolving host %1...", server_ip_quoted);
    #		    map m = (map)SCR::Execute (.target.bash_output, sformat ("/usr/bin/host %1 | /bin/grep address", server_ip_quoted));
    #
    #		    if (m["exit"]:0 == 0)
    #		    {
    #			string out = m["stdout"]:"";
    #			string ip = regexpsub (out, "has address (.*)$", "\\1");
    #			if (ip != nil)
    #			{
    #			    y2milestone("...resolved to %1", ip);
    #			    // cache the IP address
    #			    dns_cache[server_ip] = ip;
    #
    #			    server_ip = ip;
    #			}
    #		    }
    #		}
    #	    }

    # 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

- (String) SelectOneSLPService

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.

Returns:

  • (String)

    service_URL



569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
# File '../../src/modules/SourceManagerSLP.rb', line 569

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) == 0
    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) == 0
    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_result = HandleSLPListDialog(
      slp_services_found_ref
    );
    slp_services_found = slp_services_found_ref.value;
    _HandleSLPListDialog_result
  )
  CloseSLPListFoundDialog()

  selected_service
end

- (Object) SetSearchUI(content)



72
73
74
75
76
77
# File '../../src/modules/SourceManagerSLP.rb', line 72

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

  nil
end

- (Object) ShowDetailsDialog(services)



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
291
292
293
294
295
296
297
298
# File '../../src/modules/SourceManagerSLP.rb', line 204

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