Module: Yast::BackupUiInclude

Defined in:
../../src/include/backup/ui.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) AbortNewProfileCreation(profile_name)

Dialog asks for aborting the new profile creation, If aborted, profile is deleted and true returned.

Parameters:

  • string

    profile name

Returns:

  • (Boolean)

    whether abort meaning is returned



741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File '../../src/include/backup/ui.rb', line 741

def AbortNewProfileCreation(profile_name)
  # TRANSLATORS: Popup question, [Yes] means `cancel the profile creation`
  cancel_it = Popup.YesNo(_("Really cancel the profile creation?"))

  if cancel_it
    # remove the profile
    Backup.RemoveBackupProfile(profile_name, true)
    # abort the creation
    return true
  else
    # continue creation
    return false
  end
end

- (Object) AddEditScriptDialog(ret)



4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
# File '../../src/include/backup/ui.rb', line 4289

def AddEditScriptDialog(ret)
  current_item = -1
  editing = false

  default_run_before_backup = ""
  default_run_after_backup = ""

  # edit
  if ret == :edit_script
    current_item = Convert.to_integer(
      UI.QueryWidget(Id("table_of_scripts"), :CurrentItem)
    )
    editing = true 
    # add
  else
    if Convert.to_boolean(
        SCR.Execute(path(".target.mkdir"), Backup.backup_scripts_dir)
      ) != true
      Builtins.y2error("Cannot create %1", Backup.backup_scripts_dir)
    end
  end

  # >>> before backup - proposes a unique script name
  cmd = Convert.to_map(
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat(
        "mktemp --dry-run -p '%1' -t run_before_backup.XXXXXXXXXXXXXXXX",
        String.Quote(Backup.backup_scripts_dir)
      )
    )
  )

  if Ops.get_integer(cmd, "exit", -1) == 0
    default_run_before_backup = Ops.get(
      Builtins.splitstring(Ops.get_string(cmd, "stdout", ""), "\n"),
      0,
      ""
    )
  else
    Builtins.y2warning("Cannot propose a script name: %1", cmd)
  end
  # <<<

  # >>> after backup - proposes a unique script name
  cmd = Convert.to_map(
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat(
        "mktemp --dry-run -p '%1' -t run_after_backup.XXXXXXXXXXXXXXXX",
        String.Quote(Backup.backup_scripts_dir)
      )
    )
  )

  if Ops.get_integer(cmd, "exit", -1) == 0
    default_run_after_backup = Ops.get(
      Builtins.splitstring(Ops.get_string(cmd, "stdout", ""), "\n"),
      0,
      ""
    )
  else
    Builtins.y2warning("Cannot propose a script name: %1", cmd)
  end
  # <<<

  this_entry = Ops.get(Backup.backup_helper_scripts, current_item, {})

  UI.OpenDialog(
    VBox(
      MarginBox(
        1,
        0,
        Left(
          Heading(
            editing == true ?
              _("Edit Backup Helper Script Options") :
              _("Add Backup Helper Script")
          )
        )
      ),
      MarginBox(
        1,
        1,
        VBox(
          Frame(
            _("Script Type"),
            RadioButtonGroup(
              Id("script_type"),
              VBox(
                Left(
                  RadioButton(
                    Id("before"),
                    Opt(:notify),
                    _("&Before Backup")
                  )
                ),
                Left(
                  RadioButton(Id("after"), Opt(:notify), _("&After Backup"))
                )
              )
            )
          ),
          VSpacing(0.5),
          VSquash(
            HBox(
              Bottom(
                ComboBox(
                  Id("script_name"),
                  Opt(:editable, :hstretch, :notify),
                  _("Script &Path"),
                  []
                )
              ),
              Bottom(
                PushButton(Id("browse_script_name"), Label.BrowseButton)
              )
            )
          ),
          VSpacing(0.5),
          MinSize(
            80,
            12,
            MultiLineEdit(Id("script_content"), _("Script &Content"), "")
          )
        )
      ),
      ButtonBox(
        PushButton(Id(:ok), Label.OKButton),
        PushButton(Id(:cancel), Label.CancelButton)
      )
    )
  )

  current_script_type = ""
  default_script_path = ""

  # Adjusting the defaults
  if Ops.get_string(this_entry, "type", "before") == "before"
    current_script_type = "before"
    default_script_path = default_run_before_backup
  else
    current_script_type = "after"
    default_script_path = default_run_after_backup
  end

  initial_script_path = Ops.get_string(
    this_entry,
    "path",
    default_script_path
  )

  # Adjusting UI
  UI.ChangeWidget(Id("script_type"), :CurrentButton, current_script_type)
  UI.ChangeWidget(
    Id("script_name"),
    :Items,
    Builtins.toset(
      [
        Ops.get_string(this_entry, "path", default_script_path),
        default_script_path
      ]
    )
  )
  UI.ChangeWidget(Id("script_name"), :Value, initial_script_path)

  InitScriptContent()

  ret = nil
  dialog_ret = false
  path_changed_by_user = false

  while true
    ret = UI.UserInput

    if ret == :ok
      Ops.set(this_entry, "path", UI.QueryWidget(Id("script_name"), :Value))
      Ops.set(
        this_entry,
        "type",
        UI.QueryWidget(Id("script_type"), :CurrentButton)
      )

      if Ops.get_string(this_entry, "path", "") == ""
        UI.SetFocus(Id("script_name"))
        Report.Error(_("Script file name must be set."))
        next
      end

      next if !StoreScriptContent(Ops.get_string(this_entry, "path", ""))

      # a new entry
      if current_item == -1
        current_item = Builtins.size(Backup.backup_helper_scripts)
      end

      Ops.set(Backup.backup_helper_scripts, current_item, this_entry)

      dialog_ret = true
      break
    elsif ret == :cancel
      break 

      # Switching the script type
    elsif ret == "after" || ret == "before"
      if ret == "before"
        current_script_type = "before"
        default_script_path = default_run_before_backup
      else
        current_script_type = "after"
        default_script_path = default_run_after_backup
      end

      if path_changed_by_user != true
        UI.ChangeWidget(Id("script_name"), :Value, default_script_path)
      end

      InitScriptContent() 

      # Changed the script name
    elsif ret == "script_name"
      path_changed_by_user = true
      InitScriptContent() 

      # User pressed the [Browse] button
    elsif ret == "browse_script_name"
      file = UI.AskForExistingFile(
        Backup.backup_scripts_dir,
        "*",
        _("Choose a Script File Name")
      )

      next if file == nil

      UI.ChangeWidget(Id("script_name"), :Value, file)
      InitScriptContent()
      path_changed_by_user = true
    else
      Builtins.y2error("Ret %1 not handled", ret)
    end
  end

  UI.CloseDialog

  dialog_ret
end

- (Object) AddExcludeItem_Dir



5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
# File '../../src/include/backup/ui.rb', line 5265

def AddExcludeItem_Dir
  # textentry label
  result = ShowEditDialog(_("&Add New Directory"), "", nil, [])

  if Ops.get(result, "clicked") == :ok
    new = Ops.get_string(result, "text")

    # add item only if it's not empty and it isn't already in list
    if new != "" && new != nil
      if Builtins.contains(Backup.dir_list, new)
        # error poup message - %1 is a directory name
        Popup.Error(
          Builtins.sformat(_("Directory %1 is already in the list."), new)
        )
      else
        Backup.dir_list = Builtins.add(Backup.dir_list, new)

        RedrawConstraintsTable()
      end
    end
  end

  nil
end

- (Object) AddExcludeItem_Fs(all_fss)



5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
# File '../../src/include/backup/ui.rb', line 5290

def AddExcludeItem_Fs(all_fss)
  # combobox label
  result = ShowEditDialog(_("&Add New File System"), "", all_fss.value, [])

  if Ops.get(result, "clicked") == :ok
    new = Ops.get_string(result, "text")

    # add item only if it's not empty and it isn't already in list
    if new != "" && new != nil
      if Builtins.contains(Backup.fs_exclude, new)
        # error poup message - %1 is a directory name
        Popup.Error(
          Builtins.sformat(_("File system %1 is already in the list."), new)
        )
      else
        Backup.fs_exclude = Builtins.add(Backup.fs_exclude, new)

        RedrawConstraintsTable()
      end
    end
  end

  nil
end

- (Object) AddExcludeItem_Regexp



5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
# File '../../src/include/backup/ui.rb', line 5237

def AddExcludeItem_Regexp
  # textentry label
  result = ShowEditDialog(_("&Add New Expression"), "", nil, [])

  if Ops.get(result, "clicked") == :ok
    new_regexp = Ops.get_string(result, "text")

    # add item only if it's not empty and it isn't already in list
    if new_regexp != "" && new_regexp != nil
      if Builtins.contains(Backup.regexp_list, new_regexp)
        # error poup message - %1 is an entered regular expression
        Popup.Error(
          Builtins.sformat(
            _("Expression %1 is already in the list."),
            new_regexp
          )
        )
      else
        Backup.regexp_list = Builtins.add(Backup.regexp_list, new_regexp)

        RedrawConstraintsTable()
      end
    end
  end

  nil
end

- (Object) AddIncludeItem



5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
# File '../../src/include/backup/ui.rb', line 5429

def AddIncludeItem
  while true
    # return $[ "text" : text, "clicked" : input ];
    new_dir = ShowEditBrowseDialog(_("&Add New Directory"), "")

    if Ops.get(new_dir, "clicked") == :ok &&
        Ops.get_string(new_dir, "text", "") != "" &&
        Ops.get(new_dir, "text") != nil
      # bnc #395835
      if Mode.normal &&
          !FileUtils.Exists(Ops.get_string(new_dir, "text", "")) &&
          !Popup.AnyQuestion(
            _("Warning"),
            Builtins.sformat(
              _(
                "Directory %1 does not exist.\n" +
                  "\n" +
                  "Use it anyway?"
              ),
              Ops.get_string(new_dir, "text", "")
            ),
            _("Yes, Use It"),
            Label.NoButton,
            :focus_yes
          )
        next
      end

      AddIncludeItemNow(Ops.get_string(new_dir, "text", ""))

      RedrawIncludeTable()
    end

    break
  end

  nil
end

- (Object) AddIncludeItemNow(new_dir)

Managing Include dirs –>



5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
# File '../../src/include/backup/ui.rb', line 5403

def AddIncludeItemNow(new_dir)
  # Removing "/" if present
  if Builtins.contains(Backup.include_dirs, Backup.default_include_dir)
    Backup.include_dirs = Builtins.filter(Backup.include_dirs) do |one_dir|
      one_dir != Backup.default_include_dir
    end
  end

  # Removing the last slash
  if Builtins.regexpmatch(new_dir, "^.+/$")
    new_dir = Builtins.regexpsub(new_dir, "^(.+)/$", "\\1")
  end

  if new_dir == Backup.default_include_dir
    Builtins.y2milestone("Selecting the whole fs '/'")
    Backup.include_dirs = [Backup.default_include_dir]
  else
    # Adding new directory
    Backup.include_dirs = Builtins.toset(
      Builtins.add(Backup.include_dirs, new_dir)
    )
  end

  nil
end

- (Symbol) ArchDialog

Dialog for setting archive options

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



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
790
791
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
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
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
953
954
955
956
957
958
959
960
961
962
963
964
965
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
993
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
1024
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
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
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
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
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
1215
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
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
# File '../../src/include/backup/ui.rb', line 759

def ArchDialog
  # do not allow manual changes of configuration
  if Backup.no_interactive
    cont2 = true
    nfsdir = ""

    # no multivolume and does not exists, continue
    if !Backup.multi_volume
      # check if archive can be (over)written
      cont2 = WriteArchive()

      if cont2 == nil
        # error popup message - NFS mount failed
        Popup.Error(_("Cannot mount the selected NFS share."))

        cont2 = false
      end
    elsif Backup.multi_volume # test if some volume part exists
      # list directory content
      dir = Builtins.substring(
        Backup.archive_name,
        0,
        Builtins.findlastof(Backup.archive_name, "/")
      )
      fn = Builtins.substring(
        Backup.archive_name,
        Ops.add(Builtins.findlastof(Backup.archive_name, "/"), 1)
      )

      if Backup.target_type == :nfs
        nfsdir = Nfs.Mount(Backup.nfsserver, Backup.nfsexport, nil, "", "")

        if nfsdir == nil
          # error popup message - NFS mount failed
          Popup.Error(_("Cannot mount the selected NFS share."))
        else
          dir = Ops.add(Ops.add(nfsdir, "/"), dir)
        end
      end

      Builtins.y2debug("dir: %1", dir)
      Builtins.y2debug("file: %1", fn)

      ls = Convert.convert(
        SCR.Read(path(".target.dir"), dir),
        :from => "any",
        :to   => "list <string>"
      )

      matched = false

      conflict_file = ""

      # check if some volume part exists
      Builtins.foreach(ls) do |f|
        if Builtins.regexpmatch(f, Ops.add("d*_", fn)) == true
          if matched == false
            matched = true
            conflict_file = f
          end
        end
      end 


      Builtins.y2debug("found volume part: %1", conflict_file)

      # display question
      if matched == true
        # For translators %1 is volume file name (e.g. /tmp/01_backup.tar)
        cont2 = Popup.YesNo(
          Builtins.sformat(
            _(
              "The existing file %1 could become part of new volume set and be overwritten.\nReally continue?"
            ),
            Ops.add(Ops.add(dir, "/"), conflict_file)
          )
        )
      else
        cont2 = true
      end
    end

    # unmount mounted directory
    Nfs.Unmount(nfsdir) if Ops.greater_than(Builtins.size(nfsdir), 0)

    if cont2
      @last_input = :next
      return @last_input
    end
  end

  # dialog header
  Wizard.SetContents(
    _("Archive Settings"),
    VBox(
      VSpacing(0.5),
      HBox(
        InputField(Id(:filename), Opt(:hstretch), Label.FileName),
        HSpacing(1),
        VBox(Label(""), PushButton(Id(:browse_file), Label.BrowseButton))
      ),
      VSpacing(0.5),
      Frame(
        _("Backup Location"),
        HBox(
          RadioButtonGroup(
            Id(:source),
            Opt(:notify),
            VBox(
              VSpacing(0.3),
              # radio button label
              Left(
                RadioButton(
                  Id(:file),
                  Opt(:notify),
                  _("&Local File"),
                  Backup.target_type == :file
                )
              ),
              VSpacing(0.3),
              # radio button label
              Left(
                RadioButton(
                  Id(:nfs),
                  Opt(:notify),
                  _("Network (N&FS)"),
                  Backup.target_type == :nfs
                )
              ),
              HBox(
                HSpacing(2),
                # text entry label
                InputField(
                  Id(:nfsserver),
                  Opt(:hstretch),
                  _("I&P Address or Name of NFS Server"),
                  Backup.nfsserver
                ),
                HSpacing(1),
                # push button label
                VBox(
                  Label(""),
                  # Pushbutton label
                  PushButton(Id(:selecthost), _("&Select..."))
                )
              ),
              HBox(
                HSpacing(2),
                # text entry label
                InputField(
                  Id(:nfsexport),
                  Opt(:hstretch),
                  _("&Remote Directory"),
                  Backup.nfsexport
                ),
                HSpacing(1),
                # push button label
                VBox(
                  Label(""),
                  # Pushbutton label
                  PushButton(Id(:selectexport), _("S&elect..."))
                )
              ),
              VSpacing(0.3)
            )
          ),
          HSpacing(1)
        )
      ),
      VSpacing(0.5),
      # frame label
      Frame(
        _("Archive Type"),
        VBox(
          VSpacing(Opt(:hstretch), 0.5),
          RadioButtonGroup(
            Id(:rbgroup),
            VBox(
              Left(
                RadioButton(
                  Id(:archive),
                  Opt(:notify),
                  _("Create Backup Archive")
                )
              ),
              HBox(
                HSpacing(4.0),
                ComboBox(
                  Id(:type),
                  Opt(:notify),
                  # combo box label
                  _("Archive &Type"),
                  # archive type - combo box item
                  [
                    Item(Id(:tgz), _("tar with tar-gzip subarchives")),
                    # archive type - combo box item
                    Item(Id(:tbz), _("tar with tar-bzip2 subarchives")),
                    # archive type - combo box item
                    Item(Id(:tar), _("tar with tar subarchives")),
                    # archive type - combo box item
                    Item(Id(:stgz), _("tar with star-gzip subarchives")),
                    # archive type - combo box item
                    Item(Id(:stbz), _("tar with star-bzip2 subarchives")),
                    # archive type - combo box item
                    Item(Id(:star), _("tar with star subarchives"))
                  ]
                ),
                HSpacing(3.0),
                VBox(
                  VSpacing(1.0),
                  # push button label
                  PushButton(Id(:opts), _("&Options..."))
                ),
                HStretch()
              ),
              VSpacing(0.5),
              # radiobutton label
              Left(
                RadioButton(
                  Id(:only_list),
                  Opt(:notify),
                  _("Only Create List of Files Found")
                )
              )
            )
          ),
          VSpacing(0.5)
        )
      ),
      VSpacing(0.5)
    ),
    backup_help_archive_settings,
    true,
    true
  )

  update_location_dialog

  Backup.archive_type = :tgz if Backup.archive_type == nil

  # set values
  UI.ChangeWidget(Id(:filename), :Value, Backup.archive_name)
  #    UI::ChangeWidget(`id(`description), `Value, Backup::description);

  if Backup.archive_type != :txt
    UI.ChangeWidget(Id(:type), :Value, Backup.archive_type)
  end
  refresh_widget_status(Backup.archive_type != :txt)

  cont = false
  ret = nil
  id_result = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), "/usr/bin/id -u")
  )

  if Ops.get_string(id_result, "stdout", "") != "0\n" &&
      @root_warning_displayed == false
    # warning popup message
    Popup.Warning(
      _(
        "You are not logged in as root.\n" +
          "Some files can only be read by the user root.\n" +
          "Not all files will be backed up,\n" +
          "so it will not be possible to restore\n" +
          "the system completely later.\n" +
          "\n" +
          "System areas on hard disks can only\n" +
          "be backed up by root.\n"
      )
    )
    @root_warning_displayed = true
  end


  while !cont
    ret = Convert.to_symbol(UI.UserInput)

    if ret == :browse_file
      # TRANSLATORS: explanatory headline for UI::AskForExistingFile pop-up
      new_filename = UI.AskForSaveFileName(
        "",
        "",
        _("Where would you like to store the backup?")
      )
      if new_filename != nil && new_filename != ""
        UI.ChangeWidget(Id(:filename), :Value, new_filename)
      end
      next
    end

    # update dialog (enable/disable widgets)
    update_location_dialog

    Backup.nfsserver = Convert.to_string(
      UI.QueryWidget(Id(:nfsserver), :Value)
    )
    Backup.nfsexport = Convert.to_string(
      UI.QueryWidget(Id(:nfsexport), :Value)
    )

    Backup.archive_name = Convert.to_string(
      UI.QueryWidget(Id(:filename), :Value)
    )
    type = Convert.to_symbol(UI.QueryWidget(Id(:rbgroup), :CurrentButton)) == :only_list ?
      :txt :
      Convert.to_symbol(UI.QueryWidget(Id(:type), :Value))

    # add extension ".tar" if it is missing
    if type != :txt
      Backup.archive_name = AddMissingExtension(Backup.archive_name, ".tar")
      UI.ChangeWidget(Id(:filename), :Value, Backup.archive_name)
    end

    if ret == :type
      stat = Convert.to_symbol(UI.QueryWidget(Id(:type), :Value)) != :txt

      UI.ChangeWidget(Id(:opts), :Enabled, stat)
    else
      if ret == :next
        # check NFS server and export name
        if Convert.to_boolean(UI.QueryWidget(Id(:nfs), :Value)) == true
          if Builtins.size(
              Convert.to_string(UI.QueryWidget(Id(:nfsserver), :Value))
            ) == 0
            Popup.Warning(
              _(
                "A server name is required.\nEnter the server name to use.\n"
              )
            )
            next
          elsif Builtins.size(
              Convert.to_string(UI.QueryWidget(Id(:nfsexport), :Value))
            ) == 0
            Popup.Warning(
              _(
                "A remote directory name is required.\nEnter the directory name to use.\n"
              )
            )
            next
          end
        end

        # check if star is installed for star subarchive type
        if (type == :star || type == :stgz || type == :stbz) &&
            Ops.less_than(
              Convert.to_integer(
                SCR.Read(path(".target.size"), "/usr/bin/star")
              ),
              0
            )
          InstallNeededPackages(["star"])
        end

        Builtins.y2milestone("Multivolume: %1", Backup.multi_volume)

        if Builtins.size(Backup.archive_name) == 0
          # warning popup message
          Popup.Warning(
            _(
              "An archive filename is required.\nEnter the filename to use.\n"
            )
          )
          cont = false
          next
        end

        if Builtins.substring(Backup.archive_name, 0, 1) != "/" &&
            Backup.target_type == :file
          # warning popup message
          Popup.Warning(
            _(
              "Enter the archive filename with\nits absolute path, as in /tmp/backup.tar."
            )
          )
          cont = false
          next
        end

        if Builtins.regexpmatch(Backup.archive_name, "/")
          dir = Builtins.substring(
            Backup.archive_name,
            0,
            Builtins.findlastof(Backup.archive_name, "/")
          )

          # testing if the directory exists or if it is possible to create it
          error_message = IsPossibleToCreateDirectoryOrExists(dir)
          if error_message != ""
            Popup.Error(error_message)

            cont = false
            next
          end
        end

        if !Backup.multi_volume
          # check if archive can be (over)written
          cont = WriteArchive()

          if cont == nil
            # error popup message - NFS mount failed
            Popup.Error(_("Cannot mount the selected NFS share."))

            cont = false
          end
        elsif Backup.multi_volume # test if some volume part exists
          # list directory content
          dir = Builtins.substring(
            Backup.archive_name,
            0,
            Builtins.findlastof(Backup.archive_name, "/")
          )
          fn = Builtins.substring(
            Backup.archive_name,
            Ops.add(Builtins.findlastof(Backup.archive_name, "/"), 1)
          )

          Builtins.y2debug("dir: %1", dir)
          Builtins.y2debug("file: %1", fn)

          ls = Convert.convert(
            SCR.Read(path(".target.dir"), dir),
            :from => "any",
            :to   => "list <string>"
          )

          matched = false

          conflict_file = ""

          # check if some volume part exists
          Builtins.foreach(ls) do |f|
            if Builtins.regexpmatch(f, Ops.add("d*_", fn)) == true
              if matched == false
                matched = true
                conflict_file = f
              end
            end
          end 


          Builtins.y2debug("found volume part: %1", conflict_file)

          # display question
          if matched == true
            # For translators %1 is volume file name (e.g. /tmp/01_backup.tar)
            cont = Popup.YesNo(
              Builtins.sformat(
                _(
                  "The existing file %1 could become part of new volume set and be overwritten.\nReally continue?"
                ),
                Ops.add(Ops.add(dir, "/"), conflict_file)
              )
            )
          else
            cont = true
          end
        else
          cont = true
        end
      elsif ret == :back
        # backup profile is a new profile, just created
        if Backup.profile_is_new_one
          ret = :back
          cont = AbortNewProfileCreation(Backup.selected_profile)
        else
          ret = :back
          cont = true
        end
      elsif ret == :abort || ret == :cancel
        ret = :abort
        cont = AbortConfirmation(:changed)
      elsif ret == :only_list || ret == :archive
        refresh_widget_status(ret == :archive)
      elsif ret == :file || ret == :nfs
        update_location_dialog

        Backup.target_type = ret
      # select NFS server
      elsif ret == :selecthost
        srv = NetworkPopup.NFSServer(Backup.nfsserver)

        if srv != nil
          UI.ChangeWidget(Id(:nfsserver), :Value, srv)
          Backup.nfsserver = srv
        end
      # select NFS export
      elsif ret == :selectexport
        server = Convert.to_string(UI.QueryWidget(Id(:nfsserver), :Value))

        if Ops.greater_than(Builtins.size(server), 0)
          exp = NetworkPopup.NFSExport(server, Backup.nfsexport)

          if exp != nil
            UI.ChangeWidget(Id(:nfsexport), :Value, exp)
            Backup.nfsexport = exp
          end
        else
          Popup.Message(_("Enter a server name."))
        end
      else
        cont = true
      end
    end
  end

  # get values
  Backup.archive_type = Convert.to_symbol(
    UI.QueryWidget(Id(:rbgroup), :CurrentButton)
  ) == :archive ?
    Convert.to_symbol(UI.QueryWidget(Id(:type), :Value)) :
    :txt

  if ret == :opts
    if Builtins.contains(
        [:tar, :tgz, :tbz, :stgz, :stbz, :star],
        Backup.archive_type
      )
      ret = :tar_opt
    end
  end

  @last_input = ret
  ret
