Class: Yast::PackageSlideShowClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
src/modules/PackageSlideShow.rb

Overview

Module to access slides from installation repository

Constant Summary collapse

MAX_TIME_PER_CD =

seconds to cut off predicted time

7200
MIN_TIME_PER_CD =

minimum time displayed per CD if there is something to install

5
SIZE_COLUMN_POSITION =

Column index for refreshing statistics: remaining size

1
PKG_COUNT_COLUMN_POSITION =

Column index for refreshing statistics: remaining number of packages

2
TIME_COLUMN_POSITION =

Column index for refreshing statistics: remaining time

3

Instance Method Summary collapse

Instance Method Details

#CdProgressId(src_no, cd_no) ⇒ Object

Return a CD's progress bar ID


1080
1081
1082
# File 'src/modules/PackageSlideShow.rb', line 1080

def CdProgressId(src_no, cd_no)
  Builtins.sformat("Src %1 CD %2", src_no, cd_no)
end

#CdStatisticsTableItemsObject

Returns a table widget item list for CD statistics


850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
# File 'src/modules/PackageSlideShow.rb', line 850

def CdStatisticsTableItems
  itemList = []

  #
  # Add "Total" item - at the top so it is visible by default even if there are many items
  #

  # List column header for total remaining MB and time to install
  caption = _("Total")
  remaining = TotalRemainingSize()
  rem_size = FormatRemainingSize(remaining)
  rem_count = FormatRemainingCount(TotalRemainingPkgCount())
  rem_time = ""

  if @unit_is_seconds && Ops.greater_than(@bytes_per_second, 0)
    rem_time = FormatTimeShowOverflow(TotalRemainingTime())
  end

  itemList = Builtins.add(
    itemList,
    SlideShow.TableItem(
      "total",
      caption,
      Ops.add("   ", rem_size),
      Ops.add("   ", rem_count),
      Ops.add("   ", rem_time)
    )
  )

  #
  # Now go through all repositories
  #

  src_no = 0

  Builtins.foreach(@remaining_sizes_per_cd_per_src) do |inst_src|
    Builtins.y2milestone("src #%1: %2", src_no, inst_src)
    # Ignore repositories from where there is nothing is to install
    if Ops.greater_than(ListSum(inst_src), 0)
      # Add heading for this repository
      itemList = Builtins.add(
        itemList,
        SlideShow.TableItem(
          Builtins.sformat("src(%1)", src_no),
          Ops.get(@inst_src_names, src_no, ""),
          "",
          "",
          ""
        )
      )

      cd_no = 0

      Builtins.foreach(inst_src) do |src_remaining|
        if Ops.greater_than(src_remaining, 0) ||
            Ops.add(src_no, 1) == @current_src_no &&
                Ops.add(cd_no, 1) == @current_cd_no # suppress current CD
          caption = Builtins.sformat(@media_type, Ops.add(cd_no, 1)) # "Medium 1" - column #0
          rem_size = FormatRemainingSize(src_remaining) # column #1
          rem_count = FormatRemainingCount(
            Ops.get(@src_remaining_pkg_count_per_cd_per_src, [src_no, cd_no], 0)
          )
          rem_time = ""

          if @unit_is_seconds && Ops.greater_than(@bytes_per_second, 0)
            src_remaining = Ops.divide(src_remaining, @bytes_per_second)
            src_remaining = MIN_TIME_PER_CD if src_remaining < MIN_TIME_PER_CD
            rem_time = String.FormatTime(src_remaining) # column #2

            if Ops.greater_than(src_remaining, MAX_TIME_PER_CD) # clip off at 2 hours
              # When data throughput goes downhill (stalled network connection etc.),
              # cut off the predicted time at a reasonable maximum.
              # "%1" is a predefined maximum time.
              rem_time = FormatTimeShowOverflow(
                Ops.unary_minus(MAX_TIME_PER_CD)
              )
            end
          end

          itemList = Builtins.add(
            itemList,
            SlideShow.TableItem(
              Builtins.sformat("cd(%1,%2)", src_no, cd_no), # ID
              caption,
              Ops.add("   ", rem_size),
              Ops.add("   ", rem_count),
              Ops.add("   ", rem_time)
            )
          )
        end
        cd_no = Ops.add(cd_no, 1)
      end
    end
    src_no = Ops.add(src_no, 1)
  end

  if @debug
    Builtins.y2milestone("Remaining: %1", @remaining_sizes_per_cd_per_src)
    Builtins.y2milestone("CD table item list:\n%1", itemList)
  end

  deep_copy(itemList)
end

#DisplayGlobalProgressObject


994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
# File 'src/modules/PackageSlideShow.rb', line 994

def DisplayGlobalProgress
  tot_rem_t = TotalRemainingTime()

  rem_string =
    if @unit_is_seconds && Ops.greater_than(@bytes_per_second, 0) &&
        Ops.greater_than(tot_rem_t, 0)
      Builtins.sformat(
        "%1 / %2",
        FormatRemainingSize(TotalRemainingSize()),
        FormatTimeShowOverflow(tot_rem_t)
      )
    else
      FormatRemainingSize(TotalRemainingSize())
    end

  rem_string = Ops.add(rem_string, ", ") if rem_string != ""

  SlideShow.SetGlobalProgressLabel(
    Ops.add(
      SlideShow.CurrentStageDescription,
      Builtins.sformat(
        _(" (Remaining: %1%2 packages)"),
        rem_string,
        TotalRemainingPkgCount()
      )
    )
  )

  nil