end

- (Symbol) ArchivingDialog

Display progress of creating archive

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
# File '../../src/include/backup/ui.rb', line 3237

def ArchivingDialog
  # Creating Progress Bar/Steps
  CreateProgress_ArchivingDialog()

  ret = nil

  progress_count = Ops.add(@selected_pkg_num, @selected_files_num)
  progress_count = 1 if Ops.less_than(progress_count, 1)

  Builtins.y2milestone(
    "Number of selected packages: %1, selected files: %2",
    @selected_pkg_num,
    @selected_files_num
  )

  @file_list_stored = Ops.get_boolean(
    @selected_info,
    "file_list_stored",
    false
  )
  tmpfile_list = Ops.add(
    Convert.to_string(SCR.Read(path(".target.tmpdir"))),
    "/filelist"
  )

  # store comment to file
  tmpfile_comment = Ops.add(
    Convert.to_string(SCR.Read(path(".target.tmpdir"))),
    "/comment"
  )
  @comment_stored = SCR.Write(
    path(".target.string"),
    tmpfile_comment,
    Backup.description
  )

  Builtins.y2debug("%1", "Comment stored to file")
  Progress.NextStep

  if !@comment_stored
    Report.Warning(
      Builtins.sformat(
        _("Cannot write comment to file %1."),
        tmpfile_comment
      )
    )
  end

  @added_files = 0

  # prepare start
  Backup.PrepareBackup

  script_out = []

  @archived_num = 0
  tar_running = false

  id_storing_list = "Storing list"
  id_list_stored = "File list stored"

  @e2image_results = []
  @stored_ptables = []
  @created_archive_files = []

  last_out = nil
  system_stage_changed = false

  Builtins.y2milestone("Creating archive...")

  @backup_PID = Convert.to_integer(
    SCR.Execute(
      path(".process.start_shell"),
      Builtins.sformat(
        "%1 %2",
        Backup.script_create_archive,
        Backup.get_archive_script_parameters(tmpfile_list, tmpfile_comment)
      ),
      { "C_locale" => true }
    )
  )
  started = @backup_PID != nil && Ops.greater_than(@backup_PID, 0)

  if !started
    # error popup message
    Report.Error(
      _("Could not start archiving script.\nAborting the backup.\n")
    )
    return :abort
  end

  Backup.just_creating_archive = true

  @line = "-- just -- started --"
  # start while
  #
  # .running might return false
  # but there still might be some buffer left
  while Convert.to_boolean(SCR.Read(path(".process.running"), @backup_PID)) ||
      !Convert.to_boolean(
        SCR.Read(path(".process.buffer_empty"), @backup_PID)
      )
    @line = Convert.to_string(
      SCR.Read(path(".process.read_line"), @backup_PID)
    )
    next if @line == nil

    script_out = [@line]

    # script returned some lines, no check the free space
    if Ops.greater_than(Builtins.size(script_out), 0)
      @waiting_without_output = 0
    end

    while Ops.greater_than(Builtins.size(script_out), 0)
      line = Ops.get(script_out, 0) # read line
      script_out = Builtins.remove(script_out, 0) # remove line

      Builtins.y2debug("Archive script output: %1", line)

      if Backup.archive_type == :txt
        if line != id_storing_list
          if line == id_list_stored
            @stored_list = true

            Builtins.y2debug("List of files stored")
            Progress.NextStep
          else
            Builtins.y2warning(
              "Unknown output from archive script: %1",
              line
            )
          end
        end
      else
        if tar_running
          if Builtins.substring(line, 0, Builtins.size(@id_tar_exit)) == @id_tar_exit
            Builtins.y2milestone(
              "Tar exit: %1\nErr: %2",
              line,
              SCR.Read(path(".process.read_stderr"), @backup_PID)
            )

            @tar_result = Builtins.tointeger(
              Builtins.substring(line, Builtins.size(@id_tar_exit))
            )
          else
            if Builtins.substring(line, 0, Builtins.size(@id_new_volume)) == @id_new_volume
              vol_name = Builtins.substring(
                line,
                Builtins.size(@id_new_volume)
              )

              # update NFS archive name
              if Backup.target_type == :nfs
                Builtins.y2milestone(
                  "vol_name: %1, nfsmount: %2, size(nfsmount):%3",
                  vol_name,
                  Backup.nfsmount,
                  Builtins.size(Backup.nfsmount)
                )
                location = Builtins.substring(
                  vol_name,
                  Builtins.size(Backup.nfsmount)
                )
                vol_name = Ops.add(
                  Ops.add(Ops.add(Backup.nfsserver, ":"), Backup.nfsexport),
                  location
                )
                Builtins.y2debug("Volume name: %1", vol_name)
              end

              @created_archive_files = Builtins.add(
                @created_archive_files,
                vol_name
              )
            elsif line == @id_creating_target
              Builtins.y2debug("Creating target archive")
              Progress.NextStage
            elsif Builtins.substring(
                line,
                0,
                Builtins.size(@id_not_readable)
              ) == @id_not_readable
              @not_readable_files = Builtins.add(
                @not_readable_files,
                Builtins.substring(line, Builtins.size(@id_not_readable))
              )
              Builtins.y2warning(
                "File %1 can not be read.",
                Builtins.substring(line, Builtins.size(@id_not_readable))
              )
              Progress.NextStep
            else
              if Backup.multi_volume
                if last_out != line
                  @archived_num = Ops.add(@archived_num, 1)
                  last_out = line
                end
              else
                @archived_num = Ops.add(@archived_num, 1)
                Builtins.y2debug("File: %1 added to archive", line)
              end

              @this_file_stage = Builtins.tointeger(
                Ops.divide(
                  Ops.multiply(@archived_num, @stages_for_files),
                  progress_count
                )
              )
              if Ops.greater_than(@this_file_stage, @last_file_stage)
                Progress.NextStep
                @last_file_stage = @this_file_stage
              end
            end
          end
        else
          if Builtins.substring(line, 0, Builtins.size(@id_hostname)) == @id_hostname
            tmp = Builtins.substring(line, Builtins.size(@id_hostname))
            @hostname_stored = tmp == @id_ok

            Builtins.y2debug("Hostaneme stored: %1", @hostname_stored)
            Progress.NextStage
          else
            if Builtins.substring(line, 0, Builtins.size(@id_date)) == @id_date
              tmp = Builtins.substring(line, Builtins.size(@id_date))
              @date_stored = tmp == @id_ok

              Builtins.y2debug("Date stored: %1", @date_stored)
              Progress.NextStep
            else
              if Builtins.substring(line, 0, Builtins.size(@id_partab)) == @id_partab
                if !system_stage_changed
                  Progress.NextStage
                  system_stage_changed = true
                else
                  Progress.NextStep
                end
              else
                if Builtins.substring(line, 0, Builtins.size(@id_ptstored)) == @id_ptstored
                  part_name = Builtins.substring(
                    line,
                    Builtins.size(@id_ptstored)
                  )

                  @added_files = Ops.add(@added_files, 2)
                  @stored_ptables = Builtins.add(@stored_ptables, part_name)
                else
                  if Builtins.substring(
                      line,
                      0,
                      Builtins.size(@id_not_stored)
                    ) == @id_not_stored
                    Builtins.y2warning("PTble was not stored: %1", line)
                    @failed_ptables = Builtins.add(
                      @failed_ptables,
                      Builtins.substring(
                        line,
                        Builtins.size(@id_not_stored)
                      )
                    )
                  else
                    if Builtins.substring(line, 0, Builtins.size(@id_ext2)) == @id_ext2
                      if !system_stage_changed
                        Progress.NextStage
                        system_stage_changed = true
                      end
                    else
                      if line == @id_archive
                        tar_running = true
                        Builtins.y2debug("Creating archive")

                        # set next stage if system backup was selected, but no partition table or ext2 image was selected
                        if Backup.system && !system_stage_changed
                          Progress.NextStage
                          system_stage_changed = true
                        end

                        Progress.NextStage
                      else
                        if line == @id_ok || line == @id_failed
                          @e2image_results = Builtins.add(
                            @e2image_results,
                            line == @id_ok
                          )
                        else
                          if Builtins.substring(
                              line,
                              0,
                              Builtins.size(@id_not_readable)
                            ) == @id_not_readable
                            @not_readable_files = Builtins.add(
                              @not_readable_files,
                              Builtins.substring(
                                line,
                                Builtins.size(@id_not_readable)
                              )
                            )
                            Builtins.y2warning(
                              "File %1 can not be read.",
                              Builtins.substring(
                                line,
                                Builtins.size(@id_not_readable)
                              )
                            )
                            Progress.NextStep
                          else
                            if line == @id_pt_read
                              @read_ptables_info = true
                            else
                              if Builtins.substring(
                                  line,
                                  0,
                                  Builtins.size(@id_storing_installed_pkgs)
                                ) == @id_storing_installed_pkgs
                                Builtins.y2milestone(
                                  @id_storing_installed_pkgs
                                )
                              else
                                if Builtins.substring(
                                    line,
                                    0,
                                    Builtins.size(@id_storedpkg)
                                  ) == @id_storedpkg
                                  @packages_list_stored = Builtins.substring(
                                    line,
                                    Builtins.size(@id_storedpkg)
                                  ) == @id_ok
                                  Builtins.y2debug(
                                    "Stored list of installed packages %1",
                                    @packages_list_stored
                                  )
                                  Progress.NextStep
                                else
                                  Builtins.y2warning(
                                    "Unknown output from archive script: %1",
                                    line
                                  )
                                end
                              end
                            end
                          end
                        end
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end

      if Backup.cron_mode
        ret = nil
        if Convert.to_boolean(
            SCR.Read(path(".process.buffer_empty"), @backup_PID)
          ) == true
          Builtins.sleep(@wait_time)
        end
        CheckFreeSpace()
      else
        ret = waitForUserOrProcess(@wait_time, :changed)
        CheckFreeSpace()
      end

      # evaluetest the free space, asks user when there not enough free space
      # changes ret symbol when needed
      ret = EvaluateFreeSpace(ret)

      if ret != nil
        # free resources when backup is finished
        Backup.PostBackup
        return ret
      end
    end
  end
  # end while

  Builtins.y2milestone(
    "DEBUG: running %1",
    Convert.to_boolean(SCR.Read(path(".process.running"), @backup_PID))
  )
  Builtins.y2milestone(
    "DEBUG: empty %1",
    Convert.to_boolean(SCR.Read(path(".process.buffer_empty"), @backup_PID))
  )

  Backup.selected_files = {}

  if ret == :abort
    # remove incomplete backup archive file
    SCR.Execute(path(".target.remove"), Backup.archive_name)
  else
    # write autoinstallation profile
    Progress.NextStage

    @profilewritten = Backup.WriteProfile(@created_archive_files)
  end

  # free resources when backup is finished
  Backup.PostBackup
  :next
end

- (String) AskNewProfileName(current_name)

Allow user to enter a new profile name. If the profile already exists, it allows to replace it. Allows to rename current profile if current_name in not nil or "".

Parameters:

  • string

    current name of the profile

Returns:

  • (String)

    the name for the new profile, “” for cancel



3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
# File '../../src/include/backup/ui.rb', line 3648

def AskNewProfileName(current_name)
  # Translators: text of a popup dialog
  dialog_text = _("Enter a name for the new profile.")
  # renaming the current profile
  if current_name != nil && current_name != ""
    # TRANSLATORS: text of a popup dialog, %1 is a profile name to be renamed
    dialog_text = Builtins.sformat(
      _("Enter a new name for the %1 profile."),
      current_name
    )
  end
  # double-quote in name breaks backup in several places
  new_name = ShowEditDialog(dialog_text, "", nil, ["\""])

  while Ops.get_symbol(new_name, "clicked") == :ok &&
      Ops.get(Backup.backup_profiles, Ops.get_string(new_name, "text")) != nil
    # Translators: error popup, %1 is profile name
    if !Popup.YesNo(
        Builtins.sformat(
          _("A profile %1 already exists.\nReplace the existing profile?\n"),
          Ops.get_string(new_name, "text", "")
        )
      )
      # double-quote in name breaks backup at several places
      new_name = ShowEditDialog(
        _("Enter a name for the new profile."),
        "",
        nil,
        ["\""]
      )
    else
      # yes, do replace
      return Ops.get_string(new_name, "text", "")
    end
  end

  if Ops.get_symbol(new_name, "clicked") == :ok
    return Ops.get_string(new_name, "text", "")
  else
    return ""
  end
end

- (Symbol) BackupDialog

Dialog for setting backup options

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
# File '../../src/include/backup/ui.rb', line 1454