end

#DoneProvide(error, _reason, _name) ⇒ Object


1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
# File 'src/modules/PackageSlideShow.rb', line 1025

def DoneProvide(error, _reason, _name)
  if error.zero?
    @total_downloaded = Ops.add(@total_downloaded, @current_provide_size)

    @total_count_downloaded = Ops.add(@total_count_downloaded, 1)
    Builtins.y2milestone(
      "Downloaded %1/%2 packages",
      @total_count_downloaded,
      @total_count_to_download
    )

    # move the progress also for downloaded files
    UpdateTotalProgressValue()

    d_mode = Ops.get_symbol(Pkg.CommitPolicy, "download_mode", :default)

    if d_mode == :download_in_advance ||
        d_mode == :default && Mode.normal &&
            !Installation.dirinstall_installing_into_dir
      # display download progress in DownloadInAdvance mode
      # translations: progress message (part1)
      SlideShow.SetGlobalProgressLabel(
        Ops.add(
          _("Downloading Packages..."),
          # progress message (part2)
          Builtins.sformat(
            _(" (Downloaded %1 of %2 packages)"),
            @total_count_downloaded,
            @total_count_to_download
          )
        )
      )
    end
  end

  nil
end

#FindNextMediaObject

Try to figure out what media will be needed next and set next_src_no and next_cd_no accordingly.


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

def FindNextMedia
  # Normally we would have to use current_cd_no+1,
  # but since this uses 1..n and we need 0..n-1
  # for array subscripts anyway, use it as it is.
  @next_cd_no = @current_cd_no
  @next_src_no = Ops.subtract(@current_src_no, 1)
  @last_cd = false

  while Ops.less_than(
    @next_src_no,
    Builtins.size(@remaining_sizes_per_cd_per_src)
  )
    remaining_sizes = Ops.get(
      @remaining_sizes_per_cd_per_src,
      @next_src_no,
      []
    )

    while Ops.less_than(@next_cd_no, Builtins.size(remaining_sizes))
      if Ops.greater_than(Ops.get(remaining_sizes, @next_cd_no, 0), 0)
        if @debug
          Builtins.y2milestone(
            "Next media: src: %1 CD: %2",
            @next_src_no,
            @next_cd_no
          )
        end
        return
      else
        @next_cd_no = Ops.add(@next_cd_no, 1)
      end
    end

    @next_src_no = Ops.add(@next_src_no, 1)
  end

  Builtins.y2milestone("No next media - all done") if @debug

  @next_src_no = -1
  @next_cd_no = -1
  @last_cd = true

  nil
end

#FormatNextMediaObject


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

def FormatNextMedia
  text = ""

  if Ops.greater_or_equal(@next_src_no, 0) &&
      Ops.greater_or_equal(@next_cd_no, 0)
    next_media_name = Builtins.sformat(
      "%1 %2",
      Ops.get(@inst_src_names, @next_src_no, ""),
      Builtins.sformat(@media_type, Ops.add(@next_cd_no, 1))
    )

    if @unit_is_seconds
      # Status line informing about the next CD that will be used
      # %1: Media type ("CD" / "DVD", ???)
      # %2: Media name ("SuSE Linux Professional CD 2" )
      # %3: Time remaining until this media will be needed
      text = Builtins.sformat(
        _("Next: %1 -- %2"),
        next_media_name,
        String.FormatTime(
          Ops.get(
            @remaining_times_per_cd_per_src,
            [
              Ops.subtract(@current_src_no, 1),
              Ops.subtract(@current_cd_no, 1)
            ],
            1
          )
        )
      )
    else
      # Status line informing about the next CD that will be used
      # %1: Media type ("CD" / "DVD", ???)
      # %2: Media name ("SuSE Linux Professional CD 2" )
      text = Builtins.sformat(_("Next: %1"), next_media_name)
    end
  end

  text
end

#FormatRemainingCount(remaining) ⇒ String

Format number of remaining packages to be installed as string.


219
220
221
222
223
224
225
226
227
# File 'src/modules/PackageSlideShow.rb', line 219

def FormatRemainingCount(remaining)
  if Ops.less_than(remaining, 0)
    # Nothing more to install from this CD (very concise - little space!!)
    return _("Done.")
  end
  return "" if remaining.zero?

  Builtins.sformat("%1", remaining)
end

#FormatRemainingSize(remaining) ⇒ String

Format number of remaining bytes to be installed as string.


205
206
207
208
209
210
211
212
213
# File 'src/modules/PackageSlideShow.rb', line 205

def FormatRemainingSize(remaining)
  if Ops.less_than(remaining, 0)
    # Nothing more to install from this CD (very concise - little space!!)
    return _("Done.")
  end
  return "" if remaining.zero?

  String.FormatSize(remaining)