def BackupDialog
  # do not allow manual changes of configuration
  return :next2 if Backup.no_interactive

  # dialog header
  Wizard.SetContents(
    _("Backup Options"),
    VBox(
      VSpacing(0.5),
      #rwalter consider whether this frame and the next should be eliminated to simplify the dialog
      # frame label
      Frame(
        _("File Selection"),
        VBox(
          VSpacing(0.3),
          # check box label
          Left(
            CheckBox(
              Id(:search),
              Opt(:notify),
              _("&Back Up Files Not Belonging to Any Package"),
              Backup.do_search
            )
          ),
          # check box label
          Left(
            CheckBox(
              Id(:all_rpms_content),
              Opt(:notify),
              _("Back up Content of &All Packages"),
              Backup.backup_all_rpms_content
            )
          ),
          VSpacing(0.3),
          # check box label
          Left(
            CheckBox(
              Id(:display),
              _("Display List of Files Before &Creating Archive"),
              Backup.display
            )
          ),
          VSpacing(0.3)
        )
      ),
      VSpacing(0.5),
      # frame label
      Frame(
        _("Search Options"),
        VBox(
          VSpacing(0.3),
          # frame label
          Left(
            CheckBox(
              Id(:md5_check),
              _("Check MD&5 Sum instead of Time or Size"),
              Backup.do_md5_test
            )
          ),
          VSpacing(0.3)
        )
      ),
      VSpacing(0.3),
      # multi line widget label
      MultiLineEdit(
        Id(:description),
        _("Archive &Description"),
        Backup.description
      ),
      VSpacing(0.3),
      PushButton(Id(:xpert), _("E&xpert...")),
      VSpacing(0.5)
    ),
    backup_help_backup_setting,
    true,
    true
  )

  ret = nil

  while ret != :next && ret != :abort && ret != :back && ret != :xpert
    ret = Convert.to_symbol(UI.UserInput)

    if ret == :abort || ret == :cancel
      ret = :abort
      if !AbortConfirmation(:changed)
        ret = nil # not confirmed, unset ret
      end
    end
  end

  # get values
  Backup.backup_all_rpms_content = Convert.to_boolean(
    UI.QueryWidget(Id(:all_rpms_content), :Value)
  )
  Backup.do_search = Convert.to_boolean(UI.QueryWidget(Id(:search), :Value))
  Backup.display = Convert.to_boolean(UI.QueryWidget(Id(:display), :Value))
  Backup.do_md5_test = Convert.to_boolean(
    UI.QueryWidget(Id(:md5_check), :Value)
  )
  Backup.description = Convert.to_string(
    UI.QueryWidget(Id(:description), :Value)
  )

  ret
end

- (Object) CallPrePostBackupScripts(scripts_to_call, dialog_caption)



2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
# File '../../src/include/backup/ui.rb', line 2323

def CallPrePostBackupScripts(scripts_to_call, dialog_caption)
  scripts_to_call = deep_copy(scripts_to_call)
  Builtins.y2milestone("Running scripts: %1", scripts_to_call)

  Wizard.SetContents(
    dialog_caption,
    VBox(
      LogView(Id("script_log"), _("User-Defined Scripts Output"), 18, 1024)
    ),
    " ",
    false,
    false
  )
  UI.RecalcLayout

  dialog_ret = true
  ui_wait_time = 100

  Builtins.foreach(scripts_to_call) do |script_to_call|
    script = Ops.get_string(script_to_call, "path", "")
    if script == nil || script == ""
      Builtins.y2error("Cannot run script %1", script_to_call)
      next
    end
    Builtins.y2milestone("Running script %1", script)
    UI.ChangeWidget(
      Id("script_log"),
      :LastLine,
      Builtins.sformat(_("Starting script %1...\n"), script)
    )
    script_PID = Convert.to_integer(
      SCR.Execute(
        path(".process.start_shell"),
        script,
        { "C_locale" => true }
      )
    )
    Builtins.y2milestone("Script started with PID %1", script_PID)
    if script_PID == nil || script_PID == 0
      Builtins.y2error("Cannot start script %1", script)
      Report.Error(Builtins.sformat(_("Cannot start %1 script\n"), script))
      next
    end
    ret = nil
    line = nil
    errline = nil
    # something might be still in the buffer(s)
    last_line_non_empty = nil
    while Convert.to_boolean(SCR.Read(path(".process.running"), script_PID)) ||
        !Convert.to_boolean(
          SCR.Read(path(".process.buffer_empty"), script_PID)
        ) ||
        last_line_non_empty == true
      last_line_non_empty = false

      line = Convert.to_string(
        SCR.Read(path(".process.read_line"), script_PID)
      )
      if line != nil
        UI.ChangeWidget(Id("script_log"), :LastLine, Ops.add(line, "\n"))
        last_line_non_empty = true
      end

      errline = Convert.to_string(
        SCR.Read(path(".process.read_line_stderr"), script_PID)
      )
      if errline != nil
        UI.ChangeWidget(Id("script_log"), :LastLine, Ops.add(errline, "\n"))
        last_line_non_empty = true
      end

      if Backup.cron_mode
        if Convert.to_boolean(
            SCR.Read(path(".process.buffer_empty"), @backup_PID)
          ) == true
          Builtins.sleep(@wait_time)
        end
      else
        ret = UI.PollInput

        if ret == :abort || ret == :cancel
          Builtins.y2warning("Abort pressed")
          ret = :abort

          if AbortConfirmation(:changed)
            SCR.Execute(path(".process.kill"), script_PID)
            dialog_ret = false
            break
          end
        end

        if line == nil && errline == nil
          if Convert.to_boolean(
              SCR.Read(path(".process.buffer_empty"), @backup_PID)
            ) == true
            Builtins.sleep(ui_wait_time)
          end
        end
      end
    end
    SCR.Execute(path(".process.release"), script_PID)
    UI.ChangeWidget(Id("script_log"), :LastLine, "\n\n")
    raise Break if dialog_ret != true
  end

  dialog_ret
end

- (Object) CallScriptsAfterBackup



2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
# File '../../src/include/backup/ui.rb', line 2449

def CallScriptsAfterBackup
  scripts_to_call = Builtins.filter(Backup.backup_helper_scripts) do |one_script|
    Ops.get_string(one_script, "type", "before") != "before"
  end

  if Ops.less_than(Builtins.size(scripts_to_call), 1)
    Builtins.y2milestone("No 'after' scripts to call...")
    return :next
  end

  if !CallPrePostBackupScripts(scripts_to_call, _("User-Defined Scripts"))
    Builtins.y2milestone("Aborting the backup")
    return :abort
  end

  :next
end

- (Object) CallScriptsBeforeBackup



2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
# File '../../src/include/backup/ui.rb', line 2431

def CallScriptsBeforeBackup
  scripts_to_call = Builtins.filter(Backup.backup_helper_scripts) do |one_script|
    Ops.get_string(one_script, "type", "before") == "before"
  end

  if Ops.less_than(Builtins.size(scripts_to_call), 1)
    Builtins.y2milestone("No 'before' scripts to call...")
    return :next
  end

  if !CallPrePostBackupScripts(scripts_to_call, _("User-Defined Scripts"))
    Builtins.y2milestone("Aborting the backup")
    return :abort
  end

  :next
end

- (Boolean) check_space(found_size, tmp_dir, target_dir, target_type)

Check available free space and decide whether archive will fit

Parameters:

  • found_size (Fixnum)

    total size of found files in bytes

  • tmp_dir (String)

    selected temporary directory

  • target_dir (String)

    target archive directory

  • target_type (Symbol)

    target archive type

Returns:

  • (Boolean)

    true = archive fits, false = it doesn't fit, nil = may not fit (compression is used, there is no guarantee that archive will fit but it can be possible if compression ratio will be enough high



1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
# File '../../src/include/backup/ui.rb', line 1917

def check_space(found_size, tmp_dir, target_dir, target_type)
  # required size in 1024-blocks
  found_size = Ops.divide(found_size, 1024)

  available_tmp = get_free_space(tmp_dir)
  available_target = get_free_space(target_dir)

  if Builtins.size(available_target) == 0 ||
      Builtins.size(available_tmp) == 0
    return true
  end

  fits = true

  # temporary and target directories are same
  if Ops.get_string(available_tmp, "device") ==
      Ops.get_string(available_target, "device")
    free = Ops.get_integer(available_target, "free", 0)
    # required space is doubled (tmpdir + target_dir)
    required = Ops.add(found_size, found_size)

    fits = is_space(required, free, target_type)

    return false if display_free_space_warning(fits, target_dir) == false
  else
    # temporary location and target directories are different
    fits = is_space(
      found_size,
      Ops.get_integer(available_target, "free", 0),
      target_type
    )
    return false if display_free_space_warning(fits, target_dir) == false

    fits = is_space(
      found_size,
      Ops.get_integer(available_tmp, "free", 0),
      target_type
    )
    return false if display_free_space_warning(fits, tmp_dir) == false
  end

  true
end

- (Object) CheckFreeSpace

Function periodically checks the free space



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File '../../src/include/backup/ui.rb', line 163

def CheckFreeSpace
  @waiting_without_output = Ops.add(@waiting_without_output, @wait_time)

  if Ops.greater_or_equal(@waiting_without_output, @max_wait_without_output)
    # null the waiting time now
    @waiting_without_output = 0
    return if Ops.less_than(Builtins.time, @next_time_check)
    # next space check - not before time() + wait_sec_check
    @next_time_check = Ops.add(Builtins.time, @wait_sec_check)

    # null the free space flags
    @waiting_without_output = 0
    @enough_free_space_tmp = true
    @enough_free_space_target = true

    # check the tmpdir free space
    free_tmp = Convert.to_integer(
      SCR.Read(path(".system.freespace"), Backup.tmp_dir)
    )
    if free_tmp != -1 && Ops.less_than(free_tmp, @min_free_space)
      @enough_free_space_tmp = false
    end

    # check the targetdir free space
    free_target = Convert.to_integer(
      SCR.Read(path(".system.freespace"), Backup.target_dir)
    )
    if free_target != -1 && Ops.less_than(free_target, @min_free_space)
      @enough_free_space_target = false
    end
  end

  nil
end

- (Symbol) ConstraintDialog

Dialog for setting excluded directories, file systems and reg. expressions

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
# File '../../src/include/backup/ui.rb', line 5503

def ConstraintDialog
  ret = InitConstraintDialog()
  return ret if ret != nil

  foundfilesystems = Convert.convert(
    SCR.Read(path(".proc.filesystems")),
    :from => "any",
    :to   => "map <string, string>"
  )
  all_fss = []

  if Ops.greater_than(Builtins.size(foundfilesystems), 0)
    Builtins.foreach(foundfilesystems) do |fsname, flag|
      all_fss = Builtins.add(all_fss, fsname)
    end
  end

  curr = nil
  type = nil
  value = nil
  line = nil

  # --> while
  while ret != :next && ret != :back && ret != :abort
    ret = Convert.to_symbol(UI.UserInput)
    Builtins.y2milestone("Ret: %1", ret)

    # Managing Exclude items
    if Builtins.contains([:edit, :delete, :dir, :fs, :regexp], ret)
      curr = Convert.to_integer(UI.QueryWidget(Id(:const), :CurrentItem))
      if curr != nil
        Builtins.y2milestone("current item: %1", curr)
        line = Convert.to_term(
          UI.QueryWidget(Id(:const), term(:Item, curr))
        )
        Builtins.y2milestone("current option: %1", line)

        value = Ops.get_string(line, 1)
        Builtins.y2milestone("value: %1", value)

        type = Ops.get_string(line, 2)
        Builtins.y2milestone("type: %1", type)
      end 
      # Managing Include items
    elsif Builtins.contains(
        [:add_include, :edit_include, :delete_include],
        ret
      )
      value = Convert.to_string(UI.QueryWidget(Id(:include), :CurrentItem))
      Builtins.y2milestone("value: %1", value)
    end

    # Exclude item - delete
    if ret == :delete && type != nil && value != nil
      ExcludeItemDelete(value, type) 
      # Exclude item - edit
    elsif ret == :edit && type != nil && value != nil
      all_fss_ref = arg_ref(all_fss)
      ExcludeItemEdit(value, type, all_fss_ref)
      all_fss = all_fss_ref.value 
      # Exclude item - add regexp
    elsif ret == :regexp
      AddExcludeItem_Regexp() 
      # Exclude item - add directory
    elsif ret == :dir
      AddExcludeItem_Dir() 
      # Exclude item - add filesystem
    elsif ret == :fs
      all_fss_ref = arg_ref(all_fss)
      AddExcludeItem_Fs(all_fss_ref)
      all_fss = all_fss_ref.value 
      # Include Directory - add
    elsif ret == :add_include
      AddIncludeItem() 
      # Include Directory - delete
    elsif ret == :delete_include
      DeleteIncludeItem(value) 
      # Include Directory - edit
    elsif ret == :edit_include
      EditIncludeItem(value) 
      # Unknown
    elsif ret != :next && ret != :back && ret != :abort
      Builtins.y2error("Unknown ret %1", ret)
    end
  end
  # <-- while

  if Backup.selected_profile != nil
    # Restore 'next' button
    Wizard.RestoreNextButton
  end

  ret
end

- (Object) CreateProgress_ArchivingDialog



3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
# File '../../src/include/backup/ui.rb', line 3148

def CreateProgress_ArchivingDialog
  # create Progress bar

  # progress stage
  stages1 = [_("Store host information")]
  # progress step
  stages2 = [_("Storing host information...")]

  @selected_info = Backup.MapFilesToString
  @selected_files_num = Ops.get_integer(@selected_info, "sel_files", 0)
  @selected_pkg_num = Ops.get_integer(@selected_info, "sel_packages", 0)

  # number of steps = number of selected files + nuber of selected packages (selected files added below)
  #			+ 6 files (comment, hostname, date, files, installed_packages, packages_info)
  #			+ 3 steps (comment, hostname, installed PRMs)
  #			+ 3 stages (storing files, creating package archives, creating big archive)
  num_stages = 12

  if Backup.system
    # progress stage
    stages1 = Builtins.add(stages1, _("Create system area backup"))
    # progress step
    stages2 = Builtins.add(stages2, _("Creating system area backup..."))

    num_stages = Ops.add(num_stages, 1) if Backup.backup_pt

    num_stages = Ops.add(num_stages, Builtins.size(Backup.ext2_backup))

    num_stages = Ops.add(num_stages, 1) # System backup stage
  end

  if Backup.multi_volume
    num_stages = Ops.add(num_stages, 1) # tar prints Volume label if multi volume selected, but only at first volume
  end

  if Backup.do_search
    num_stages = Ops.add(num_stages, 1) # add NOPACKAGE archive step
  end

  if Ops.greater_than(Builtins.size(Backup.complete_backup), 0)
    num_stages = Ops.add(num_stages, 1) # add complete list step
  end

  @stages_for_files = Ops.multiply(num_stages, 9)

  num_stages = Ops.add(num_stages, @stages_for_files)
  # last file-stage is 0%
  @last_file_stage = 0
  @this_file_stage = 0

  # progress stage
  stages1 = Builtins.add(stages1, _("Create package archives"))
  # progress stage
  stages1 = Builtins.add(stages1, _("Create target archive"))

  # progress step
  stages2 = Builtins.add(stages2, _("Creating package archives..."))
  # progress step
  stages2 = Builtins.add(stages2, _("Creating target archive..."))

  # progress stage
  stages1 = Builtins.add(stages1, _("Write autoinstallation profile"))
  # progress step
  stages2 = Builtins.add(stages1, _("Writing autoinstallation profile..."))

  if Backup.cron_mode == true
    Progress.set(false)
  else
    Builtins.y2milestone(
      "Creating progress dialog with %1 steps",
      num_stages
    )
    Progress.New(
      # progress
      _("Creating Archive"),
      " ",
      num_stages,
      stages1,
      stages2,
      backup_help_creating_archive
    )
  end

  nil
end

- (Symbol) CronDialog

Display dialog for automatic backup - set time when backup module will be started at background with current selected profile.

Returns:

  • (Symbol)

    User input value



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
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
562
563
564
565
566
567
568
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
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
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File '../../src/include/backup/ui.rb', line 482

def CronDialog
  # read current settings from profile
  current_profile = Builtins.eval(
    Ops.get(Backup.backup_profiles, Backup.selected_profile, {})
  )
  current_settings = Builtins.eval(
    Ops.get_map(current_profile, :cron_settings, {})
  )

  # current day settings
  cday = Ops.get_symbol(current_settings, "every", :none)
  cweekday = Ops.get_integer(current_settings, "weekday", 0)

  items = []
  # create combo box content
  Builtins.foreach(Backup.daynames) do |num, name|
    items = Builtins.add(items, Item(Id(num), name, cweekday == num))
  end 


  # dialog header - %1 is profile name
  Wizard.SetContents(
    Builtins.sformat(
      _("Automatic Backup Options for Profile %1"),
      Backup.selected_profile
    ),
    VBox(
      VSpacing(0.5),
      # check box label
      Left(
        CheckBox(
          Id(:enabled),
          Opt(:notify),
          _("&Start Backup Automatically"),
          Ops.get_boolean(current_settings, "auto", false)
        )
      ),
      VSpacing(0.45),
      HBox(
        HSpacing(4),
        VBox(
          # frame label
          #rwalter please remove this frame
          #`Frame(_("Frequency"), as you wish
          VBox(
            VSpacing(0.45),
            HBox(
              HSpacing(1),
              ComboBox(
                Id(:time),
                Opt(:notify),
                _("&Frequency"),
                [
                  Item(Id(:day), _("Daily"), cday == :day),
                  Item(Id(:week), _("Weekly"), cday == :week),
                  Item(Id(:month), _("Monthly"), cday == :month)
                ]
              ),
              HStretch()
            ),
            VSpacing(0.45)
          ), #)
          #),
          VSpacing(0.45),
          # frame label
          Frame(
            _("Backup Start Time"),
            VBox(
              VSpacing(0.45),
              HBox(
                HSpacing(1),
                # combo box label
                ComboBox(Id(:weekday), _("Day of the &Week"), items),
                HSpacing(2),
                # integer field widget label
                IntField(
                  Id(:day),
                  _("&Day of the Month"),
                  1,
                  31,
                  Ops.get_integer(current_settings, "day", 1)
                ),
                HStretch()
              ),
              VSpacing(0.45),
              HBox(
                HSpacing(1),
                # integer field widget label
                IntField(
                  Id(:hour),
                  _("&Hour"),
                  0,
                  23,
                  Ops.get_integer(current_settings, "hour", 0)
                ),
                HSpacing(2),
                # integer field widget label
                IntField(
                  Id(:minute),
                  _("&Minute"),
                  0,
                  59,
                  Ops.get_integer(current_settings, "minute", 0)
                ),
                HStretch()
              ),
              VSpacing(0.45)
            )
          ),
          VSpacing(0.45),
          #rwalter we can probably do without this one too.
          #`Frame(_("Other Settings"), well, let's see
          VBox(
            VSpacing(0.45),
            HBox(
              HSpacing(1),
              # integer field widget label
              IntField(
                Id(:old),
                _("Ma&ximum Number of Old Full Backups"),
                0,
                100,
                Ops.get_integer(current_settings, "old", 3)
              ),
              HStretch()
            ),
            VSpacing(0.45),
            # Checkbox label
            Left(
              CheckBox(
                Id(:mail),
                _("S&end Summary Mail to User root"),
                Backup.mail_summary
              )
            ),
            VSpacing(0.45)
          )
        ),
        HSpacing(2)
      )
    ),
    backup_help_cron_dialog,
    true,
    true
  )

  # replace 'Next' button with 'Ok'
  Wizard.SetNextButton(:next, Label.OKButton)
  UI.SetFocus(Id(:next))

  # set initial widget states
  update_cron_dialog

  ret = Convert.to_symbol(UI.UserInput)

  while !Builtins.contains([:abort, :cancel, :back, :next], ret)
    update_cron_dialog
    ret = Convert.to_symbol(UI.UserInput)
  end

  if ret == :cancel
    ret = :abort
  elsif ret == :next
    # store setting to the selected profile
    if Backup.selected_profile != nil
      cron_changed = Ops.get(current_settings, "auto") !=
        UI.QueryWidget(Id(:enabled), :Value) ||
        Ops.get(current_settings, "every") !=
          UI.QueryWidget(Id(:time), :Value) ||
        Ops.get(current_settings, "weekday") !=
          UI.QueryWidget(Id(:weekday), :Value) ||
        Ops.get(current_settings, "day") != UI.QueryWidget(Id(:day), :Value) ||
        Ops.get(current_settings, "hour") !=
          UI.QueryWidget(Id(:hour), :Value) ||
        Ops.get(current_settings, "minute") !=
          UI.QueryWidget(Id(:minute), :Value)

      Builtins.y2milestone("cron_changed: %1", cron_changed)

      Ops.set(
        current_settings,
        "auto",
        UI.QueryWidget(Id(:enabled), :Value)
      )
      Ops.set(current_settings, "every", UI.QueryWidget(Id(:time), :Value))

      Ops.set(
        current_settings,
        "weekday",
        UI.QueryWidget(Id(:weekday), :Value)
      )
      Ops.set(current_settings, "day", UI.QueryWidget(Id(:day), :Value))
      Ops.set(current_settings, "hour", UI.QueryWidget(Id(:hour), :Value))
      Ops.set(
        current_settings,
        "minute",
        UI.QueryWidget(Id(:minute), :Value)
      )

      Ops.set(current_settings, "old", UI.QueryWidget(Id(:old), :Value))

      Ops.set(current_settings, "cron_changed", cron_changed)

      Ops.set(
        current_profile,
        :cron_settings,
        Builtins.eval(current_settings)
      )
      Ops.set(
        current_profile,
        :mail_summary,
        UI.QueryWidget(Id(:mail), :Value)
      )
      Ops.set(
        Backup.backup_profiles,
        Backup.selected_profile,
        Builtins.eval(current_profile)
      )

      Builtins.y2milestone(
        "Profile: %1, New settings: %2",
        Backup.selected_profile,
        current_settings
      )
    end
  end

  Wizard.RestoreNextButton

  ret