end

#FormatTimeShowOverflow(seconds) ⇒ Object

Format an integer seconds value with min:sec or hours:min:sec

Negative values are interpreted as overflow - “>” is prepended and the absolute value is used.


182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'src/modules/PackageSlideShow.rb', line 182

def FormatTimeShowOverflow(seconds)
  text = ""

  if Ops.less_than(seconds, 0) # Overflow (indicated by negative value)
    # When data throughput goes downhill (stalled network connection etc.),
    # cut off the predicted time at a reasonable maximum.
    # "%1" is a predefined maximum time.

    text = Builtins.sformat(
      _(">%1"),
      String.FormatTime(Ops.unary_minus(seconds))
    )
  else
    text = String.FormatTime(seconds)
  end

  text
end

#GetPackageSummaryObject


106
107
108
109
110
111
112
113
114
115
116
117
# File 'src/modules/PackageSlideShow.rb', line 106

def GetPackageSummary
  {
    "installed"        => @installed_packages,
    "updated"          => @updated_packages,
    "removed"          => @removed_packages,
    "installed_list"   => @installed_packages_list,
    "updated_list"     => @updated_packages_list,
    "removed_list"     => @removed_packages_list,
    "downloaded_bytes" => @total_downloaded,
    "installed_bytes"  => @total_installed
  }
end

#InitPkgData(force) ⇒ Object

Initialize internal pacakge data, such as remaining package sizes and times. This may not be called before the pkginfo server is up and running, so this cannot be reliably done from the constructor in all cases.


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

def InitPkgData(force)
  return if @init_pkg_data_complete && !force

  ResetPackageSummary()
  # Reinititalize some globals (in case this is a second run)
  @total_size_installed = 0
  # total_time_elapsed  = 0;
  # start_time    = -1;
  @current_src_no = -1 # 1..n
  @current_cd_no = -1 # 1..n
  @next_src_no = -1
  @next_cd_no = -1
  @last_cd = false
  @unit_is_seconds = false # begin with package sizes
  @bytes_per_second = 1

  src_list = Pkg.PkgMediaNames
  @inst_src_names = Builtins.maplist(src_list) do |src|
    Ops.get_string(src, 0, "CD")
  end

  Builtins.y2milestone("Media names: %1", @inst_src_names)

  index = 0

  @srcid_to_current_src_no = Builtins.listmap(src_list) do |src|
    index = Ops.add(index, 1)
    { Ops.get_integer(src, 1, -1) => index }
  end

  Builtins.y2milestone(
    "Repository  mapping information: %1",
    @srcid_to_current_src_no
  )

  @total_sizes_per_cd_per_src = Pkg.PkgMediaSizes
  @total_pkg_count_per_cd_per_src = Pkg.PkgMediaCount

  @total_size_to_install = ListSum(
    Builtins.flatten(@total_sizes_per_cd_per_src)
  )
  Builtins.y2milestone("total_size_to_install: %1", @total_size_to_install)
  @remaining_sizes_per_cd_per_src = Builtins.eval(
    @total_sizes_per_cd_per_src
  )
  @remaining_pkg_count_per_cd_per_src = Builtins.eval(
    @total_pkg_count_per_cd_per_src
  )
  @total_cd_count = Builtins.size(
    Builtins.flatten(@total_sizes_per_cd_per_src)
  )
  @total_count_to_download = packages_to_download(
    @total_pkg_count_per_cd_per_src
  )
  @total_count_downloaded = 0
  total_count_to_install = packages_to_install(
    @total_pkg_count_per_cd_per_src
  )
  total = Ops.add(total_count_to_install, @total_count_to_download)
  @downloading_pct = Ops.divide(
    Ops.multiply(total.zero? ? 0 : 100, @total_count_to_download),
    total
  )
  @init_pkg_data_complete = true

  # reset the history log
  SlideShow.inst_log = ""

  Builtins.y2milestone(
    "PackageSlideShow::InitPkgData() done; total_sizes_per_cd_per_src: %1",
    @total_sizes_per_cd_per_src
  )
  Builtins.y2milestone(
    "PackageSlideShow::InitPkgData(): pkg: %1",
    @total_pkg_count_per_cd_per_src
  )

  # RebuildDialog(true);

  nil
end

#ListSum(sizes) ⇒ Fixnum

Sum up all list items


127
128
129
# File 'src/modules/PackageSlideShow.rb', line 127

def ListSum(sizes)
  sizes.reduce(0) { |a, e| e == -1 ? a : a + e }
end

#ListSumCutOff(sizes, max_cutoff) ⇒ Object