end

- (Object) DeleteIncludeItem(delete_dir)



5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
# File '../../src/include/backup/ui.rb', line 5468

def DeleteIncludeItem(delete_dir)
  if Confirm.DeleteSelected &&
      Builtins.contains(Backup.include_dirs, delete_dir)
    Backup.include_dirs = Builtins.filter(Backup.include_dirs) do |one_dir|
      one_dir != delete_dir
    end

    RedrawIncludeTable()
  end

  nil
end

- (Hash) DirPopup(label, dir)

Directory selection dialog

Parameters:

  • label (String)

    dialog label

  • dir (String)

    start directory

Returns:

  • (Hash)

    result $[ “input” : symbol (user input, ok orcancel), “dir” : string (selected directory) ];



4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
# File '../../src/include/backup/ui.rb', line 4904

def DirPopup(label, dir)
  UI.OpenDialog(
    VBox(
      VSpacing(0.5),
      HBox(
        HSpacing(1.0),
        InputField(Id(:dir), Opt(:vstretch), label, dir),
        HSpacing(1),
        VBox(Label(""), PushButton(Id(:browse), _("&Browse..."))),
        HSpacing(1.0)
      ),
      VSpacing(1.0),
      HBox(
        PushButton(Id(:ok), Label.OKButton),
        PushButton(Id(:cancel), Label.CancelButton)
      ),
      VSpacing(0.3)
    )
  )

  UI.SetFocus(Id(:ok))

  input = Convert.to_symbol(UI.UserInput)

  while input != :ok && input != :cancel
    if input == :browse
      # title in the file selection dialog
      new = UI.AskForExistingDirectory(dir, _("Directory Selection"))

      if Ops.greater_than(Builtins.size(new), 0)
        UI.ChangeWidget(Id(:dir), :Value, new)
      end
    end

    input = Convert.to_symbol(UI.UserInput)
  end

  newval = Convert.to_string(UI.QueryWidget(Id(:dir), :Value))

  UI.CloseDialog

  { "input" => input, "dir" => newval }
end

- (Boolean) display_free_space_warning(fits, dir)

Display warning dialog - there is (may) not enough free space in the directory. The dialog is not displayed when cron mode is active (there is no real UI). if nil display "there may not be space"

Parameters:

  • dir (String)

    directory

  • fits (Boolean)

    if true no dialog is displayed, if false display “there is no space”,

Returns:

  • (Boolean)

    false = abort backup



1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
# File '../../src/include/backup/ui.rb', line 1874

def display_free_space_warning(fits, dir)
  cont = true

  # don't ask in cron mode - there is no UI
  # always continue, summary mail with fail message
  # will be sent to root user
  return cont if Backup.cron_mode == true

  if fits == false
    # there is no enough space
    cont = Popup.YesNo(
      Builtins.sformat(
        _(
          "There is not enough free space in directory %1.\nContinue anyway?\n"
        ),
        dir
      )
    )
  elsif fits == nil
    # may be that there is not enough space
    cont = Popup.YesNo(
      Builtins.sformat(
        _(
          "There may not be enough free space in directory %1.\nContinue anyway?\n"
        ),
        dir
      )
    )
  end

  cont
end

- (Object) EditIncludeItem(old_item)



5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
# File '../../src/include/backup/ui.rb', line 5481

def EditIncludeItem(old_item)
  new_dir = ShowEditBrowseDialog(_("&Edit Included Directory"), old_item)

  if Ops.get(new_dir, "clicked") == :ok &&
      Ops.get_string(new_dir, "text", "") != "" &&
      Ops.get(new_dir, "text") != nil
    # item changed
    if Ops.get_string(new_dir, "text", "") != old_item
      DeleteIncludeItem(old_item)
      AddIncludeItemNow(Ops.get_string(new_dir, "text", ""))

      RedrawIncludeTable()
    end
  end

  nil
end

- (Object) EvaluateFreeSpace(ret)



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
291
# File '../../src/include/backup/ui.rb', line 198

def EvaluateFreeSpace(ret)
  # If zero (or almost zero) free space in tmpdir
  if !@enough_free_space_tmp
    Builtins.y2warning("Not enough free space in the temporary directory")
    # cron mode => finish immediately
    if Backup.cron_mode
      Builtins.y2milestone("Finishing backup...")
      return :abort 
      # !cron mode => ask user
    elsif Convert.to_boolean(
        SCR.Read(path(".process.running"), @backup_PID)
      )
      if !Popup.YesNoHeadline(
          # headline of a popup message
          _("Warning"),
          # a popup question - no free space, %1 is the name of the directory
          Builtins.sformat(
            _(
              "There is not enough free space in the temporary directory %1.\nContinue anyway?"
            ),
            Backup.tmp_dir
          )
        )
        Builtins.y2milestone("Finishing backup...")
        return :abort
      else
        Builtins.y2milestone("Trying co continue...")
        @waiting_without_output = 0
        return ret
      end 
      # background agent is not running
    else
      # a popup error message - no free space, %1 is the name of the directory
      Report.Error(
        Builtins.sformat(
          _(
            "There is not enough free space in the backup target directory %1.\nAborting the backup."
          ),
          Backup.tmp_dir
        )
      )
      return :abort
    end
  end

  # If zero (or almost zero) free space in targetdir
  if !@enough_free_space_target
    Builtins.y2warning(
      "Not enough free space in the backup target directory"
    )
    # cron mode => finish immediately
    if Backup.cron_mode
      Builtins.y2milestone("Finishing backup...")
      return :abort 
      # !cron mode => ask user
    elsif Convert.to_boolean(
        SCR.Read(path(".process.running"), @backup_PID)
      )
      if !Popup.YesNoHeadline(
          # headline of a popup message
          _("Warning"),
          # a popup question - no free space, %1 is the name of the directory
          Builtins.sformat(
            _(
              "There is not enough free space in the backup target directory %1.\nContinue anyway?"
            ),
            Backup.target_dir
          )
        )
        Builtins.y2milestone("Finishing backup...")
        return :abort
      else
        Builtins.y2milestone("Trying co continue...")
        @waiting_without_output = 0
        return ret
      end 
      # background agent is not running
    else
      # a popup error message - no free space, %1 is the name of the directory
      Report.Error(
        Builtins.sformat(
          _(
            "There is not enough free space in the backup target directory %1.\nAborting the backup."
          ),
          Backup.target_dir
        )
      )
      return :abort
    end
  end

  # nothing changed
  ret
end

- (Object) ExcludeItemDelete(value, type)



5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
# File '../../src/include/backup/ui.rb', line 5383

def ExcludeItemDelete(value, type)
  # remove selected constraint
  if type == @regexp_text
    Backup.regexp_list = Builtins.filter(Backup.regexp_list) do |i|
      i != value
    end
  elsif type == @directory_text
    Backup.dir_list = Builtins.filter(Backup.dir_list) { |i| i != value }
  elsif type == @filesystem_text
    Backup.fs_exclude = Builtins.filter(Backup.fs_exclude) { |i| i != value }
  end

  # refresh table content
  RedrawConstraintsTable()

  nil
end

- (Object) ExcludeItemEdit(value, type, all_fss)



5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
# File '../../src/include/backup/ui.rb', line 5315

def ExcludeItemEdit(value, type, all_fss)
  # textentry label
  result = ShowEditDialog(
    Label.EditButton,
    value,
    type == @filesystem_text ? all_fss.value : nil,
    []
  )

  if Ops.get(result, "clicked") == :ok
    new_txt = Ops.get_string(result, "text")

    if new_txt != nil && new_txt != value
      if type == @regexp_text
        if Builtins.contains(Backup.regexp_list, new_txt)
          # error popup message
          Popup.Error(
            Builtins.sformat(
              _("Expression %1 is already in the list."),
              new_txt
            )
          )
        else
          # refresh regexp_list content
          Backup.regexp_list = Builtins.maplist(Backup.regexp_list) do |i|
            i == value ? new_txt : i
          end
        end
      elsif type == @directory_text
        if Builtins.contains(Backup.dir_list, new_txt)
          # error popup message
          Popup.Error(
            Builtins.sformat(
              _("Directory %1 is already in the list."),
              new_txt
            )
          )
        else
          # refresh regexp_list content
          Backup.dir_list = Builtins.maplist(Backup.dir_list) do |i|
            i == value ? new_txt : i
          end
        end
      elsif type == @filesystem_text
        if Builtins.contains(Backup.fs_exclude, new_txt)
          # error popup message
          Popup.Error(
            Builtins.sformat(
              _("File system %1 is already in the list."),
              new_txt
            )
          )
        else
          # refresh regexp_list content
          Backup.fs_exclude = Builtins.maplist(Backup.fs_exclude) do |i|
            i == value ? new_txt : i
          end
        end
      end

      # refresh table content
      RedrawConstraintsTable()
    end
  end

  nil
end

- (Symbol) ExpertOptionsDialog

Display dialog with expert options (e.g. system area backup, temporary location...)

Returns:

  • (Symbol)

    user input - widget ID



4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
# File '../../src/include/backup/ui.rb', line 4540

def ExpertOptionsDialog
  # dialog header
  Wizard.SetContents(
    _("Expert Backup Options"),
    VBox(
      VSpacing(0.5),
      # check box label
      Left(
        CheckBoxFrame(
          Id(:system),
          Opt(:notify),
          _("Back Up &Hard Disk System Areas"),
          Backup.system,
          HBox(HStretch(), PushButton(Id(:set_system), _("&Options...")))
        )
      ),
      # text entry label
      InputField(
        Id(:tmp),
        Opt(:hstretch),
        _("Temporary &Location of Archive Parts"),
        Backup.tmp_dir
      ),
      VSpacing(1),
      Left(Label(_("Pre and Post-Backup Scripts"))),
      Table(
        Id("table_of_scripts"),
        Header(
          # a header item
          _("Script Type"),
          # a header item
          _("Path")
        ),
        []
      ),
      Left(
        HBox(
          PushButton(Id(:add_script), Opt(:key_F3), _("&Add...")),
          PushButton(Id(:edit_script), Opt(:key_F4), _("&Edit...")),
          PushButton(Id(:delete_script), Opt(:key_F5), Label.DeleteButton)
        )
      ),
      VStretch()
    ),
    expert_options_help,
    true,
    true
  )

  RedrawScriptsTable(0)

  # enable/disable widges
  if Backup.archive_type == :txt
    UI.ChangeWidget(Id(:system), :Enabled, false)
    UI.ChangeWidget(Id(:set_system), :Enabled, false)
  else
    UI.ChangeWidget(Id(:set_system), :Enabled, Backup.system)
  end

  Wizard.SetNextButton(:finish, Label.OKButton)
  UI.SetFocus(Id(:finish))

  ret = nil
  current_item = nil

  while ret != :finish && ret != :back && ret != :abort &&
      ret != :set_system
    ret = Convert.to_symbol(UI.UserInput)
    current_item = Convert.to_integer(
      UI.QueryWidget(Id("table_of_scripts"), :CurrentItem)
    )

    if ret == :finish || ret == :set_system
      Backup.tmp_dir = Convert.to_string(UI.QueryWidget(Id(:tmp), :Value))
      Backup.system = Convert.to_boolean(
        UI.QueryWidget(Id(:system), :Value)
      )
    elsif ret == :system
      UI.ChangeWidget(
        Id(:set_system),
        :Enabled,
        Convert.to_boolean(UI.QueryWidget(Id(:system), :Value))
      )
    elsif ret == :add_script || ret == :edit_script
      if AddEditScriptDialog(ret) == true
        # Redraw table and select either the new or the edited script
        RedrawScriptsTable(
          ret == :add_script ?
            Ops.subtract(Builtins.size(Backup.backup_helper_scripts), 1) :
            current_item
        )
      end
    elsif ret == :delete_script
      next if Confirm.DeleteSelected != true
      Ops.set(Backup.backup_helper_scripts, current_item, nil)
      Backup.backup_helper_scripts = Builtins.filter(
        Backup.backup_helper_scripts
      ) { |one_item| one_item != nil }
      RedrawScriptsTable(0)
    end
  end

  Wizard.RestoreNextButton

  ret
end

- (Symbol) FilesDialog

Display found files, user can select files to backup

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
# File '../../src/include/backup/ui.rb', line 2833

def FilesDialog
  # busy message
  Wizard.SetContents(
    "",
    Label(_("Adding files to table...")),
    "",
    false,
    false
  )

  t1 = Builtins.time

  items = []
  items_filename = Ops.add(Directory.tmpdir, "/items-list.ycp")

  if FileUtils.Exists(items_filename)
    Builtins.y2milestone("Reading %1", items_filename)
    items = Convert.convert(
      SCR.Read(path(".target.ycp"), items_filename),
      :from => "any",
      :to   => "list <list>"
    )
  else
    Builtins.y2error("File %1 doesn't exist!", items_filename)
  end

  # dialog header
  Wizard.SetContents(
    _("File Selection"),
    VBox(
      VSpacing(0.5),
      # label text
      Left(Label(_("Files to Back Up"))),
      Table(
        Id(:table),
        Opt(:notify),
        # table header
        Header(" ", _("Filename"), _("Package")),
        []
      ),
      Left(
        HBox(
          # push button label
          PushButton(Id(:sel_file), _("Select or Deselect &File")),
          # push button label
          PushButton(Id(:sel_all), _("&Select All")),
          # push button label
          PushButton(Id(:desel_all), _("&Deselect All"))
        )
      ),
      VSpacing(1.0)
    ),
    backup_help_file_selection,
    true,
    true
  )

  # Items are pre-defined in the file
  items_filename_show = Ops.add(Directory.tmpdir, "/items.ycp")
  UI.ChangeWidget(
    Id(:table),
    :Items,
    FileUtils.Exists(items_filename_show) ?
      Convert.convert(
        SCR.Read(path(".target.ycp"), items_filename_show),
        :from => "any",
        :to   => "list <term>"
      ) :
      [Item(Id("none"), ["", _("Internal error"), ""])]
  )

  t2 = Builtins.time
  Builtins.y2milestone("UI finished after %1 seconds", Ops.subtract(t2, t1))

  # mark unselected files - use list from previous run
  if Ops.greater_than(Builtins.size(Backup.unselected_files), 0)
    t1 = Builtins.time
    # suppose that number of unselected files is much lower than number of
    # found files (otherwise we should iterate trough list of unselected
    # files)

    Builtins.y2milestone(
      "Found %1 unselected files",
      Builtins.size(Backup.unselected_files)
    )

    UI.OpenDialog(
      Left(
        Label(
          # busy message
          _("Deselecting files...")
        )
      )
    )
    Builtins.foreach(items) do |file_f|
      if Builtins.contains(
          Backup.unselected_files,
          Ops.get_string(file_f, 1)
        ) == true
        Builtins.y2debug(
          "Found previously unselected file: %1 (idx: %2)",
          Ops.get(file_f, 1),
          Ops.get(file_f, 0)
        )
        Ops.set(@deselected_ids, Ops.get_integer(file_f, 0), 1)
      end
    end 

    UI.CloseDialog

    Builtins.y2milestone(
      "searching unselected files was finished after %1 seconds",
      Ops.subtract(Builtins.time, t1)
    )
  end

  if Ops.greater_than(Builtins.size(@deselected_ids), 0)
    Builtins.y2milestone(
      "Deselecting %1 files",
      Builtins.size(@deselected_ids)
    )
    # remove selection mark for deselected files
    Builtins.foreach(@deselected_ids) do |idx, dummy_value|
      UI.ChangeWidget(Id(:table), term(:Item, idx, 0), " ")
    end
  end

  ret = nil
  changed = false

  while ret != :next && ret != :back && ret != :abort
    ret = Convert.to_symbol(UI.UserInput)

    if ret == :abort || ret == :cancel
      ret = :abort
      if !AbortConfirmation(:changed)
        ret = nil # not confirmed
      else
        break
      end
    end

    current_item = Convert.to_integer(
      UI.QueryWidget(Id(:table), :CurrentItem)
    )

    if ret == :sel_all || ret == :desel_all
      UI.OpenDialog(
        Left(
          Label(
            ret == :sel_all ?
              # An informative popup label during selecting all items in the table (can consume a lot of time)
              _("Selecting all items...") :
              # An informative popup label during deselecting all items in the table (can consume a lot of time)
              _("Deselecting all items...")
          )
        )
      )

      if ret == :sel_all
        Backup.unselected_files = []
        @deselected_ids = {}
      else
        Backup.unselected_files = []

        Builtins.foreach(Backup.selected_files) do |pack, info|
          Backup.unselected_files = Convert.convert(
            Builtins.merge(
              Backup.unselected_files,
              Ops.get_list(info, "changed_files", [])
            ),
            :from => "list",
            :to   => "list <string>"
          )
        end 


        desel_num = Builtins.size(Backup.unselected_files)
        @deselected_ids = {}

        while Ops.greater_than(desel_num, 0)
          Ops.set(@deselected_ids, desel_num, 1)
          desel_num = Ops.subtract(desel_num, 1)
        end
      end

      UI.CloseDialog
      UI.ChangeWidget(
        Id(:table),
        :Items,
        ret == :sel_all ?
          Convert.convert(
            # selecting all
            SCR.Read(
              path(".target.ycp"),
              Ops.add(
                Convert.to_string(SCR.Read(path(".target.tmpdir"))),
                "/items.ycp"
              )
            ),
            :from => "any",
            :to   => "list <term>"
          ) :
          Convert.convert(
            # deselecting all
            SCR.Read(
              path(".target.ycp"),
              Ops.add(
                Convert.to_string(SCR.Read(path(".target.tmpdir"))),
                "/items.ycp2"
              )
            ),
            :from => "any",
            :to   => "list <term>"
          )
      )

      if current_item != nil
        UI.ChangeWidget(Id(:table), :CurrentItem, current_item)
      end

      changed = true
    else
      if ret == :table || ret == :sel_file
        table_item = Convert.to_term(
          UI.QueryWidget(Id(:table), term(:Item, current_item))
        )

        current_value = Ops.get_string(table_item, 1, @nocheckmark)
        file_name = Ops.get_string(table_item, 2, "unknown file")
        package_name = Ops.get_string(table_item, 3, "unknown package")

        if current_value == @checkmark
          current_value = @nocheckmark

          # add to unselected files
          if !Builtins.contains(Backup.unselected_files, file_name)
            Backup.unselected_files = Builtins.add(
              Backup.unselected_files,
              file_name
            )
            Ops.set(@deselected_ids, current_item, 1)
          end

          # remove from selected files
          info = Ops.get(Backup.selected_files, package_name, {})
          if Ops.greater_than(Builtins.size(info), 0)
            chfiles = Ops.get_list(info, "changed_files", [])
            chfiles = Builtins.filter(chfiles) { |fn| fn != file_name }

            Ops.set(
              Backup.selected_files,
              [package_name, "changed_files"],
              chfiles
            )
          end
          Builtins.y2milestone(
            "File %1 removed from %2",
            file_name,
            package_name
          )
        else
          current_value = @checkmark

          # remove from unselected
          Backup.unselected_files = Builtins.filter(Backup.unselected_files) do |fn|
            fn != file_name
          end
          @deselected_ids = Builtins.remove(@deselected_ids, current_item)

          # add to selected
          info = Ops.get(Backup.selected_files, package_name, {})
          chfiles = Ops.get_list(info, "changed_files", [])

          if !Builtins.contains(chfiles, file_name)
            chfiles = Builtins.add(chfiles, file_name)

            Ops.set(
              Backup.selected_files,
              [package_name, "changed_files"],
              chfiles
            )
          end

          Builtins.y2milestone(
            "File %1 added to %2",
            file_name,
            package_name
          )
        end

        # refresh table
        UI.ChangeWidget(
          Id(:table),
          term(:Item, current_item, 0),
          current_value
        )

        changed = true
      end
    end
  end

  return ret if ret == :abort

  # file selection was changed, update profile data
  if changed == true && Backup.selected_profile != nil
    Backup.StoreSettingsToBackupProfile(Backup.selected_profile)
  end

  return :back_from_files if ret == :back

  ret