Sum up all positive list items, but cut off individual items at a maximum value. Negative return values indicate overflow of any individual item at “max_cutoff”. In this case, the absolute value of the return value is “max_cutoff” * number of overflows. (e.g. >2hour + >2hours + 1:13:20 => >4hours


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'src/modules/PackageSlideShow.rb', line 136

def ListSumCutOff(sizes, max_cutoff)
  sizes = deep_copy(sizes)
  overflow = 0
  sum = 0

  Builtins.foreach(sizes) do |item|
    if Ops.greater_than(item, 0)
      if Ops.greater_than(item, max_cutoff)
        overflow = Ops.add(overflow, 1)
      else
        sum = Ops.add(sum, item)
      end
    end
  end

  if Ops.greater_than(overflow, 0)
    sum = Ops.multiply(Ops.unary_minus(overflow), max_cutoff)
  end

  sum
end

#mainObject


24
25
26
27
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
# File 'src/modules/PackageSlideShow.rb', line 24

def main
  Yast.import "UI"
  Yast.import "Pkg"

  textdomain "packager"

  Yast.import "Slides"
  Yast.import "SlideShow"
  Yast.import "String"
  Yast.import "Mode"
  Yast.import "URL"
  Yast.import "Installation"

  @total_sizes_per_cd_per_src = [] # total sizes per inst-src: [ [42, 43, 44], [12, 13, 14] ]
  @remaining_sizes_per_cd_per_src = [] # remaining sizes
  @remaining_times_per_cd_per_src = [] # remaining times
  @inst_src_names = [] # a list of strings identifying each repository
  @total_pkg_count_per_cd_per_src = [] # number of pkgs per inst-src: [ [7, 5, 3], [2, 3, 4] ]
  @remaining_pkg_count_per_cd_per_src = [] # remaining number of pkgs
  @srcid_to_current_src_no = {}
  # the string is follwed by a media number, e.g. "Medium 1"
  @media_type = _("Medium %1")
  @total_size_installed = 0
  @total_size_to_install = 0
  @total_count_to_download = 0
  @total_count_downloaded = 0
  @downloading_pct = 0

  @current_src_no = -1 # 1..n
  @current_cd_no = -1 # 1..n
  @next_src_no = -1
  @next_cd_no = -1
  @last_cd = false
  @total_cd_count = 0
  @unit_is_seconds = false # begin with package sizes
  @bytes_per_second = 1
  @init_pkg_data_complete = false

  @debug = false # more debugging info
  @provide_name = "" # currently downlaoded package name
  @provide_size = "" # currently downlaoded package size

  # package summary
  # package counters
  @installed_packages = 0
  @updated_packages = 0
  @removed_packages = 0

  @total_downloaded = 0
  @total_installed = 0

  # package list (only used in installed system)
  @installed_packages_list = []
  @updated_packages_list = []
  @removed_packages_list = []
  #    integer avg_download_rate = 0;

  @current_provide_size = 0
  @current_install_size = 0
  @updating = false
end

#packages_to_download(src_mapping) ⇒ Object


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

def packages_to_download(src_mapping)
  src_mapping = deep_copy(src_mapping)
  # src_mapping contains only enabled repos, get indices of the enabled repos here
  # and remap enabled index to the global repo ID
  enabled_sources = Pkg.SourceGetCurrent(true)

  Builtins.y2milestone("Packages to download input: %1", src_mapping)

  ret = 0

  i = 0
  Builtins.foreach(src_mapping) do |media_mapping|
    if Ops.greater_than(Builtins.size(media_mapping), 0)
      # check if the repository is remote
      repo_url = Ops.get_string(
        Pkg.SourceGeneralData(Ops.get(enabled_sources, i, -1)),
        "url",
        ""
      )
      repo_schema = Builtins.tolower(
        Ops.get_string(URL.Parse(repo_url), "scheme", "")
      )

      # iso repos get also downloaded according to experience; the addition is not a perfect
      # fix, but still improves the progress (bnc#724486)
      if Builtins.contains(["http", "https", "ftp", "sftp", "iso"], repo_schema)
        total = 0
        Builtins.foreach(media_mapping) do |count|
          total = Ops.add(total, count)
        end

        Builtins.y2milestone(
          "Downloading %1 packages from remote repository %2",
          total,
          Ops.get(enabled_sources, i, -1)
        )
        ret = Ops.add(ret, total)
      end
    end
    i = Ops.add(i, 1)
  end

  Builtins.y2milestone("Total number of packages to download: %1", ret)

  ret
end

#packages_to_install(src_mapping) ⇒ Object


393
394
395
396
397
398
# File 'src/modules/PackageSlideShow.rb', line 393

def packages_to_install(src_mapping)
  src_mapping = deep_copy(src_mapping)
  ret = ListSum(Builtins.flatten(src_mapping))
  Builtins.y2milestone("Total number of packages to install: %1", ret)
  ret
end

#RecalcRemainingTimes(force_recalc) ⇒ Object

Recalculate remaining times per CD based on package sizes remaining and data rate so far. Recalculation is only done each 'recalc_interval' seconds unless 'force_recalc' is set to 'true'.

See Also:

  • SlideShow.next_recalc_time
  • Yast2::SystemTime.uptime

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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# File 'src/modules/PackageSlideShow.rb', line 578

def RecalcRemainingTimes(force_recalc)
  if !force_recalc && Yast2::SystemTime.uptime < SlideShow.next_recalc_time
    # Nothing to do (yet) - simply return
    return false
  end

  elapsed = SlideShow.total_time_elapsed

  if SlideShow.start_time >= 0
    elapsed += Yast2::SystemTime.uptime - SlideShow.start_time
  end

  if elapsed.zero?
    # Called too early - no calculation possible yet.
    # This happens regularly during initialization, so an error
    # message wouldn't be a good idea here.

    return false
  end

  # This is the real thing.

  real_bytes_per_second = @total_size_installed.to_f / elapsed

  # But this turns out to be way to optimistic - RPM gets slower and
  # slower while installing. So let's add some safety margin to make
  # sure initial estimates are on the pessimistic side - the
  # installation being faster than initially estimated will be a
  # pleasant surprise to the user. Most users don't like it the other
  # way round.
  #
  # The "pessimistic factor" progressively decreases as the installation
  # proceeds.  It begins with about 1.7, i.e. the data transfer rate is
  # halved to what it looks like initially. It decreases to 1.0 towards
  # the end.

  pessimistic_factor = 1.0

  if @total_size_to_install > 0
    pessimistic_factor = 1.7 - @total_size_installed.to_f / @total_size_to_install
  end

  @bytes_per_second = (real_bytes_per_second / pessimistic_factor + 1).floor

  @remaining_times_per_cd_per_src = []

  # Recalculate remaining times for the individual CDs

  Builtins.foreach(@remaining_sizes_per_cd_per_src) do |remaining_sizes_list|
    remaining_times_list = []
    remaining_time = -1

    remaining_sizes_list.each do |remaining_size|
      remaining_time = remaining_size

      if remaining_size > 0
        remaining_time = (remaining_size.to_f / @bytes_per_second).round

        if remaining_time < MIN_TIME_PER_CD
          # It takes at least this long for the CD drive to spin up and
          # for RPM to do _anything_. Times below this values are
          # ridiculously unrealistic.
          remaining_time = MIN_TIME_PER_CD
        elsif remaining_time > MAX_TIME_PER_CD # clip off at 2 hours
          # When data throughput goes downhill (stalled network connection etc.),
          # cut off the predicted time at a reasonable maximum.
          remaining_time = MAX_TIME_PER_CD
        end
      end

      remaining_times_list << remaining_time
    end

    @remaining_times_per_cd_per_src << remaining_times_list
    log.debug "Recalculated remaining time: #{@remaining_times_per_cd_per_src}"
  end

  # Since yast2 3.1.182, SlideShow.next_recalc_time holds the uptime value
  # to avoid problems if timezone changes (bnc#956730), so
  # Yast2::SystemTime.uptime must be used instead of ::Time.now
  # (bsc#982138).
  SlideShow.next_recalc_time = Yast2::SystemTime.uptime + SlideShow.recalc_interval

  true
end

#ResetPackageSummaryObject


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'src/modules/PackageSlideShow.rb', line 86

def ResetPackageSummary
  @installed_packages = 0
  @updated_packages = 0
  @removed_packages = 0
  @total_downloaded = 0
  @total_installed = 0
  # avg_download_rate = 0;

  @installed_packages_list = []
  @updated_packages_list = []
  @removed_packages_list = []

  # temporary values
  @current_provide_size = 0
  @current_install_size = 0
  @updating = false

  nil
end

#SanityCheck(_silent) ⇒ Object

Perform sanity check for correct initialzation etc.


277
278
279
# File 'src/modules/PackageSlideShow.rb', line 277

def SanityCheck(_silent)
  true # FIXME!
end

#SetCurrentCdNo(src_no, cd_no) ⇒ Object

Set the current repository and CD number. Must be called for each CD change. src_no: 1…n cd_no: 1…n


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

def SetCurrentCdNo(src_no, cd_no)
  if cd_no.zero?
    Builtins.y2milestone("medium number 0, using medium number 1")
    cd_no = 1
  end

  Builtins.y2milestone("SetCurrentCdNo() - src: %1 , CD: %2", src_no, cd_no)
  @current_src_no = Ops.get(@srcid_to_current_src_no, src_no, -1)
  @current_cd_no = cd_no

  SlideShow.CheckForSlides
  FindNextMedia()

  if Slides.HaveSlides && Slides.HaveSlideSupport
    if !SlideShow.HaveSlideWidget
      SlideShow.RebuildDialog

      SlideShow.SwitchToDetailsView if SlideShow.user_switched_to_details
    end

    # Don't override explicit user request!
    SlideShow.SwitchToSlideView if !SlideShow.user_switched_to_details
  elsif !SlideShow.ShowingDetails
    SlideShow.RebuildDialog
  end

  nil
end

#SlideDeltaApplyStart(pkg_name) ⇒ Object


1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
# File 'src/modules/PackageSlideShow.rb', line 1255

def SlideDeltaApplyStart(pkg_name)
  return if !SanityCheck(false)
  return if !SlideShow.ShowingDetails

  SlideShow.SubProgress(0, pkg_name)

  SlideShow.AppendMessageToInstLog(
    Builtins.sformat(_("Applying delta RPM: %1"), pkg_name)
  )

  nil
end

#SlideDisplayDone(pkg_name, pkg_size, deleting) ⇒ Object

package start display update

  • this is called at the end of a new package


1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
# File 'src/modules/PackageSlideShow.rb', line 1090

def SlideDisplayDone(pkg_name, pkg_size, deleting)
  if !deleting
    SubtractPackageSize(pkg_size)

    if SwitchToSecondsIfNecessary() || RecalcRemainingTimes(false) # no forced recalculation
      Builtins.y2debug("Updating progress for all CDs")
      UpdateAllCdProgress(false)
    else
      UpdateCurrentCdProgress(false)
    end

    UpdateTotalProgress(false)

    # Update global progress bar
    DisplayGlobalProgress()

    if @updating
      @updated_packages = Ops.add(@updated_packages, 1)

      if Mode.normal
        @updated_packages_list = Builtins.add(
          @updated_packages_list,
          pkg_name
        )
      end
    else
      @installed_packages = Ops.add(@installed_packages, 1)

      if Mode.normal
        @installed_packages_list = Builtins.add(
          @installed_packages_list,
          pkg_name
        )
      end
    end

    @total_installed = Ops.add(@total_installed, @current_install_size)
  else
    @removed_packages = Ops.add(@removed_packages, 1)

    if Mode.normal
      @removed_packages_list = Builtins.add(
        @removed_packages_list,
        pkg_name
      )
    end
  end

  nil
end

#SlideDisplayStart(pkg_name, pkg_location, _pkg_summary, pkg_size, deleting) ⇒ Object

package start display update

  • this is called at the beginning of a new package


1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
# File 'src/modules/PackageSlideShow.rb', line 1150

def SlideDisplayStart(pkg_name, pkg_location, _pkg_summary, pkg_size, deleting)
  return if !SanityCheck(false)

  # remove path
  pkg_location ||= ""
  pkg_filename = File.basename(pkg_location)
  log.info "pkg_name: #{pkg_name}"

  if deleting
    pkg_size = -1

    # This is a kind of misuse of insider knowledge: If there are packages to delete, this
    # deletion comes first, and only then packages are installed. This, however, greatly
    # distorts the estimated times based on data throughput so far: While packages are
    # deleted, throughput is zero, and estimated times rise to infinity (they are cut off
    # at max_time_per_cd to hide this). So we make sure the time spent deleting packages is
    # not counted for estimating remaining times - reset the timer.
    #
    # Note: This will begin to fail when some day packages are deleted in the middle of the
    # installaton process.

    # FIXME: SlideShow.PauseTimer
    SlideShow.ResetTimer
  end

  msg = ""

  if deleting
    # Heading for the progress bar for the current package
    # while it is deleted. "%1" is the package name.
    msg = Builtins.sformat(_("Deleting %1"), pkg_name)
  else
    @updating = Pkg.PkgInstalled(pkg_name)

    # package installation - summary text
    # %1 is RPM name, %2 is installed (unpacked) size (e.g. 6.20MB)
    msg = Builtins.sformat(
      _("Installing %1 (installed size %2)"),
      pkg_filename,
      String.FormatSize(pkg_size)
    )

    @current_install_size = pkg_size
  end

  #
  # Update package progress bar
  #
  SlideShow.SubProgress(0, msg)

  # Update global progress bar
  DisplayGlobalProgress()

  #
  # Update (user visible) installation log
  #
  SlideShow.AppendMessageToInstLog(msg)

  #
  # Update the current slide if applicable
  #
  SlideShow.ChangeSlideIfNecessary if SlideShow.ShowingSlide

  nil
end

#SlideGenericProvideStart(pkg_name, sz, pattern, remote) ⇒ Object


1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
# File 'src/modules/PackageSlideShow.rb', line 1216

def SlideGenericProvideStart(pkg_name, sz, pattern, remote)
  return if !SanityCheck(false)
  return if !SlideShow.ShowingDetails

  provide_msg = ""

  if remote
    @provide_name = pkg_name
    @provide_size = String.FormatSize(sz)

    provide_msg = Builtins.sformat(
      _("Downloading %1 (download size %2)"),
      @provide_name,
      @provide_size
    )
  else
    provide_msg = pkg_name
  end

  SlideShow.SubProgress(0, provide_msg)

  #
  # Update (user visible) installation log
  # for remote download only
  #

  return if !remote

  Builtins.y2milestone("Package '%1' is remote", pkg_name)

  # message in the installatino log, %1 is package name,
  # %2 is package size
  SlideShow.AppendMessageToInstLog(
    Builtins.sformat(pattern, pkg_name, String.FormatSize(sz))
  )

  nil
end

#SlideProvideStart(pkg_name, sz, remote) ⇒ Object

Package providal start


1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
# File 'src/modules/PackageSlideShow.rb', line 1269

def SlideProvideStart(pkg_name, sz, remote)
  @current_provide_size = remote ? sz : 0

  if remote
    # message in the installatino log, %1 is package name,
    # %2 is package size
    SlideGenericProvideStart(
      pkg_name,
      sz,
      _("Downloading %1 (download size %2)"),
      remote
    )
  end

  nil
end

#SubtractPackageSize(pkg_size) ⇒ Object

Update internal bookkeeping: subtract size of one package from the global list of remaining sizes per CD


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

def SubtractPackageSize(pkg_size)
  remaining = Ops.get(
    @remaining_sizes_per_cd_per_src,
    [Ops.subtract(@current_src_no, 1), Ops.subtract(@current_cd_no, 1)],
    1
  )
  remaining = Ops.subtract(remaining, pkg_size)
  @total_size_installed = Ops.add(@total_size_installed, pkg_size)

  if Ops.less_or_equal(remaining, 0)
    # -1 is the indicator for "done with this CD" - not to be
    # confused with 0 for "nothing to install from this CD".
    remaining = -1
  end

  Ops.set(
    @remaining_sizes_per_cd_per_src,
    [Ops.subtract(@current_src_no, 1), Ops.subtract(@current_cd_no, 1)],
    remaining
  )
  Ops.set(
    @remaining_pkg_count_per_cd_per_src,
    [Ops.subtract(@current_src_no, 1), Ops.subtract(@current_cd_no, 1)],
    Ops.subtract(
      Ops.get(
        @remaining_pkg_count_per_cd_per_src,
        [Ops.subtract(@current_src_no, 1), Ops.subtract(@current_cd_no, 1)],
        0
      ),
      1
    )
  )

  if @unit_is_seconds
    seconds = 0

    if Ops.greater_than(remaining, 0) &&
        Ops.greater_than(@bytes_per_second, 0)
      seconds = Ops.divide(remaining, @bytes_per_second)
    end

    seconds = MIN_TIME_PER_CD if seconds < MIN_TIME_PER_CD
    log.debug "Updating remaining time for source #{@current_src_no} " \
      "(medium #{@current_cd_no}): #{seconds}"
    Ops.set(
      @remaining_times_per_cd_per_src,
      [Ops.subtract(@current_src_no, 1), Ops.subtract(@current_cd_no, 1)],
      seconds
    )
  end

  if @debug
    Builtins.y2milestone(
      "SubtractPackageSize( %1 ) -> %2",
      pkg_size,
      @remaining_sizes_per_cd_per_src
    )
  end

  nil
end

#SwitchToSecondsIfNecessaryObject

Switch unit to seconds if necessary and recalc everything accordingly.


667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'src/modules/PackageSlideShow.rb', line 667

def SwitchToSecondsIfNecessary
  if @unit_is_seconds ||
      Ops.less_than(
        Yast2::SystemTime.uptime,
        Ops.add(SlideShow.start_time, SlideShow.initial_recalc_delay)
      )
    return false # no need to switch
  end

  RecalcRemainingTimes(true) # force recalculation
  @unit_is_seconds = true

  true # just switched
end

#TotalInstalledSizeObject


173
174
175
# File 'src/modules/PackageSlideShow.rb', line 173

def TotalInstalledSize
  Ops.subtract(@total_size_to_install, TotalRemainingSize())
end

#TotalRemainingPkgCountObject


169
170
171
# File 'src/modules/PackageSlideShow.rb', line 169

def TotalRemainingPkgCount
  ListSum(Builtins.flatten(@remaining_pkg_count_per_cd_per_src))
end

#TotalRemainingSizeObject


158
159
160
# File 'src/modules/PackageSlideShow.rb', line 158

def TotalRemainingSize
  ListSum(Builtins.flatten(@remaining_sizes_per_cd_per_src))
end

#TotalRemainingTimeObject


162
163
164
165
166
167
# File 'src/modules/PackageSlideShow.rb', line 162

def TotalRemainingTime
  ListSumCutOff(
    Builtins.flatten(@remaining_times_per_cd_per_src),
    MAX_TIME_PER_CD
  )
end

#UpdateAllCdProgress(silent_check) ⇒ Object

Update progress widgets for all CDs. Uses global statistics variables.


1066
1067
1068
1069
1070
1071
1072
1073
1074
# File 'src/modules/PackageSlideShow.rb', line 1066

def UpdateAllCdProgress(silent_check)
  return if !SanityCheck(silent_check)

  RecalcRemainingTimes(true) if @unit_is_seconds # force

  SlideShow.UpdateTable(CdStatisticsTableItems())

  nil
end

#UpdateCurrentCdProgress(silent_check) ⇒ Object

Update progress widgets for the current CD: Label and ProgressBar. Use global statistics variables for that.


689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# File 'src/modules/PackageSlideShow.rb', line 689

def UpdateCurrentCdProgress(silent_check)
  return if !SanityCheck(silent_check)
  return if !UI.WidgetExists(:cdStatisticsTable)

  #
  # Update table entries for current CD
  #

  remaining = Ops.get(
    @remaining_sizes_per_cd_per_src,
    [Ops.subtract(@current_src_no, 1), Ops.subtract(@current_cd_no, 1)],
    0
  )
  UI.ChangeWidget(
    Id(:cdStatisticsTable),
    term(
      :Item,
      Builtins.sformat(
        "cd(%1,%2)",
        Ops.subtract(@current_src_no, 1),
        Ops.subtract(@current_cd_no, 1)
      ),
      SIZE_COLUMN_POSITION
    ),
    FormatRemainingSize(remaining)
  )

  UI.ChangeWidget(
    Id(:cdStatisticsTable),
    term(
      :Item,
      Builtins.sformat(
        "cd(%1,%2)",
        Ops.subtract(@current_src_no, 1),
        Ops.subtract(@current_cd_no, 1)
      ),
      PKG_COUNT_COLUMN_POSITION
    ),
    FormatRemainingCount(
      Ops.get(
        @remaining_pkg_count_per_cd_per_src,
        [Ops.subtract(@current_src_no, 1), Ops.subtract(@current_cd_no, 1)],
        0
      )
    )
  )

  if @unit_is_seconds
    # Convert 'remaining' from size (bytes) to time (seconds)

    remaining = Ops.divide(remaining, @bytes_per_second)

    remaining = 0 if Ops.less_or_equal(remaining, 0)

    if Ops.greater_than(remaining, MAX_TIME_PER_CD) # clip off at 2 hours
      # When data throughput goes downhill (stalled network connection etc.),
      # cut off the predicted time at a reasonable maximum.
      remaining = Ops.unary_minus(MAX_TIME_PER_CD)
    end

    UI.ChangeWidget(
      Id(:cdStatisticsTable),
      term(
        :Item,
        Builtins.sformat(
          "cd(%1,%2)",
          Ops.subtract(@current_src_no, 1),
          Ops.subtract(@current_cd_no, 1)
        ),
        TIME_COLUMN_POSITION
      ),
      FormatTimeShowOverflow(remaining)
    )
  end

  #
  # Update "total" table entries
  #

  UI.ChangeWidget(
    Id(:cdStatisticsTable),
    term(:Item, "total", SIZE_COLUMN_POSITION),
    FormatRemainingSize(TotalRemainingSize())
  )

  UI.ChangeWidget(
    Id(:cdStatisticsTable),
    term(:Item, "total", PKG_COUNT_COLUMN_POSITION),
    FormatRemainingCount(TotalRemainingPkgCount())
  )

  if @unit_is_seconds
    UI.ChangeWidget(
      Id(:cdStatisticsTable),
      term(:Item, "total", TIME_COLUMN_POSITION),
      FormatTimeShowOverflow(TotalRemainingTime())
    )
  end

  nil
end

#UpdateCurrentPackageProgress(pkg_percent) ⇒ Object

Progress display update This is called via the packager's progress callbacks.


959
960
961
962
963
# File 'src/modules/PackageSlideShow.rb', line 959

def UpdateCurrentPackageProgress(pkg_percent)
  SlideShow.SubProgress(pkg_percent, nil)

  nil
end

#UpdateCurrentPackageRateProgress(pkg_percent, bps_avg, bps_current) ⇒ Object

update the download rate


966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
# File 'src/modules/PackageSlideShow.rb', line 966

def UpdateCurrentPackageRateProgress(pkg_percent, bps_avg, bps_current)
  # avg_download_rate = bps_avg;

  return if !SlideShow.ShowingDetails

  new_text = nil # no update of the label
  if Ops.greater_than(bps_current, 0)
    # do not show the average download rate if the space is limited
    if SlideShow.textmode && Ops.less_than(SlideShow.display_width, 100)
      bps_avg = -1
    end
    new_text = String.FormatRateMessage(
      Ops.add(@provide_name, " - %1"),
      bps_avg,
      bps_current
    )
    new_text = Builtins.sformat(
      _("Downloading %1 (download size %2)"),
      new_text,
      @provide_size
    )
  end

  SlideShow.SubProgress(pkg_percent, new_text)

  nil
end

#UpdateTotalProgress(silent_check) ⇒ Object

Update progress widgets


829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
# File 'src/modules/PackageSlideShow.rb', line 829

def UpdateTotalProgress(silent_check)
  # update the overall progress value (download + installation)
  UpdateTotalProgressValue()

  UpdateCurrentCdProgress(silent_check)

  if UI.WidgetExists(:nextMedia)
    nextMedia = FormatNextMedia()

    if nextMedia != "" || @last_cd
      UI.ChangeWidget(:nextMedia, :Value, nextMedia)
      UI.RecalcLayout
      @last_cd = false
    end
  end

  nil
end

#UpdateTotalProgressValueObject

update the overall progress value (download + installation)


792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
# File 'src/modules/PackageSlideShow.rb', line 792

def UpdateTotalProgressValue
  total_progress = 0

  if @total_count_to_download.zero?
    # no package to download, just use the install size
    total_progress = Ops.divide(
      Ops.multiply(TotalInstalledSize(), 100),
      @total_size_to_install
    )
  else
    # compute the total progress (use both download and  installation size)
    total_progress = Ops.add(
      Ops.divide(
        Ops.multiply(@total_count_downloaded, @downloading_pct),
        @total_count_to_download
      ),
      Ops.divide(
        Ops.multiply(
          TotalInstalledSize(),
          Ops.subtract(100, @downloading_pct)
        ),
        @total_size_to_install
      )
    )
  end

  Builtins.y2debug(
    "Total package installation progress: %1%%",
    total_progress
  )
  SlideShow.StageProgress(total_progress, nil)

  nil
end