end

- (Object) InitConstraintDialog

Initialize the “Search Constraints” dialog



5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
# File '../../src/include/backup/ui.rb', line 5151

def InitConstraintDialog
  # initialize excluded directories
  Backup.dir_list = [] if Backup.dir_list == nil

  # initialize excluded filesystems
  if Backup.detected_fs == nil
    # busy message
    Wizard.SetContents(
      "",
      Label(_("Detecting file system types...")),
      "",
      false,
      false
    )
    Backup.detected_fs = GetMountedFilesystems()
    Backup.ExcludeNodevFS
  end

  # do not allow manual changes of configuration
  return :next if Backup.no_interactive

  # dialog header
  Wizard.SetContents(
    _("Search Constraints"),
    VBox(
      VSquash(
        MinHeight(
          6,
          # selection box
          SelectionBox(
            Id(:include),
            Opt(:shrinkable),
            _("&Directories Included in Search"),
            []
          )
        )
      ),
      HBox(
        # push button label
        PushButton(Id(:add_include), _("&Add...")),
        # push button label
        PushButton(Id(:edit_include), _("&Edit...")),
        # push button label
        PushButton(Id(:delete_include), _("De&lete"))
      ),
      VSpacing(1.0),
      # table label
      Left(Label(_("Items Excluded from Search"))),
      # table header
      Table(Id(:const), Opt(:vstretch), Header(_("Value"), _("Type")), []),
      Left(
        HBox(
          # push button label
          MenuButton(
            Id(:add_menu),
            _("A&dd"),
            [
              Item(Id(:dir), _("&Directory...")),
              Item(Id(:fs), _("&File System...")),
              Item(Id(:regexp), _("&Regular Expression..."))
            ]
          ),
          # push button label
          PushButton(Id(:edit), Opt(:key_F4), _("&Edit...")),
          # push button label
          PushButton(Id(:delete), Opt(:key_F5), _("De&lete"))
        )
      )
    ),
    backup_help_constraints,
    true,
    true
  )

  RedrawConstraintsTable()
  RedrawIncludeTable()

  if Backup.selected_profile != nil
    # replace 'Next' button with 'OK' if profile is configured
    Wizard.SetNextButton(:next, Label.OKButton)
    UI.SetFocus(Id(:next))
  end

  nil
end

- (Object) initialize_backup_ui(include_target)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
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
# File '../../src/include/backup/ui.rb', line 17

def initialize_backup_ui(include_target)
  Yast.import "UI"

  Yast.import "Backup"
  Yast.import "Wizard"
  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Label"
  Yast.import "Popup"
  Yast.import "String"
  Yast.import "NetworkPopup"
  Yast.import "Nfs"
  Yast.import "PackageSystem"
  Yast.import "Confirm"
  Yast.import "Mode"

  Yast.include include_target, "backup/help_texts.rb"
  Yast.include include_target, "backup/functions.rb"

  textdomain "backup"

  @wait_time = 250 # loop delay (in miliseconds)

  # used for the ag_process
  @backup_PID = nil

  # variables needed for backup when freezes on ZERO (or almost zero) free space
  @waiting_without_output = 0
  @enough_free_space_tmp = true
  @enough_free_space_target = true

  # wait 1 minute between checking for the free space
  @max_wait_without_output = 60000
  # wait sec between checking
  @wait_sec_check = 59
  @next_time_check = Ops.add(Builtins.time, @wait_sec_check)
  # minimal reasonable free space is 512K
  @min_free_space = 512

  @last_input = nil

  @deselected_ids = {}

  # type of item (displayed in the table)
  @filesystem_text = _("File system")
  # type of item (displayed in the table)
  @directory_text = _("Directory")
  # type of item (displayed in the table)
  @regexp_text = _("Regular expression")

  @selected_pkg_num = 0 # number of packages which files are selected
  @modified_size = 0 # size
  @modified_num = 0 # number of modified files


  @nopkg_num = 0 # number of found files which do not belong to any package
  @nopkg_size = 0 # size
  @selected_files_num = 0 # number of selected files to backup

  @checkmark = "X"
  @nocheckmark = " "

  @root_warning_displayed = false

  @file_list_stored = false

  @hostname_stored = false
  @date_stored = false
  @comment_stored = false
  @e2image_results = [] # results of storing ext2 images
  @archived_num = 0
  @not_readable_files = []
  @created_archive_files = []
  @failed_ptables = []
  @stored_ptables = []
  @read_ptables_info = false
  @stored_list = false

  @tar_result = 1 # exit status of tar
  @total_files = 0 # total number of files in archive
  @added_files = 0

  @packages_list_stored = false
  @profilewritten = {} # result of writing profile

  # -->>
  # definition of variables for search dialog/functions
  # trying to break huge cycle into more smaller functions

  @package_num = 0
  @actual_package = ""
  @package_files = []
  @actual_instprefixes = ""
  @line = ""
  @total_packages = 0

  # output strings from search script
  @id_package = "Package: "
  @id_complete_package = "Complete package: "
  @id_file = "Size: "
  @id_nopackage = "Nopackage:"
  @id_instprefixes = "Installed: "
  @id_reading_packages = "Reading installed packages"
  @id_packages_num = "Packages: "
  @id_reading_files = "Reading all files"
  @id_files_read = "Files read"

  @search_no_package = false
  @reading_installed_packages = false

  # we are in ncurses
  @in_ncurses = false

  @ui_last_refresh = 0
  @ui_time_now = 0

  @dir_last_refresh = 0
  @dir_time_now = 0
  @dir_shown = ""

  #  Variables for the ArchivingDialog() and functions beyond
  @id_hostname = "Storing hostname: "
  @id_date = "Storing date: "
  @id_partab = "Storing partition table"
  @id_ptstored = "Stored partition: "
  @id_ok = "Success"
  @id_failed = "Failed"
  @id_storing_installed_pkgs = "Storing list of installed packages"
  @id_storedpkg = "Packages stored: "
  @id_ext2 = "Storing ext2 area: "
  @id_archive = "Creating archive:"
  @id_tar_exit = "/Tar result:"
  @id_new_volume = "/Volume created: "
  @id_not_readable = "/File not readable: "
  @id_not_stored = "Error storing partition: "
  @id_pt_read = "Partition tables info read"
  @id_creating_target = "Creating target archive file..."

  @selected_info = {}

  @last_file_stage = 0
  @this_file_stage = 0
  @stages_for_files = 0
end

- (Object) InitScriptContent



4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
# File '../../src/include/backup/ui.rb', line 4214

def InitScriptContent
  file = Convert.to_string(UI.QueryWidget(Id("script_name"), :Value))

  # the default content is taken from UI (might be already defined)
  script_content = Convert.to_string(
    UI.QueryWidget(Id("script_content"), :Value)
  )

  # if a file exists, the content is taken from there
  if FileUtils.Exists(file)
    script_content = Convert.to_string(
      SCR.Read(path(".target.string"), file)
    )

    if script_content == nil
      Builtins.y2error("Cannot read file %1", file)
      script_content = ""
    end
  else
    Builtins.y2warning("File %1 does not exist (yet)", file)
  end

  # adjust UI
  UI.ChangeWidget(Id("script_content"), :Value, script_content)

  nil
end

- (Object) InitSearchingModifiedDialog

Initializes variables before the SearchingModifiedDialog



2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
# File '../../src/include/backup/ui.rb', line 2026

def InitSearchingModifiedDialog
  if !Backup.cron_mode
    Wizard.ClearContents
    Wizard.SetContents(
      "",
      # label text
      Label(_("Reading packages available at the software repositories...")),
      backup_help_searching_modified,
      false,
      false
    )
  end

  # read list of available packages at the original installation sources
  Backup.ReadInstallablePackages

  # initialize list of completely backed up packages
  Backup.complete_backup = []

  @selected_pkg_num = 0

  Backup.selected_files = {}

  nil
end

- (Object) InstallNeededPackages(packages)

Function for installing packages



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File '../../src/include/backup/ui.rb', line 381

def InstallNeededPackages(packages)
  packages = deep_copy(packages)
  if Builtins.size(packages) == 0
    Builtins.y2error("empty list of packages to be installed")
    return false
  end

  return true if Mode.test

  if !PackageSystem.CheckAndInstallPackagesInteractive(packages)
    Builtins.y2debug("star package wasn't installed")
    return false
  end

  true
end

- (Boolean) is_space(required, available, target_type)

Check whether there is enough free space.

Parameters:

  • required (Fixnum)

    required space in kB

  • available (Fixnum)

    required space in kB

  • target_type (Symbol)

    selected target archive type

Returns:

  • (Boolean)

    true = there is enough free space, false = not enough free space, nil = may be not enough space (compression is used, impossible to tell exactly)



1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
# File '../../src/include/backup/ui.rb', line 1839

def is_space(required, available, target_type)
  Builtins.y2milestone("Checking free space for the backup.")

  return false if Ops.less_than(available, 0)

  if Builtins.contains([:tgz, :stgz, :tbz, :stbz], target_type)
    # require at least 10M extra free space (overhead)
    required = Ops.add(required, 10240)
    Builtins.y2milestone("Required: %1, Available: %2", required, available)
    return Ops.less_than(required, available) ? true : nil
  elsif target_type == :tar || target_type == :star
    # require at least 10M extra free space (overhead)
    required = Ops.add(required, 10240)
    Builtins.y2milestone("Required: %1, Available: %2", required, available)
    return Ops.less_than(required, available)
  elsif target_type == :txt
    # require at least 500k extra free space (overhead)
    required = Ops.add(required, 500)
    Builtins.y2milestone("Required: %1, Available: %2", required, available)
    return Ops.less_than(required, available)
  else
    Builtins.y2warning("Unknown archive type: %1", target_type)
    Builtins.y2milestone("Required: %1, Available: %2", required, available)
  end

  nil
end

- (Array<Yast::Term>) list2items(start_id, type, input)

Convert list of strings to list of items

Parameters:

  • start_id (Fixnum)

    identification of the first item

  • type (String)

    description of item

  • input (Array<String>)

    input

Returns:

  • (Array<Yast::Term>)

    result



5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
# File '../../src/include/backup/ui.rb', line 5065

def list2items(start_id, type, input)
  input = deep_copy(input)
  ret = []
  i = start_id

  Builtins.foreach(input) do |itm|
    ret = Builtins.add(ret, Item(Id(i), itm, type))
    i = Ops.add(i, 1)
  end if Ops.greater_than(
    Builtins.size(input),
    0
  )

  deep_copy(ret)
end

- (Object) MemorySpent

Function might be removed, only for testing memory spent…



2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
# File '../../src/include/backup/ui.rb', line 2307

def MemorySpent
  command = "LC_ALL=C /bin/ps auxw | grep \"\\(y2base\\|^USER\\)\" | grep -v \"grep\""
  run_ps = Convert.convert(
    SCR.Execute(path(".target.bash_output"), command),
    :from => "any",
    :to   => "map <string, any>"
  )
  if Ops.get_integer(run_ps, "exit", 0) != 0
    Builtins.y2warning(
      "MemorySpent Error: '%1'",
      Ops.get_string(run_ps, "stderr", "")
    )
  end
  Ops.get_string(run_ps, "stdout", "")
end

- (Symbol) PrepareSearching

Choose the next step - start searching or return to the profile dialog.

Returns:

  • (Symbol)

    Symbol for wizard sequencer - next for searching,next2 for return to profile dialog



4890
4891
4892
4893
4894
4895
4896
4897
4898
# File '../../src/include/backup/ui.rb', line 4890

def PrepareSearching
  # if the user does not use profile, start searching
  if Backup.selected_profile == nil || Backup.no_interactive
    return :next
  else
    Backup.StoreSettingsToBackupProfile(Backup.selected_profile)
    return :ok
  end
end

- (Object) RedrawConstraintsTable

Redraws contstraints table content - directories, regular expressions and file systems to exclude



5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
# File '../../src/include/backup/ui.rb', line 5121

def RedrawConstraintsTable
  items = []

  items = Builtins.merge(
    items,
    list2items(Builtins.size(items), @directory_text, Backup.dir_list)
  )
  items = Builtins.merge(
    items,
    list2items(Builtins.size(items), @regexp_text, Backup.regexp_list)
  )
  items = Builtins.merge(
    items,
    list2items(Builtins.size(items), @filesystem_text, Backup.fs_exclude)
  )

  if items != [] && items != nil
    UI.ChangeWidget(Id(:const), :Items, items)
    UI.ChangeWidget(Id(:edit), :Enabled, true)
    UI.ChangeWidget(Id(:delete), :Enabled, true)
  else
    UI.ChangeWidget(Id(:const), :Items, [])
    UI.ChangeWidget(Id(:edit), :Enabled, false)
    UI.ChangeWidget(Id(:delete), :Enabled, false)
  end

  nil
end

- (Object) RedrawIncludeTable



5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
# File '../../src/include/backup/ui.rb', line 5081

def RedrawIncludeTable
  items = []

  # If no include_dir is defined, use the entire root "/"
  if Backup.include_dirs == nil || Backup.include_dirs == []
    Backup.include_dirs = [Backup.default_include_dir]
  end

  enable_include_table = true
  Builtins.foreach(Backup.include_dirs) do |include_dir|
    # The entire file system is included
    if include_dir == Backup.default_include_dir
      # TRANSLATORS: informative text in the multiline select-box
      items = [
        Item(Id(include_dir), _("Entire file system will be searched"))
      ]
      enable_include_table = false
      raise Break 
      # Other directories are included
    else
      items = Builtins.add(items, Item(Id(include_dir), include_dir))
    end
  end

  if items != [] && items != nil && enable_include_table
    UI.ChangeWidget(Id(:include), :Items, items)
    UI.ChangeWidget(Id(:edit_include), :Enabled, true)
    UI.ChangeWidget(Id(:delete_include), :Enabled, true)
  else
    UI.ChangeWidget(Id(:include), :Items, items)
    UI.ChangeWidget(Id(:edit_include), :Enabled, false)
    UI.ChangeWidget(Id(:delete_include), :Enabled, false)
  end

  nil
end

- (Object) RedrawScriptsTable(selected_item)



4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
# File '../../src/include/backup/ui.rb', line 4180

def RedrawScriptsTable(selected_item)
  counter = -1

  items = Builtins.maplist(Backup.backup_helper_scripts) do |one_item|
    counter = Ops.add(counter, 1)
    # before
    Item(
      Id(counter),
      Ops.get_string(one_item, "type", "before") == "before" ?
        # Script type
        _("Run before backup") :
        # Script type
        _("Run after backup"),
      Ops.get_string(one_item, "path", "")
    )
  end

  UI.ChangeWidget(Id("table_of_scripts"), :Items, items)

  if Ops.greater_than(
      Builtins.size(Backup.backup_helper_scripts),
      selected_item
    )
    UI.ChangeWidget(Id("table_of_scripts"), :CurrentItem, selected_item)
  end

  button_state = Ops.greater_than(Builtins.size(items), 0)

  UI.ChangeWidget(Id(:delete_script), :Enabled, button_state)
  UI.ChangeWidget(Id(:edit_script), :Enabled, button_state)

  nil
end

- (Object) refresh_widget_status(enable_archive_type)

Refresh widget status (enable/disable) in the displayed dialog. and option push button, select "archive" radio button. If enable_archive_type is false then disbale widgets, select "only list" radio button.

Parameters:

  • enable_archive_type (Boolean)

    if true enable archive selection combo box



720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# File '../../src/include/backup/ui.rb', line 720

def refresh_widget_status(enable_archive_type)
  if enable_archive_type == false
    UI.ChangeWidget(Id(:type), :Enabled, false)
    UI.ChangeWidget(Id(:opts), :Enabled, false)
    #	UI::ChangeWidget(`id(`description), `Enabled, false);
    UI.ChangeWidget(Id(:rbgroup), :CurrentButton, :only_list)
  else
    UI.ChangeWidget(Id(:type), :Enabled, true)
    UI.ChangeWidget(Id(:opts), :Enabled, true)
    #	UI::ChangeWidget(`id(`description), `Enabled, true);
    UI.ChangeWidget(Id(:rbgroup), :CurrentButton, :archive)
  end

  nil
end

- (Object) RenameProfilePupupDialog(current_name)

Displays a popup dialog asking for new name for the current profile. If nil returned, no redraw is needed, no changes are done.

Parameters:

  • string

    current profile

  • string

    name to be selected



4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
# File '../../src/include/backup/ui.rb', line 4652

def RenameProfilePupupDialog(current_name)
  Backup.RestoreSettingsFromBackupProfile(current_name)
  new_name = AskNewProfileName(current_name)

  # no changes, the same name
  return nil if current_name == new_name

  # if not cancelled
  if new_name != "" && new_name != nil
    #map current_profile = (map)eval(Backup::backup_profiles[Backup::selected_profile]:$[]);
    #map current_settings = (map)eval(current_profile[`cron_settings]:$[]);

    Backup.StoreSettingsToBackupProfile(new_name)


    # "Renaming", Cron settings, It seems to be a hack }8->
    Ops.set(
      Backup.backup_profiles,
      [new_name, :cron_settings],
      Ops.get_map(
        Backup.backup_profiles,
        [current_name, :cron_settings],
        {}
      )
    )
    # Setting that cron settings were changed
    Ops.set(
      Backup.backup_profiles,
      [new_name, :cron_settings, "cron_changed"],
      true
    )
    Ops.set(
      Backup.backup_profiles,
      [current_name, :cron_settings, "cron_changed"],
      true
    )

    # Remove the backup profile, but do not remove cron file
    Backup.RemoveBackupProfile(current_name, false)

    return new_name
  end
  nil
end

- (Object) ResetGlobalVariables

<<–



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
# File '../../src/include/backup/ui.rb', line 345

def ResetGlobalVariables
  @deselected_ids = {}
  @selected_pkg_num = 0
  @modified_size = 0
  @modified_num = 0
  @nopkg_num = 0
  @selected_files_num = 0
  @archived_num = 0
  @not_readable_files = []
  @created_archive_files = []
  @failed_ptables = []
  @stored_ptables = []
  @tar_result = 1
  @total_files = 0
  @added_files = 0

  @package_num = 0
  @actual_package = ""
  @package_files = []
  @actual_instprefixes = ""
  @line = ""
  @total_packages = 0

  @search_no_package = false
  @reading_installed_packages = false

  Backup.just_creating_archive = false

  ui_capabilities = UI.GetDisplayInfo
  @in_ncurses = Ops.get_boolean(ui_capabilities, "TextMode", true)
  Builtins.y2milestone("Running in TextMode: %1", @in_ncurses)

  nil
end

- (Object) Search_ChangedPackageFiles



2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
# File '../../src/include/backup/ui.rb', line 2070

def Search_ChangedPackageFiles
  # store package's changed files
  if Ops.greater_than(Builtins.size(@package_files), 0)
    Ops.set(
      Backup.selected_files,
      @actual_package,
      {
        "changed_files"    => @package_files,
        "install_prefixes" => @actual_instprefixes
      }
    )
    @package_files = []
    @selected_pkg_num = Ops.add(@selected_pkg_num, 1)
  end

  complete = Builtins.substring(
    @line,
    0,
    Builtins.size(@id_complete_package)
  ) == @id_complete_package
  @actual_package = complete ?
    Builtins.substring(@line, Builtins.size(@id_complete_package)) :
    Builtins.substring(@line, Builtins.size(@id_package))

  if complete == true
    Builtins.y2debug("Complete package: %1", @actual_package)
    Backup.complete_backup = Builtins.add(
      Backup.complete_backup,
      @actual_package
    )
  end
  @package_num = Ops.add(@package_num, 1)

  # Do not refresh UI in cron mode
  return if Backup.cron_mode

  @ui_time_now = Builtins.time

  # BNC#756493: Refresh the UI max. once per second
  # Otherwise it uses too much CPU on faster systems / disks
  if Ops.greater_than(@ui_time_now, @ui_last_refresh)
    @ui_last_refresh = @ui_time_now

    UI.ChangeWidget(
      Id(:package),
      :Value,
      Ops.add(_("Searching in Package: "), @actual_package)
    )
    UI.ChangeWidget(Id(:progress), :Value, @package_num)
    # bug #172406
    # Cannot be used for ncurses
    UI.RecalcLayout if !@in_ncurses
  end

  nil
end

- (Object) Search_ModifiedFiles

Updates UI while searching for modified files



2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
# File '../../src/include/backup/ui.rb', line 2156

def Search_ModifiedFiles
  @line = Builtins.substring(@line, Builtins.size(@id_file))

  size_str = Builtins.substring(@line, 0, Builtins.findfirstof(@line, " "))
  @modified_size = Ops.add(@modified_size, Builtins.tointeger(size_str))
  @modified_num = Ops.add(@modified_num, 1)

  modified_size_ref = arg_ref(@modified_size)
  modified_num_ref = arg_ref(@modified_num)
  Search_UpdateFilesAndSize(modified_size_ref, modified_num_ref)
  @modified_size = modified_size_ref.value
  @modified_num = modified_num_ref.value

  found_file = Builtins.substring(
    @line,
    Ops.add(Builtins.findfirstof(@line, " "), 1)
  )

  # escape newlines in file name
  # double backslashes
  parts = Builtins.splitstring(found_file, "\\")
  escaped = Builtins.mergestring(parts, "\\\\")

  # change newline to \n
  parts = Builtins.splitstring(escaped, "\n")
  escaped = Builtins.mergestring(parts, "\\n")

  # add file to list of found files
  @package_files = Builtins.add(@package_files, escaped)

  nil
end

- (Object) Search_NonPackageFile



2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
# File '../../src/include/backup/ui.rb', line 2189

def Search_NonPackageFile
  if Ops.greater_than(Builtins.size(@package_files), 0)
    Ops.set(
      Backup.selected_files,
      @actual_package,
      {
        "changed_files"    => @package_files,
        "install_prefixes" => @actual_instprefixes
      }
    )
    @package_files = []
    @selected_pkg_num = Ops.add(@selected_pkg_num, 1)
  end

  @actual_package = "" # empty package name
  @search_no_package = true # no package part of output

  Builtins.y2milestone(
    "Searching files which are not in any package started"
  )

  nil
end

- (Object) Search_ProcessInstalledPackages

Takes care about installed packages



2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
# File '../../src/include/backup/ui.rb', line 2054

def Search_ProcessInstalledPackages
  if Builtins.substring(@line, 0, Builtins.size(@id_packages_num)) == @id_packages_num
    @reading_installed_packages = false
    @total_packages = Builtins.tointeger(
      Builtins.substring(@line, Builtins.size(@id_packages_num))
    )

    Builtins.y2milestone(
      "Number of installed packages: %1",
      @total_packages
    )
  end

  nil
end

- (Object) Search_ReadListOfFilesAndPackages

Reads list of packages files, installed packages



2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
# File '../../src/include/backup/ui.rb', line 2214

def Search_ReadListOfFilesAndPackages
  if @line == @id_reading_files
    if !Backup.cron_mode
      # label text
      Wizard.SetContents(
        "",
        Label(_("Reading packages files...")),
        backup_help_searching_modified,
        false,
        false
      )
    end
  else
    if @line == @id_reading_packages
      Builtins.y2milestone("Reading installed packages")

      if !Backup.cron_mode
        # label text
        Wizard.SetContents(
          "",
          Label(_("Reading list of installed packages...")),
          backup_help_searching_modified,
          false,
          false
        )
      end

      @reading_installed_packages = true
    else
      if @line == @id_files_read
        if !Backup.cron_mode
          SetDialogContents_SearchingForModifiedFiles(@total_packages)
          UI.RecalcLayout
        end

        Builtins.y2milestone("Searching in packages started")
      else
        Builtins.y2warning("Unknown output from search script: %1", @line)
      end
    end
  end

  nil
end

- (Object) Search_ShowCurrentDir(actual_dir)



2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
# File '../../src/include/backup/ui.rb', line 2467

def Search_ShowCurrentDir(actual_dir)
  # No update
  return if @dir_shown == actual_dir.value

  @dir_time_now = Builtins.time

  if Ops.greater_than(@dir_time_now, @dir_last_refresh)
    UI.ChangeWidget(
      Id(:directory),
      :Value,
      Ops.add(_("Searching in Directory: "), actual_dir.value)
    )
    @dir_last_refresh = @dir_time_now
    @dir_shown = actual_dir.value

    # BNC#172406: Cannot be used for ncurses
    UI.RecalcLayout if !@in_ncurses
  end

  nil
end

- (Object) Search_UpdateFilesAndSize(modified_size, modified_num)

Updates UI: Modified files size and count



2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
# File '../../src/include/backup/ui.rb', line 2128

def Search_UpdateFilesAndSize(modified_size, modified_num)
  # There's no UI in cron mode
  return if Backup.cron_mode

  @ui_time_now = Builtins.time

  if Ops.greater_than(@ui_time_now, @ui_last_refresh)
    @ui_last_refresh = @ui_time_now

    UI.ChangeWidget(
      Id(:totsize),
      :Value,
      Ops.add(_("Total Size: "), String.FormatSize(modified_size.value))
    )
    UI.ChangeWidget(
      Id(:numfiles),
      :Value,
      Ops.add(
        _("Modified Files: "),
        Builtins.sformat("%1", modified_num.value)
      )
    )
  end

  nil
end

- (Symbol) SearchingModifiedDialog

Display progress of searching modified files in packages

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
# File '../../src/include/backup/ui.rb', line 2491

def SearchingModifiedDialog
  ResetGlobalVariables()
  InitSearchingModifiedDialog()

  Builtins.y2milestone(
    "Search script: %1",
    Ops.add(Backup.script_get_files, Backup.get_search_script_parameters)
  )

  # starting the searching script in the background
  @backup_PID = Convert.to_integer(
    SCR.Execute(
      path(".process.start_shell"),
      Ops.add(Backup.script_get_files, Backup.get_search_script_parameters),
      { "C_locale" => true }
    )
  )
  script_out = []

  started = @backup_PID != nil && Ops.greater_than(@backup_PID, 0)

  ret = nil

  Builtins.y2milestone(
    "subprocess started: %1 (PID: %2)",
    started,
    @backup_PID
  )

  if !started
    # error popup message
    Report.Error(
      _("Could not start the search script.\nAborting the backup.\n")
    )
    @line = ""
    while @line != nil
      @line = Convert.to_string(
        SCR.Read(path(".process.read_line_stderr"), @backup_PID)
      )
      Builtins.y2error("Error: %1", @line)
    end

    if Backup.cron_mode
      return :abort
    else
      return :maindialog
    end
  end

  search_time = Builtins.time

  # while background script runs
  while Convert.to_boolean(SCR.Read(path(".process.running"), @backup_PID)) ||
      !Convert.to_boolean(
        SCR.Read(path(".process.buffer_empty"), @backup_PID)
      )
    @line = Convert.to_string(
      SCR.Read(path(".process.read_line"), @backup_PID)
    ) # read line

    while @line != nil
      # reading installed packages until the last package is read
      if @reading_installed_packages
        Search_ProcessInstalledPackages()
      else
        if Builtins.substring(@line, 0, Builtins.size(@id_package)) == @id_package ||
            Builtins.substring(
              @line,
              0,
              Builtins.size(@id_complete_package)
            ) == @id_complete_package
          Search_ChangedPackageFiles()
        else
          if Builtins.substring(@line, 0, Builtins.size(@id_file)) == @id_file
            @ui_last_refresh = 0
            Search_ModifiedFiles()
          else
            if @line == @id_nopackage
              Search_NonPackageFile()
              break
            else
              if Builtins.substring(
                  @line,
                  0,
                  Builtins.size(@id_instprefixes)
                ) == @id_instprefixes
                @actual_instprefixes = Builtins.substring(
                  @line,
                  Builtins.size(@id_instprefixes)
                )
              else
                Search_ReadListOfFilesAndPackages()
              end
            end
          end
        end
      end

      @line = Convert.to_string(
        SCR.Read(path(".process.read_line"), @backup_PID)
      ) # read line
    end

    break if @search_no_package

    if Backup.cron_mode
      # BNC #568615: yast2 backup takes much longer when scheduled
      if Convert.to_boolean(
          SCR.Read(path(".process.buffer_empty"), @backup_PID)
        ) == true
        Builtins.sleep(@wait_time)
      end

      ret = nil
    else
      ret = waitForUserOrProcess(@wait_time, :changed)
    end

    return ret if ret != nil
  end
  # end of the 'while' backround script runs

  if Ops.greater_than(Builtins.size(@package_files), 0)
    Ops.set(
      Backup.selected_files,
      @actual_package,
      {
        "changed_files"    => @package_files,
        "install_prefixes" => @actual_instprefixes
      }
    )
    @selected_pkg_num = Ops.add(@selected_pkg_num, 1)
  end

  Builtins.y2milestone("All packages verified.")

  # searching files not belonging to any package
  if @search_no_package
    actual_dir = "/"

    # Strings are not localized on purpose: Used for matching output from
    # the searching script
    id_readingall = "Reading all files"
    id_readall = "Files read"
    id_dir = "Dir: "

    # Chached value
    size_id_dir = Builtins.size(id_dir)

    SetDialogContents_SearchingFiles() if !Backup.cron_mode

    @ui_last_refresh = 0

    package_files_part = []
    new_files = 0

    dir_shown = ""

    while Convert.to_boolean(
        SCR.Read(path(".process.running"), @backup_PID)
      ) ||
        !Convert.to_boolean(
          SCR.Read(path(".process.buffer_empty"), @backup_PID)
        )
      # test of script_out size is needed, because previous while cycle was interrupted and script could exited with no new output...
      @line = Convert.to_string(
        SCR.Read(path(".process.read_line"), @backup_PID)
      ) # read line
      next if @line == nil

      # --->
      if Builtins.substring(@line, 0, Builtins.size(@id_file)) == @id_file
        @line = Builtins.substring(@line, Builtins.size(@id_file))

        size_str = Builtins.substring(
          @line,
          0,
          Builtins.findfirstof(@line, " ")
        )
        size_line = nil
        if size_str != nil && size_str != ""
          size_line = Builtins.tointeger(size_str)
          @nopkg_size = Ops.add(@nopkg_size, size_line) if size_line != nil
        end

        @nopkg_num = Ops.add(@nopkg_num, 1)

        modified_size_ref = arg_ref(@modified_size)
        modified_num_ref = arg_ref(@modified_num)
        Search_UpdateFilesAndSize(modified_size_ref, modified_num_ref)
        @modified_size = modified_size_ref.value
        @modified_num = modified_num_ref.value

        found_file = Builtins.substring(
          @line,
          Ops.add(Builtins.findfirstof(@line, " "), 1)
        )

        # escape newlines in file name
        # double backslashes
        parts = Builtins.splitstring(found_file, "\\")
        escaped = Builtins.mergestring(parts, "\\\\")

        # change newline to \n
        parts = Builtins.splitstring(escaped, "\n")
        escaped = Builtins.mergestring(parts, "\\n")

        # add file to list of found files
        package_files_part = Builtins.add(package_files_part, escaped)
        new_files = Ops.add(new_files, 1)

        # merge more files in one step - it's faster
        if new_files == 1000
          @package_files = Builtins.merge(
            @package_files,
            package_files_part
          )
          package_files_part = []
          new_files = 0
        end
      else
        if !Backup.cron_mode
          if Builtins.substring(@line, 0, size_id_dir) == id_dir
            actual_dir = Builtins.substring(@line, size_id_dir)
          end
        end
      end

      actual_dir_ref = arg_ref(actual_dir)
      Search_ShowCurrentDir(actual_dir_ref)
      actual_dir = actual_dir_ref.value
      # <---

      script_out = []

      if Backup.cron_mode == true
        # BNC #568615: yast2 backup takes much longer when scheduled
        if Convert.to_boolean(
            SCR.Read(path(".process.buffer_empty"), @backup_PID)
          ) == true
          Builtins.sleep(@wait_time)
        end

        ret = nil
      else
        ret = waitForUserOrProcess(@wait_time, :changed)
      end

      if ret != nil
        return ret if AbortConfirmation(:changed) if ret == :abort
      end
    end

    Ops.set(
      Backup.selected_files,
      @actual_package,
      {
        "changed_files"    => Builtins.merge(
          @package_files,
          package_files_part
        ),
        "install_prefixes" => @actual_instprefixes
      }
    )
  end

  search_time = Ops.subtract(Builtins.time, search_time)
  Builtins.y2milestone("Searching done after %1 sec.", search_time)

  dparts = Builtins.splitstring(Backup.archive_name, "/")
  dparts = Builtins.remove(dparts, Ops.subtract(Builtins.size(dparts), 1))
  tdir = Builtins.mergestring(dparts, "/")

  # just for other functions
  Backup.target_dir = tdir

  # check available space
  if check_space(
      Ops.add(@nopkg_size, @modified_size),
      Backup.tmp_dir,
      Backup.target_dir,
      Backup.archive_type
    ) == false
    # there is no space, user selected not to continue
    if Backup.cron_mode
      return :abort
    else
      return :maindialog
    end
  end

  if Backup.display && !Backup.no_interactive
    Backup.selected_files = nil if Backup.selected_files == {}

    return :next
  else
    # skip the files listed in Backup::unselected_files
    if Backup.unselected_files != nil
      # try to find each file in selected files
      Builtins.foreach(Backup.unselected_files) do |file|
        new_selected = {}
        Builtins.foreach(Backup.selected_files) do |pak, val|
          changed_files = Ops.get_list(val, "changed_files", [])
          if Builtins.contains(changed_files, file)
            changed_files = Builtins.filter(changed_files) { |v| v != file }

            # construct new package description
            Ops.set(
              Backup.selected_files,
              [pak, "changed_files"],
              changed_files
            )
            Ops.set(
              Backup.selected_files,
              [pak, "install_prefixes"],
              Ops.get_list(val, "install_prefixes", [])
            )
          end
        end
      end
      Builtins.y2milestone(
        "Filtered out unselected files according to profile"
      )
    end

    # count number of files
    @selected_files_num = 0

    Builtins.foreach(Backup.selected_files) do |pak, val|
      @selected_files_num = Ops.add(
        @selected_files_num,
        Builtins.size(Ops.get_list(val, "changed_files", []))
      )
    end

    return Backup.display && !Backup.cron_mode ? :next : :next2 # `next2 = skip file selection dialog
  end
end

- (Symbol) SelectProfileDialog

Dialog for selection of a profile before backup

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
# File '../../src/include/backup/ui.rb', line 4699

def SelectProfileDialog
  Wizard.SetNextButton(:finish, Label.OKButton)
  Wizard.SetAbortButton(:abort, Label.CancelButton)
  Wizard.HideBackButton

  tableheader1 = _("Name")
  tableheader2 = _("Description")
  tableheader3 = _("Automatic Backup")

  Wizard.SetContents(
    _("System Backup"),
    VBox(
      Left(Label(_("Available Profiles"))),
      ReplacePoint(
        Id(:selectionBox),
        Table(
          Id(:profile),
          Header(tableheader1, tableheader2, tableheader3),
          Backup.BackupProfileDescriptions
        )
      ),
      HBox(
        PushButton(Id(:start), _("&Create Backup")),
        MenuButton(
          _("Profile Mana&gement"),
          [
            Item(Id(:add), Ops.add(Label.AddButton, "...")),
            Item(Id(:clone), _("&Duplicate...")),
            Item(Id(:edit), Ops.add(Label.EditButton, "...")),
            # TRANSLATORS: Menu button selection
            Item(Id(:rename), _("Re&name") + "..."),
            Item(Id(:delete), Label.DeleteButton),
            Item(Id(:cron), Ops.add(tableheader3, "..."))
          ]
        )
      ),
      PushButton(Id(:manual), _("Back Up &Manually...")),
      VSpacing(1.5)
    ),
    profile_help,
    false,
    true
  )

  sel_prof = Backup.selected_profile == nil ?
    Ops.get(Backup.BackupProfileNames, 0) :
    Backup.selected_profile

  if sel_prof != nil
    # select the first profile in the list
    UI.ChangeWidget(Id(:profile), :CurrentItem, sel_prof)
  end

  ret = nil
  Backup.no_interactive = false
  begin
    # select the first profile in the list
    UI.ChangeWidget(
      Id(:start),
      :Enabled,
      Builtins.size(Backup.backup_profiles) != 0
    )

    ret = Convert.to_symbol(UI.UserInput)

    # load corresponding settings
    if Builtins.size(Backup.backup_profiles) == 0
      Backup.RestoreDefaultSettings
    else
      Backup.RestoreSettingsFromBackupProfile(
        Convert.to_string(UI.QueryWidget(Id(:profile), :CurrentItem))
      )
    end

    if ret == :start
      Backup.no_interactive = true
    elsif ret == :clone || ret == :add
      # add a new profile with the current/default settings
      if ret == :add
        # restore default settings, don't care about selected profile
        Backup.RestoreDefaultSettings
      end

      new_name = AskNewProfileName(nil)

      # if the user didn't choose cancel
      if new_name != ""
        Backup.StoreSettingsToBackupProfile(new_name)
        UI.ReplaceWidget(
          Id(:selectionBox),
          Table(
            Id(:profile),
            Header(tableheader1, tableheader2, tableheader3),
            Backup.BackupProfileDescriptions
          )
        )

        # select the profile in the list
        UI.ChangeWidget(Id(:profile), :CurrentItem, new_name)

        if ret == :add
          # start config. workflow for the new profile
          ret = :edit
          Backup.RestoreSettingsFromBackupProfile(
            Convert.to_string(UI.QueryWidget(Id(:profile), :CurrentItem))
          )
          # adding new profile
          Backup.profile_is_new_one = true
        end
      end
    elsif ret == :rename
      current_name = Convert.to_string(
        UI.QueryWidget(Id(:profile), :CurrentItem)
      )
      current_name = RenameProfilePupupDialog(current_name)
      # redraw if any changes are done
      if current_name != nil
        UI.ReplaceWidget(
          Id(:selectionBox),
          Table(
            Id(:profile),
            Header(tableheader1, tableheader2, tableheader3),
            Backup.BackupProfileDescriptions
          )
        )
        UI.ChangeWidget(Id(:profile), :CurrentItem, current_name)
      end
    elsif ret == :delete
      # remove the selected profile
      if Popup.YesNo(_("Remove the selected profile?"))
        # remove backup profile also with cron file
        Backup.RemoveBackupProfile(
          Convert.to_string(UI.QueryWidget(Id(:profile), :CurrentItem)),
          true
        )
        UI.ReplaceWidget(
          Id(:selectionBox),
          Table(
            Id(:profile),
            Header(tableheader1, tableheader2, tableheader3),
            Backup.BackupProfileDescriptions
          )
        )

        # select the first profile in the list
        UI.ChangeWidget(
          Id(:profile),
          :CurrentItem,
          Ops.get(Backup.BackupProfileNames, 0)
        )
      end
    elsif ret == :manual
      # load defaults, clear selected_profile
      Backup.RestoreDefaultSettings
      Backup.selected_profile = nil
    elsif ret == :cron
      selprofile = Convert.to_string(
        UI.QueryWidget(Id(:profile), :CurrentItem)
      )

      if selprofile != nil
        Backup.selected_profile = selprofile
      else
        # no selected profile, wait for next UserInput
        ret = nil
      end
    elsif ret == :cancel
      ret = :abort
    end
  end while ret != :finish && ret != :manual && ret != :start && ret != :edit &&
    ret != :cron &&
    ret != :abort

  # save profiles before quit and
  # before starting backup
  # (modifications would be lost when backup is aborted
  if ret == :finish || ret == :start || ret == :manual
    Builtins.y2milestone(" *** Storing profiles ***")
    Backup.WriteBackupProfiles
  end

  Wizard.RestoreNextButton
  Wizard.RestoreBackButton

  Builtins.y2debug("SelectProfileDialog result: %1", ret)

  ret
end

- (Object) SetDialogContents_SearchingFiles

Function sets the dialog contents before searching files…



2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
# File '../../src/include/backup/ui.rb', line 2260

def SetDialogContents_SearchingFiles
  # dialog header
  Wizard.SetContents(
    _("Searching Files"),
    VBox(
      HStretch(),
      VSpacing(0.5),
      Left(
        # label text, followed by value
        Label(
          Id(:numfiles),
          Ops.add(_("Modified Files: "), Builtins.sformat("%1", @nopkg_num))
        )
      ),
      VSpacing(0.5),
      Left(
        # label text, followed by value
        Label(
          Id(:totsize),
          Ops.add(_("Total Size: "), String.FormatSize(@nopkg_size))
        )
      ),
      VSpacing(0.5),
      Left(
        # bug #172406
        MinSize(
          42,
          1,
          # label text, followed by current directory name
          Label(
            Id(:directory),
            _("Searching in Directory: ") +
              "                                                            "
          )
        )
      )
    ),
    backup_help_searching_files,
    false,
    false
  )
  UI.RecalcLayout

  nil
end

- (Object) SetDialogContents_SearchingForModifiedFiles(total_packages)

Sets dialog contents - Searching for Modified Files

Parameters:

  • total_packages (Fixnum)


1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
# File '../../src/include/backup/ui.rb', line 1963

def SetDialogContents_SearchingForModifiedFiles(total_packages)
  Builtins.y2milestone("Progress Packages: %1", total_packages)
  Wizard.SetContents(
    # dialog header
    _("Searching for Modified Files"),
    VBox(
      VSpacing(0.5),
      Left(
        # label text, followed by number of files found so far
        Label(
          Id(:numfiles),
          Ops.add(
            _("Modified Files: "),
            Builtins.sformat("%1", @modified_num)
          )
        )
      ),
      VSpacing(0.5),
      Left(
        # label text, followed by sizes of files
        Label(
          Id(:totsize),
          Ops.add(_("Total Size: "), String.FormatSize(@modified_size))
        )
      ),
      VSpacing(0.5),
      Left(
        # label text, followed by name of current package
        Label(
          Id(:package),
          _("Searching in Package: ") + "                            "
        )
      ),
      VSpacing(3.0),
      Left(
        # bug #172406
        MinSize(
          42,
          2,
          VBox(
            HStretch(),
            # progress bar label
            ProgressBar(
              Id(:progress),
              Opt(:hstretch),
              _("Search"),
              total_packages
            )
          )
        )
      ),
      VStretch()
    ),
    backup_help_searching_modified,
    false,
    false
  )
  UI.RecalcLayout

  nil
end

- (Hash) size2map(sz)

Convert size in bytes to B, kiB, kB, MiB or MB

Parameters:

  • sz (Fixnum)

    size in bytes

Returns:

  • (Hash)

    map $[ “string” : string (textual representation), “size” : integer (value), “unit” : symbol (unit of the value) ]



4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
# File '../../src/include/backup/ui.rb', line 4951

def size2map(sz)
  ret = ""
  ret_unit = :B
  unit_descr = {}

  return nil if sz == nil

  Builtins.foreach(Backup.units_description) do |m|
    s = Ops.get_symbol(m, "symbol")
    label = Ops.get_string(m, "label")
    if s != nil && Ops.greater_than(Builtins.size(label), 0)
      Ops.set(unit_descr, s, label)
    end
  end 


  if Ops.modulo(sz, 1024) == 0
    # size in kiB
    sz = Ops.divide(sz, 1024)

    if Ops.modulo(sz, 1024) == 0
      # size in MiB
      sz = Ops.divide(sz, 1024)

      # return MiB
      ret = Ops.add(
        Ops.add(Builtins.sformat("%1", sz), " "),
        Ops.get(unit_descr, :MiB, "")
      )
      ret_unit = :MiB
    else
      # return kiB
      ret = Ops.add(
        Ops.add(Builtins.sformat("%1", sz), " "),
        Ops.get(unit_descr, :kiB, "")
      )
      ret_unit = :kiB
    end
  elsif Ops.modulo(sz, 1000) == 0
    # size in kB
    sz = Ops.divide(sz, 1000)

    if Ops.modulo(sz, 1000) == 0
      # size in MB
      sz = Ops.divide(sz, 1000)

      # return MB
      ret = Ops.add(
        Ops.add(Builtins.sformat("%1", sz), " "),
        Ops.get(unit_descr, :MB, "")
      )
      ret_unit = :MB
    else
      # return kB
      ret = Ops.add(
        Ops.add(Builtins.sformat("%1", sz), " "),
        Ops.get(unit_descr, :kB, "")
      )
      ret_unit = :kB
    end
  else
    ret = Ops.add(
      Ops.add(Builtins.sformat("%1", sz), " "),
      Ops.get(unit_descr, :B, "")
    )
    ret_unit = :B
  end

  { "string" => ret, "size" => sz, "unit" => ret_unit }
end

- (Object) StoreScriptContent(filename)



4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
# File '../../src/include/backup/ui.rb', line 4242

def StoreScriptContent(filename)
  script_content = Convert.to_string(
    UI.QueryWidget(Id("script_content"), :Value)
  )

  if !FileUtils.Exists(filename)
    pos = Builtins.findlastof(filename, "/")

    if pos == nil
      UI.SetFocus(Id("script_content"))
      Report.Error(_("Invalid file name."))
      return false
    end

    directory = Builtins.substring(filename, 0, Ops.add(pos, 1))

    cmd = Convert.to_map(
      SCR.Execute(
        path(".target.bash_output"),
        Builtins.sformat(
          "mkdir -pv '%1' && touch '%2' && chmod 0700 '%2'",
          directory,
          filename
        )
      )
    )

    if Ops.get_integer(cmd, "exit", -1) != 0
      Report.Error(
        Builtins.sformat(
          _("Cannot create file %1.\nDetails: %2"),
          filename,
          Ops.get_string(cmd, "stderr", "")
        )
      )
      return false
    end
  end

  if SCR.Write(path(".target.string"), filename, script_content) != true
    Report.Error(Builtins.sformat(_("Cannot write to %1 file."), filename))
    return false
  end

  true
end

- (Symbol) SummaryDialog

Display backup summary

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
# File '../../src/include/backup/ui.rb', line 3695

def SummaryDialog
  br = "<BR>"
  p = "<P>"
  __p = "</P>"

  em = "<B>"
  __em = "</B>"

  if Backup.cron_mode == true
    br = "\n"
    p = ""
    __p = "\n"

    em = ""
    __em = ""
  end

  backup_result = ""
  backup_details = ""

  if Backup.archive_type == :txt
    # For translators: %1 is entered archive file name (summary text)
    backup_result = Ops.add(
      Ops.add(
        p,
        @stored_list ?
          Builtins.sformat(
            _("List of files saved to file %1"),
            Backup.archive_name
          ) :
          # part of summary text
          # summary text
          Ops.add(Ops.add(em, _("Error storing list of files")), __em)
      ),
      __p
    )
  else
    # part of summary text
    backup_result = Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(Ops.add(p, _("Modified Files Found: ")), @modified_num),
            br
          ),
          # part of summary text
          _("Total Size: ")
        ),
        String.FormatSize(@modified_size)
      ),
      __p
    )

    if Backup.do_search
      # part of summary text
      backup_result = Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(
              Ops.add(
                Ops.add(
                  Ops.add(backup_result, p),
                  _("Files Not in a Package Found: ")
                ),
                @nopkg_num
              ),
              br
            ),
            # part of summary text
            _("Total Size: ")
          ),
          String.FormatSize(@nopkg_size)
        ),
        __p
      )
    end

    if Backup.display
      # part of summary text
      backup_result = Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(backup_result, p),
            _("Selected Files to Back Up: ")
          ),
          @selected_files_num
        ),
        __p
      )
    end

    # part of summary text
    backup_details = Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(
              Ops.add(
                Ops.add(
                  Ops.add(
                    Ops.add(
                      Ops.add(
                        p,
                        @hostname_stored ?
                          _("Hostname stored successfully") :
                          # part of summary text
                          Ops.add(
                            Ops.add(em, _("Storing hostname failed")),
                            __em
                          )
                      ),
                      br
                    ),
                    @date_stored ?
                      _("Date stored successfully") :
                      # part of summary text
                      Ops.add(Ops.add(em, _("Storing date failed")), __em)
                  ),
                  br
                ),
                @file_list_stored ?
                  _("File list stored successfully") :
                  # part of summary text
                  Ops.add(Ops.add(em, _("Storing file list failed")), __em)
              ),
              br
            ),
            @comment_stored ?
              _("Comment stored successfully") :
              # part of summary text
              Ops.add(Ops.add(em, _("Storing comment failed")), __em)
          ),
          br
        ),
        # part of summary text
        @packages_list_stored ?
          _("List of installed packages stored successfully") :
          # part of summary text
          Ops.add(
            Ops.add(em, _("Storing list of installed packages failed")),
            __em
          )
      ),
      __p
    )


    if Ops.greater_than(Builtins.size(@not_readable_files), 0) ||
        !@hostname_stored ||
        !@date_stored ||
        !@file_list_stored ||
        !@comment_stored ||
        !@packages_list_stored
      # part of summary text, 'Details' is button label
      backup_result = Ops.add(
        Ops.add(
          Ops.add(backup_result, p),
          _(
            "Some errors occurred during backup. Press Details for more information."
          )
        ),
        __p
      )
    end


    if Ops.greater_than(Builtins.size(@not_readable_files), 0)
      # part of summary text
      backup_details = Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(Ops.add(Ops.add(backup_details, br), p), em),
            _("Errors Creating Archive:")
          ),
          __em
        ),
        br
      )

      Builtins.foreach(@not_readable_files) do |f|
        # For translators: %1 file name - part of summary text
        backup_details = Ops.add(
          Ops.add(
            Ops.add(
              Ops.add(backup_details, em),
              Builtins.sformat(_("Cannot read file %1"), f)
            ),
            __em
          ),
          br
        )
      end 


      backup_details = Ops.add(backup_details, __p)
    end

    if Backup.system
      Builtins.y2debug("Ext2 backup: %1", Backup.ext2_backup)
      Builtins.y2debug("Ext2 results: %1", @e2image_results)

      if Backup.backup_pt
        if !@read_ptables_info
          # part of summary text
          backup_details = Ops.add(
            Ops.add(
              Ops.add(
                Ops.add(Ops.add(backup_details, p), em),
                _("Detecting disk partitions failed")
              ),
              __em
            ),
            br
          )
        end

        Builtins.foreach(@failed_ptables) do |failed_pt|
          # For translators: %1 is device name of disk, e.g. hda - part of summary text
          backup_details = Ops.add(
            Ops.add(
              Ops.add(
                Ops.add(backup_details, em),
                Builtins.sformat(
                  _("Storing partition table of disk /dev/%1 failed"),
                  failed_pt
                )
              ),
              __em
            ),
            br
          )
        end 


        Builtins.foreach(@stored_ptables) do |stored_pt|
          # For translators: %1 is device name of disk, e.g. hda - part of summary text
          backup_details = Ops.add(
            Ops.add(
              backup_details,
              Builtins.sformat(
                _("Storing partition table of disk /dev/%1 was successful"),
                stored_pt
              )
            ),
            br
          )
        end
      end

      if Ops.greater_than(Builtins.size(Backup.ext2_backup), 0)
        index = 0

        Builtins.foreach(@e2image_results) do |r|
          tmp = Ops.get(Backup.ext2_backup, index)
          tmp = Ops.get_term(tmp, 0)
          partition_name = Ops.get_string(tmp, 0, "")
          if r
            backup_details = Ops.add(
              Ops.add(
                backup_details,
                # For translators: %1 is partition name e.g. /dev/hda1 - part of summary text
                Builtins.sformat(
                  _("Ext2 image of %1 stored successfully"),
                  partition_name
                )
              ),
              br
            )

            @added_files = Ops.add(@added_files, 1)
          else
            backup_details = Ops.add(
              Ops.add(
                Ops.add(
                  Ops.add(backup_details, em),
                  # For translators: %1 is partition name e.g. /dev/hda1 - part of summary text
                  Builtins.sformat(
                    _("Storing ext2 image of %1 failed"),
                    partition_name
                  )
                ),
                __em
              ),
              br
            )
          end
          index = Ops.add(index, 1)
        end
      end

      backup_details = Ops.add(backup_details, __p)
    end

    @added_files = Ops.add(@added_files, 1) if @file_list_stored

    @added_files = Ops.add(@added_files, 1) if @hostname_stored

    @added_files = Ops.add(@added_files, 1) if @date_stored

    @added_files = Ops.add(@added_files, 1) if @comment_stored

    @added_files = Ops.add(@added_files, 1) if @packages_list_stored

    Builtins.y2debug("selected_files_num: %1", @selected_files_num)
    Builtins.y2debug("added_files: %1", @added_files)
    Builtins.y2debug("total_files: %1", @total_files)

    backup_result = Ops.add(
      Ops.add(
        Ops.add(backup_result, __p),
        # part of summary text
        br
      ),
      Ops.less_than(
        Ops.add(@selected_files_num, @added_files),
        @total_files
      ) ?
        Ops.add(
          Ops.add(
            Ops.add(em, _("Warning: Some files were not backed up")),
            __em
          ),
          br
        ) :
        ""
    )

    archive_created = ""

    if !Backup.multi_volume
      archname = Backup.target_type == :file ?
        Backup.archive_name :
        NFSfile(Backup.nfsserver, Backup.nfsexport, Backup.archive_name)
      # For translators: %1 is entered archive file name - part of summary text
      archive_created = Builtins.sformat(
        _("Archive %1 created successfully"),
        archname
      )
    else
      # part of summary text
      archive_created = _("Archive created successfully")
    end

    # part of summary text - %1 is file name
    profilesummary = Ops.get_boolean(@profilewritten, "result", false) == true ?
      Builtins.sformat(
        _("Autoinstallation profile saved to file %1."),
        Ops.get_string(@profilewritten, "profile", "")
      ) :
      Ops.add(
        Ops.add(em, _("Autoinstallation profile was not saved.")),
        __em
      )

    backup_result = Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(
              backup_result,
              # part of summary text
              @tar_result == 0 ?
                archive_created :
                Ops.add(Ops.add(em, _("Archive creation failed")), __em)
            ),
            br
          ),
          profilesummary
        ),
        br
      ),
      __p
    )

    # part of summary text
    backup_details = Ops.add(
      Ops.add(
        Ops.add(Ops.add(backup_details, p), _("Total Archived Files: ")),
        @archived_num
      ),
      __p
    )


    if Backup.multi_volume
      if Ops.greater_than(Builtins.size(@created_archive_files), 0)
        # part of summary text
        backup_details = Ops.add(
          Ops.add(
            Ops.add(
              Ops.add(Ops.add(backup_details, p), em),
              "Created archive volumes:"
            ),
            __em
          ),
          br
        )

        Builtins.foreach(@created_archive_files) do |f|
          backup_details = Ops.add(Ops.add(backup_details, f), br)
        end 


        backup_details = Ops.add(backup_details, __p)
      end
    end
  end

  buttons = HBox(PushButton(Id(:details), Opt(:key_F2), _("&Details...")))
  if Backup.selected_profile == nil
    buttons = HBox(
      PushButton(Id(:details), Opt(:key_F2), _("&Details...")),
      PushButton(Id(:profile), _("&Save as Profile..."))
    )
  end

  # cron mode
  if Backup.cron_mode == true
    if Backup.mail_summary == true
      SendSummary(
        Backup.remove_result,
        Backup.selected_profile,
        backup_result,
        backup_details
      )
    end

    return :finish
  end

  # dialog header
  Wizard.SetContents(
    _("Backup Summary"),
    VBox(
      VSpacing(0.5),
      RichText(backup_result),
      VSpacing(0.5),
      # push button label
      buttons,
      VSpacing(1.0)
    ),
    backup_help_summary,
    true,
    true
  )

  if Backup.archive_type == :txt
    UI.ChangeWidget(Id(:details), :Enabled, false)
  end

  Wizard.SetNextButton(:finish, Label.OKButton)
  UI.SetFocus(Id(:finish))

  ret = Convert.to_symbol(UI.UserInput)

  while ret != :finish && ret != :back
    if ret == :details
      # popup dialog header
      Popup.LongText(
        _("Backup Summary Details"),
        RichText(backup_details),
        70,
        15
      )
    elsif ret == :abort || ret == :cancel
      ret = :abort
      if AbortConfirmation(:changed)
        break
      else
        ret = nil
      end
    elsif ret == :profile
      new_name = AskNewProfileName(nil)

      #if no cancel, store
      Backup.StoreSettingsToBackupProfile(new_name) if new_name != ""
    end

    ret = Convert.to_symbol(UI.UserInput)
  end

  Wizard.RestoreNextButton
  ret
end

- (String) symbol2string(s, user_size)

Convert size description to string

Parameters:

  • s (Symbol)

    volume size

  • user_size (Fixnum)

    user defined size

Returns:

  • (String)

    result



5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
# File '../../src/include/backup/ui.rb', line 5026

def symbol2string(s, user_size)
  Builtins.y2milestone("s: %1, user_size: %2", s, user_size)

  ret = ""

  return ret if s == nil

  if s == :user
    tmp = size2map(user_size)
    return Ops.get_string(tmp, "string", "")
  end

  Builtins.foreach(Backup.media_descriptions) do |m|
    sym = Ops.get_symbol(m, "symbol")
    cap = Ops.get_integer(m, "capacity")
    label = Ops.get_string(m, "label", "")
    Builtins.y2milestone("symbol: %1", Ops.get(m, "symbol"))
    if sym == s
      ret = label

      if Ops.greater_than(cap, 0)
        tmp = size2map(cap)
        ret = Ops.add(
          ret,
          Builtins.sformat(" (%1)", Ops.get_string(tmp, "string", ""))
        )
      end
    end
  end 


  ret
end

- (Symbol) SystemBackupDialog

System area backup options

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
# File '../../src/include/backup/ui.rb', line 1565

def SystemBackupDialog
  if Backup.detected_ext2 == nil
    # status message - label
    Wizard.SetContents(
      "",
      Label(_("Detecting mounted ext2 file systems...")),
      "",
      false,
      false
    )
    Backup.detected_ext2 = Ext2Filesystems()
    Backup.ext2_backup = AddIdExt2(Backup.detected_ext2)
  end

  # dialog header
  Wizard.SetContents(
    _("System Area Backup"),
    VBox(
      VSpacing(0.5),
      # frame label
      Frame(
        _("Partition Table"),
        VBox(
          VSpacing(0.4),
          # check box label
          CheckBox(
            Id(:pt),
            Opt(:hstretch),
            _("Ba&ck Up Partition Tables"),
            Backup.backup_pt
          ),
          VSpacing(0.4)
        )
      ),
      VSpacing(0.5),
      # frame label
      Frame(
        _("Ext2 File System Critical Area Backup"),
        RadioButtonGroup(
          Id(:rbg),
          VBox(
            VSpacing(0.3),
            # radio button label
            Left(
              RadioButton(
                Id(:none),
                Opt(:notify),
                _("N&one"),
                Backup.backup_none_ext2
              )
            ),
            VSpacing(0.3),
            # radio button label
            Left(
              RadioButton(
                Id(:allmounted),
                Opt(:notify),
                _("All &Mounted"),
                Backup.backup_all_ext2
              )
            ),
            VSpacing(0.3),
            # radio button label
            Left(
              RadioButton(
                Id(:selected),
                Opt(:notify),
                _("&Selected"),
                Backup.backup_selected_ext2
              )
            ),
            HBox(
              HSpacing(3.0),
              VBox(
                # table header
                Table(
                  Id(:par),
                  Header(_("Ext2 Partition"), _("Mount Point")),
                  Backup.ext2_backup
                ),
                Left(
                  HBox(
                    # push button label
                    PushButton(Id(:addnew), Opt(:key_F3), _("A&dd...")),
                    # push button label
                    PushButton(Id(:edit), Opt(:key_F4), _("&Edit...")),
                    # push button label
                    PushButton(Id(:delete), Opt(:key_F5), _("De&lete"))
                  )
                )
              ),
              HSpacing(2.0)
            ),
            VSpacing(0.4)
          )
        )
      ),
      VSpacing(1.0)
    ),
    backup_help_system_backup,
    true,
    true
  )

  Wizard.SetNextButton(:finish, Label.OKButton)
  UI.SetFocus(Id(:finish))

  UI.ChangeWidget(Id(:par), :Enabled, Backup.backup_selected_ext2)
  UI.ChangeWidget(Id(:addnew), :Enabled, Backup.backup_selected_ext2)

  # Enable the buttons only if they are of any use
  enable_modif_buttons = Ops.greater_than(
    Builtins.size(Backup.ext2_backup),
    0
  )

  UI.ChangeWidget(Id(:edit), :Enabled, enable_modif_buttons)
  UI.ChangeWidget(Id(:delete), :Enabled, enable_modif_buttons)

  ret = nil

  while ret != :finish && ret != :back && ret != :abort
    ret = Convert.to_symbol(UI.UserInput)

    curr = Convert.to_string(UI.QueryWidget(Id(:par), :CurrentItem))
    if curr != nil
      if ret == :edit
        edited = ShowEditDialog(Label.EditButton, curr, nil, [])

        if Ops.get(edited, "clicked") == :ok
          txt = Ops.get_string(edited, "text", "")
          dir = Ext2MountPoint(txt)

          if txt != curr
            if Builtins.contains(
                Backup.ext2_backup,
                Item(Id(txt), txt, dir)
              )
              # error popup message, %1 is partition name (e.g. /dev/hda1)
              Popup.Error(
                Builtins.sformat(
                  _("Partition %1 is already in the list."),
                  txt
                )
              )
            else
              # refresh ext2_backup content
              Backup.ext2_backup = Builtins.maplist(Backup.ext2_backup) do |i|
                tmp = Ops.get_string(i, [0, 0], "")
                if tmp == curr
                  next Item(Id(txt), txt, dir)
                else
                  next deep_copy(i)
                end
              end

              # refresh table content
              UI.ChangeWidget(Id(:par), :Items, Backup.ext2_backup)

              Builtins.y2debug("ext2: %1", Backup.ext2_backup)
            end
          end
        end
      end

      if ret == :delete
        next if !Confirm.DeleteSelected

        Backup.ext2_backup = Builtins.filter(Backup.ext2_backup) do |i|
          tmp = Ops.get_string(i, [0, 0], "")
          tmp != curr
        end
        UI.ChangeWidget(Id(:par), :Items, Backup.ext2_backup)
      end
    end

    if ret == :addnew
      detected_ext2_strings = []

      Builtins.foreach(Backup.detected_ext2) do |info|
        part = Ops.get_string(info, "partition")
        if part != nil
          detected_ext2_strings = Builtins.add(detected_ext2_strings, part)
        end
      end 


      # popup dialog header
      result = ShowEditDialog(
        _("&Add Ext2 Partition"),
        "",
        detected_ext2_strings,
        []
      )

      if Ops.get_symbol(result, "clicked") == :ok
        sz = Builtins.size(Backup.ext2_backup)
        new_par = Ops.get_string(result, "text")
        dir = Ext2MountPoint(new_par)

        # add new partition only if it's not empty a it isn't already in list
        if new_par != "" && new_par != nil
          if Builtins.contains(
              Backup.ext2_backup,
              Item(Id(new_par), new_par, dir)
            )
            # error popup message, %1 is partition name (e.g. /dev/hda1)
            Popup.Error(
              Builtins.sformat(
                _("Partition %1 is already in the list."),
                new_par
              )
            )
          else
            Backup.ext2_backup = Builtins.add(
              Backup.ext2_backup,
              Item(Id(new_par), new_par, dir)
            )
            UI.ChangeWidget(Id(:par), :Items, Backup.ext2_backup)

            Builtins.y2debug("ext2: %1", Backup.ext2_backup)
          end
        end
      end
    end

    # Enable the buttons only if they are of any use
    enable_modif_buttons = Ops.greater_than(
      Builtins.size(Backup.ext2_backup),
      0
    )

    UI.ChangeWidget(Id(:edit), :Enabled, enable_modif_buttons)
    UI.ChangeWidget(Id(:delete), :Enabled, enable_modif_buttons)

    if ret == :allmounted || ret == :selected || ret == :none
      Backup.backup_all_ext2 = Convert.to_boolean(
        UI.QueryWidget(Id(:allmounted), :Value)
      )
      Backup.backup_none_ext2 = Convert.to_boolean(
        UI.QueryWidget(Id(:none), :Value)
      )
      Backup.backup_selected_ext2 = Convert.to_boolean(
        UI.QueryWidget(Id(:selected), :Value)
      )

      UI.ChangeWidget(Id(:par), :Enabled, Backup.backup_selected_ext2)
      UI.ChangeWidget(Id(:addnew), :Enabled, Backup.backup_selected_ext2)
      UI.ChangeWidget(Id(:edit), :Enabled, Backup.backup_selected_ext2)
      UI.ChangeWidget(Id(:delete), :Enabled, Backup.backup_selected_ext2)
    end

    if ret == :abort || ret == :cancel
      ret = :abort
      if !AbortConfirmation(:changed)
        ret = nil # not confirmed, uset ret
      end
    end
  end

  Backup.backup_pt = Convert.to_boolean(UI.QueryWidget(Id(:pt), :Value))

  Wizard.RestoreNextButton

  ret
end

- (Symbol) TarOptionsDialog

Setting multi volume archive options

Returns:

  • (Symbol)

    Symbol for wizard sequencer - pressed button



1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
# File '../../src/include/backup/ui.rb', line 1289

def TarOptionsDialog
  description_combo = MediaList2UIList(Backup.media_descriptions)
  # combo box item - user defined volume size of archive
  description_combo = Builtins.add(
    description_combo,
    Item(Id(:user_defined), _("Custom"))
  )

  Builtins.y2milestone("%1", description_combo)

  description_combo_units = MediaList2UIList(Backup.units_description)
  Builtins.y2milestone("%1", description_combo_units)

  # dialog header
  Wizard.SetContents(
    _("Archive File Options"),
    VBox(
      VSpacing(0.5),
      # frame label
      Frame(
        _("Multivolume Archive"),
        VBox(
          VSpacing(Opt(:hstretch), 0.5),
          # check box label
          Left(
            CheckBox(
              Id(:multi_volume),
              Opt(:notify),
              _("&Create a Multivolume Archive"),
              Backup.multi_volume
            )
          ),
          VSpacing(0.5),
          HBox(
            HSpacing(3.5),
            VBox(
              # combo box label
              Left(
                ComboBox(
                  Id(:vol),
                  Opt(:notify),
                  _("&Volume Size"),
                  description_combo
                )
              ),
              VSpacing(0.5),
              Left(
                VSquash(
                  HBox(
                    # text entry label
                    Bottom(
                      InputField(
                        Id(:user_size),
                        Opt(:hstretch),
                        _("Custom &Size")
                      )
                    ),
                    HSpacing(1),
                    Bottom(
                      ComboBox(Id(:user_unit), "", description_combo_units)
                    ),
                    HStretch()
                  )
                )
              ),
              VSpacing(0.5)
            ),
            HSpacing(1.0)
          )
        )
      ),
      VSpacing(1.0)
    ),
    backup_help_archive_options,
    true,
    true
  )

  # replace 'Next' button with 'Ok'
  Wizard.SetNextButton(:ok, Label.OKButton)
  UI.SetFocus(Id(:ok))

  # allow only digits in the text entry
  UI.ChangeWidget(Id(:user_size), :ValidChars, "0123456789")

  Backup.volume_size = :fd144 if Backup.volume_size == nil
  UI.ChangeWidget(Id(:vol), :Value, Backup.volume_size)

  tmp_size = ""
  tmp_size = Backup.user_volume_size if Backup.user_volume_size != nil
  UI.ChangeWidget(Id(:user_size), :Value, tmp_size)

  Backup.user_volume_unit = :B if Backup.user_volume_unit == nil
  UI.ChangeWidget(Id(:user_unit), :Value, Backup.user_volume_unit)

  SetMultiWidgetsState()

  cont = false
  ret = nil

  while !cont
    ret = Convert.to_symbol(UI.UserInput)

    if ret == :ok
      if Convert.to_boolean(UI.QueryWidget(Id(:multi_volume), :Value)) == true &&
          Convert.to_symbol(UI.QueryWidget(Id(:vol), :Value)) == :user_defined &&
          Ops.less_than(
            Ops.divide(
              Ops.multiply(
                Builtins.tofloat(UI.QueryWidget(Id(:user_size), :Value)),
                Builtins.tofloat(
                  Backup.GetCapacity(
                    Backup.units_description,
                    Convert.to_symbol(
                      UI.QueryWidget(Id(:user_unit), :Value)
                    )
                  )
                )
              ),
              1024.0
            ),
            10.0
          )
        # warning popup message
        Popup.Warning(_("Volume size must be at least 10240 bytes."))
      else
        cont = true

        Backup.multi_volume = Convert.to_boolean(
          UI.QueryWidget(Id(:multi_volume), :Value)
        )
        Backup.volume_size = Convert.to_symbol(
          UI.QueryWidget(Id(:vol), :Value)
        )
        Backup.user_volume_size = Convert.to_string(
          UI.QueryWidget(Id(:user_size), :Value)
        )
        Backup.user_volume_unit = Convert.to_symbol(
          UI.QueryWidget(Id(:user_unit), :Value)
        )
      end
    else
      if ret == :multi_volume || ret == :vol
        SetMultiWidgetsState()
      else
        if ret == :abort || ret == :cancel
          ret = :abort
          cont = AbortConfirmation(:changed)
        else
          cont = true
        end
      end
    end
  end

  # Restore 'next' button
  Wizard.RestoreNextButton

  ret
end

- (Object) update_cron_dialog

Update widget status in the dialog. Enable/disable widget according to checkbox/combobox value.



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/include/backup/ui.rb', line 400

def update_cron_dialog
  if UI.QueryWidget(Id(:enabled), :Value) == true
    UI.ChangeWidget(Id(:time), :Enabled, true)

    UI.ChangeWidget(
      Id(:weekday),
      :Enabled,
      UI.QueryWidget(Id(:time), :Value) == :week
    )
    UI.ChangeWidget(
      Id(:day),
      :Enabled,
      UI.QueryWidget(Id(:time), :Value) == :month
    )

    UI.ChangeWidget(Id(:hour), :Enabled, true)
    UI.ChangeWidget(Id(:minute), :Enabled, true)

    UI.ChangeWidget(Id(:old), :Enabled, true)
    UI.ChangeWidget(Id(:mail), :Enabled, true)
  else
    # disable all widgets
    UI.ChangeWidget(Id(:time), :Enabled, false)
    UI.ChangeWidget(Id(:weekday), :Enabled, false)
    UI.ChangeWidget(Id(:day), :Enabled, false)
    UI.ChangeWidget(Id(:hour), :Enabled, false)
    UI.ChangeWidget(Id(:minute), :Enabled, false)
    UI.ChangeWidget(Id(:old), :Enabled, false)
    UI.ChangeWidget(Id(:mail), :Enabled, false)
  end

  nil
end

- (Object) update_location_dialog

Refresh widget states in the location dialog



435
436
437
438
439
440
441
442
443
444
# File '../../src/include/backup/ui.rb', line 435

def update_location_dialog
  nfs = UI.QueryWidget(Id(:nfs), :Value) == true

  UI.ChangeWidget(Id(:nfsserver), :Enabled, nfs)
  UI.ChangeWidget(Id(:selectexport), :Enabled, nfs)
  UI.ChangeWidget(Id(:nfsexport), :Enabled, nfs)
  UI.ChangeWidget(Id(:selecthost), :Enabled, nfs)

  nil
end

- (Symbol) waitForUserOrProcess(wait, abort_question)

Wait for output from subprocess or user action. If user press `abort button, then subprocess is terminated.

Parameters:

  • wait (Fixnum)

    Delay in miliseconds between user action checks (if no output from subprocess is available)

  • abort_question (Symbol)

    Symbol for AbortConfirmation function - which dialog will be displayed if Abort button is pressed

Returns:

  • (Symbol)

    Pressed button id or nil if some data is ready from subprocess.



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
# File '../../src/include/backup/ui.rb', line 298

def waitForUserOrProcess(wait, abort_question)
  ret = Convert.to_symbol(UI.PollInput)

  if ret == :abort || ret == :cancel
    Builtins.y2warning("Abort pressed")
    ret = :abort

    if AbortConfirmation(abort_question)
      SCR.Execute(path(".process.kill"), @backup_PID) if @backup_PID != nil
      return ret
    else
      ret = nil
    end
  end

  if @backup_PID != nil &&
      Convert.to_boolean(SCR.Read(path(".process.running"), @backup_PID))
    if Convert.to_boolean(
        SCR.Read(path(".process.buffer_empty"), @backup_PID)
      ) == true
      Builtins.sleep(wait)
    end

    ret = Convert.to_symbol(UI.PollInput)

    if ret == :abort || ret == :cancel
      ret = :abort
      Builtins.y2warning("Abort pressed")

      if Backup.just_creating_archive
        CheckFreeSpace()
        ret = EvaluateFreeSpace(ret)
      else
        if AbortConfirmation(abort_question)
          SCR.Execute(path(".process.kill"), @backup_PID)
        else
          ret = nil
        end
      end
    end
  end

  ret
end

- (Boolean) WriteArchive

Ask whether archive can be overwritten if it already exists

Returns:

  • (Boolean)

    true when archive can be overwritten, nil when an error occured (e.g. NFS mount failed)



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
# File '../../src/include/backup/ui.rb', line 448

def WriteArchive
  ret = true

  Builtins.y2milestone("target_type: %1", Backup.target_type)

  exists = Backup.target_type == :file ?
    Ops.greater_or_equal(
      Convert.to_integer(
        SCR.Read(path(".target.size"), Backup.archive_name)
      ),
      0
    ) :
    NFSFileExists(Backup.nfsserver, Backup.nfsexport, Backup.archive_name)

  Builtins.y2milestone("exists: %1", exists)

  if exists == true
    # For translators %1 is archive file name (e.g. /tmp/backup.tar)
    ret = Popup.YesNo(
      Builtins.sformat(
        _("File %1 already exists.\nOverwrite it?"),
        Backup.archive_name
      )
    )
  elsif exists == nil
    ret = nil
  end

  ret
end