Module: Yast::BackupFunctionsInclude
- Defined in:
- ../../src/include/backup/functions.rb
Instance Method Summary (collapse)
-
- (Boolean) AbortConfirmation(type)
Display abort confirmation dialog.
-
- (Array) AddId(_in)
Returns list of items from list of values.
-
- (Array) AddIdBool(_in, val)
Set boolean value val to all items in list.
-
- (Array) AddIdExt2(_in)
Returns list of items from list of values.
-
- (String) AddMissingExtension(file, extension)
Add extension to the file name if it is missing.
-
- (Boolean) CloneSystem(filename, additional, extra_key, extra_options)
Store autoyast profile of the system to file.
-
- (String) CreateUnderLine(input, ch)
Create string from character ch with the same lenght as input.
-
- (Hash) DetectMountpoints
Detect mount points.
-
- (Array) Ext2Filesystems
Returns list of Ext2 mountpoints - actually mounted and from /etc/fstab file.
-
- (String) Ext2MountPoint(device_name)
Return mount point for Ext2 partition.
-
- (Hash) get_free_space(directory)
Get available space in the directory $[“device” : string(device), “total” : integer(total), “used” : integer(used), “free” : integer(free) ].
-
- (String) GetBaseName(file)
Get base file name without extension.
-
- (Array<String>) GetInstallPackages
Read packages available on the installation sources (Requires at least one installation source, otherwise return empty list).
-
- (Array) GetListWithFlags(_in, selected)
This function reads two lists: full list and selection list (contains subset of items in full list).
-
- (Array) GetMountedFilesystems
Returns list of mounted file systems types.
- - (Object) initialize_backup_functions(include_target)
- - (Object) IsPossibleToCreateDirectoryOrExists(directory)
-
- (Array) MediaList2UIList(media)
Convert media description list to ComboBox items list.
-
- (Array) MpointTableContents(selected, all, description)
Create table content with detected mount points.
-
- (String) NFSfile(server, share, filename)
Create NFS file description string.
-
- (Boolean) NFSFileExists(server, share, filename)
Check whether file on the NFS server exists.
-
- (String) SecondsToDateString(sec)
Convert number of second since 1.1.1970 to string.
-
- (Boolean) SendMail(user, subject, message)
Send mail to specified user.
-
- (Boolean) SendSummary(remove_result, cron_profile, backup_result, backup_details)
Send summary mail of the backup process to root.
-
- (void) SetMultiWidgetsState
Set state of depending widgets in Multiple volume options dialog.
- - (Object) ShowEditBrowseDialog(label, value)
-
- (Hash) ShowEditDialog(label, value, values, forbidden_letters)
Ask user for some value: display dialog with label, text entry and OK/Cancel buttons.
Instance Method Details
- (Boolean) AbortConfirmation(type)
Display abort confirmation dialog
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 |
# File '../../src/include/backup/functions.rb', line 37 def AbortConfirmation(type) ret = nil # popup dialog header heading = _("Abort Confirmation") # popup dialog question question = _("Really abort the backup?") yes = Label.YesButton no = Label.NoButton if type == :changed ret = Popup.AnyQuestion(heading, question, yes, no, :focus_no) else if type == :not_changed ret = Popup.AnyQuestion(heading, question, yes, no, :focus_yes) else if type == :none ret = true else Builtins.y2warning( "Unknown type of abort confirmation dialog: %1", type ) end end end ret end |
- (Array) AddId(_in)
Returns list of items from list of values.
287 288 289 290 291 292 |
# File '../../src/include/backup/functions.rb', line 287 def AddId(_in) _in = deep_copy(_in) return [] if _in == nil Builtins.maplist(_in) { |i| Item(Id(i), i) } end |
- (Array) AddIdBool(_in, val)
Set boolean value val to all items in list.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File '../../src/include/backup/functions.rb', line 262 def AddIdBool(_in, val) _in = deep_copy(_in) val = false if val == nil return [] if _in == nil Builtins.maplist(_in) do |i| tmp_id = nil tmp_s = nil isterm = Ops.is_term?(i) if isterm ti = Convert.to_term(i) tmp_id = Ops.get_term(ti, 0) tmp_s = Ops.get_string(ti, 1) end isterm && tmp_id != nil && tmp_s != nil ? Item(tmp_id, tmp_s, val) : nil end end |
- (Array) AddIdExt2(_in)
Returns list of items from list of values.
300 301 302 303 304 305 306 307 308 309 |
# File '../../src/include/backup/functions.rb', line 300 def AddIdExt2(_in) _in = deep_copy(_in) return [] if _in == nil Builtins.maplist(_in) do |i| pt = Ops.get_string(i, "partition") mp = Ops.get_string(i, "mountpoint") Item(Id(pt), pt, mp) end end |
- (String) AddMissingExtension(file, extension)
Add extension to the file name if it is missing. This function skips adding when the file is under the /dev/ path or when it is an existing device file.
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File '../../src/include/backup/functions.rb', line 398 def AddMissingExtension(file, extension) # input check return "" if file == nil return file if extension == nil # removing unneded slashes if Builtins.regexpmatch(file, "^/") file = Builtins.regexpsub(file, "^/+(.*)", "/\\1") end # skip if the file is a block device if FileUtils.Exists(file) && FileUtils.GetFileType(file) == "block" Builtins.y2milestone( "Leaving destination unchanged, '%1' is a block device", file ) return file end # skipping /dev/ directory if Builtins.regexpmatch(file, "^/dev/") Builtins.y2milestone( "Leaving destination unchanged, '%1' is under the /dev/ directory", file ) return file end dirs = Builtins.splitstring(file, "/") filename = Ops.get(dirs, Ops.subtract(Builtins.size(dirs), 1), file) result = "" # check if file can contain extension if Ops.greater_or_equal(Builtins.size(filename), Builtins.size(extension)) extension_re = Builtins.regexpsub(extension, "\\.(.*)", "\\.\\1") extension_re = Ops.add( extension_re == nil ? extension : extension_re, "$" ) # add extension only if it is missing # Using regexpmatch instead of substring+size because # of a bytes/characters bug #180631 if !Builtins.regexpmatch(filename, extension_re) filename = Ops.add(filename, extension) end else filename = Ops.add(filename, extension) end if Ops.greater_than(Builtins.size(dirs), 0) dirs = Builtins.remove(dirs, Ops.subtract(Builtins.size(dirs), 1)) end dirs = Builtins.add(dirs, filename) result = Builtins.mergestring(dirs, "/") result end |
- (Boolean) CloneSystem(filename, additional, extra_key, extra_options)
Store autoyast profile of the system to file
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 |
# File '../../src/include/backup/functions.rb', line 828 def CloneSystem(filename, additional, extra_key, ) additional = deep_copy(additional) = deep_copy() Yast.import "AutoinstClone" Yast.import "Profile" ret = false if Ops.greater_than(Builtins.size(filename), 0) if Ops.greater_than(Builtins.size(additional), 0) # clonne additional system parts AutoinstClone.additional = deep_copy(additional) end # create profile with with currently available resources (partitioning, software etc.) Builtins.y2milestone("Clonning system started...") if Mode.test AutoinstClone.Process Builtins.y2milestone("SKIPPING") end Builtins.y2milestone("System clonned") if Ops.greater_than(Builtins.size(), 0) && Ops.greater_than(Builtins.size(extra_key), 0) Ops.set(Profile.current, extra_key, ) end return Profile.Save(filename) end false end |
- (String) CreateUnderLine(input, ch)
Create string from character ch with the same lenght as input
540 541 542 543 544 545 546 547 548 549 550 |
# File '../../src/include/backup/functions.rb', line 540 def CreateUnderLine(input, ch) len = Builtins.size(input) ret = "" while Ops.greater_than(len, 0) ret = Ops.add(ret, ch) len = Ops.subtract(len, 1) end ret end |
- (Hash) DetectMountpoints
Detect mount points
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 |
# File '../../src/include/backup/functions.rb', line 863 def DetectMountpoints if Mode.test Builtins.y2milestone("SKIPPING") return {} end Yast.import "Storage" targetmap = Convert.convert( Storage.GetTargetMap, :from => "map <string, map>", :to => "map <string, map <string, any>>" ) Builtins.y2debug("targetmap: %1", targetmap) devices = {} Builtins.foreach(targetmap) do |disk, info| partitions = Ops.get_list(info, "partitions", []) Builtins.foreach(partitions) do |part_info| device = Ops.get_string(part_info, "device") mpoint = Ops.get_string(part_info, "mount") fs = Ops.get_symbol(part_info, "detected_fs") Builtins.y2debug("device: %1, mount: %2, fs: %3", device, mpoint, fs) # check for valid device and mount point name, ignore some filesystems if device != nil && mpoint != nil && fs != :swap && fs != :lvm && fs != :raid && fs != :xbootpdisk && fs != :xhibernate Ops.set(devices, device, { "mpoint" => mpoint, "fs" => fs }) end end end Builtins.y2milestone("Detected mountpoints: %1", devices) deep_copy(devices) end |
- (Array) Ext2Filesystems
Returns list of Ext2 mountpoints - actually mounted and from /etc/fstab file
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File '../../src/include/backup/functions.rb', line 195 def Ext2Filesystems mounted = Convert.convert( SCR.Read(path(".proc.mounts")), :from => "any", :to => "list <map <string, any>>" ) ext2mountpoints = [] tmp_parts = [] Builtins.foreach(mounted) do |m| fs = Ops.get_string(m, "vfstype") dev = Ops.get_string(m, "spec") file = Ops.get_string(m, "file") if fs == "ext2" && dev != nil && !Builtins.contains(tmp_parts, dev) ext2mountpoints = Builtins.add( ext2mountpoints, { "partition" => dev, "mountpoint" => file } ) tmp_parts = Builtins.add(tmp_parts, dev) end end if mounted != nil fstab = Convert.convert( SCR.Read(path(".etc.fstab")), :from => "any", :to => "list <map <string, any>>" ) Builtins.foreach(fstab) do |f| fs = Ops.get_string(f, "vfstype") dev = Ops.get_string(f, "spec") file = Ops.get_string(f, "file") if fs == "ext2" && dev != nil && !Builtins.contains(tmp_parts, dev) ext2mountpoints = Builtins.add( ext2mountpoints, { "partition" => dev, "mountpoint" => file } ) tmp_parts = Builtins.add(tmp_parts, dev) end end if fstab != nil deep_copy(ext2mountpoints) end |
- (String) Ext2MountPoint(device_name)
Return mount point for Ext2 partition. This function at first checks if partition is mounted. If yes it returns actual mout point, if no it searches mount point from /etc/fstab file.
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File '../../src/include/backup/functions.rb', line 352 def Ext2MountPoint(device_name) # chack if partition is now mounted mp = Convert.convert( SCR.Read(path(".proc.mounts")), :from => "any", :to => "list <map <string, any>>" ) result = nil Builtins.foreach(mp) do |p| d = Ops.get_string(p, "file") dev = Ops.get_string(p, "spec") fs = Ops.get_string(p, "vfstype") result = d if fs == "ext2" && dev == device_name end if mp != nil # if partition is not mounted then search mount point from fstab if result == nil fstab = Convert.convert( SCR.Read(path(".etc.fstab")), :from => "any", :to => "list <map <string, any>>" ) Builtins.foreach(fstab) do |p| d = Ops.get_string(p, "file") dev = Ops.get_string(p, "spec") fs = Ops.get_string(p, "vfstype") result = d if fs == "ext2" && dev == device_name end if fstab != nil end result end |
- (Hash) get_free_space(directory)
Get available space in the directory $["device" : string(device), "total" : integer(total), "used" : integer(used), "free" : integer(free) ]
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 |
# File '../../src/include/backup/functions.rb', line 1006 def get_free_space(directory) if Builtins.size(directory) == 0 Builtins.y2warning("Wrong parameter directory: %1", directory) return {} end cmd = Builtins.sformat("/bin/df -P '%1'", String.Quote(directory)) result = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) exit = Ops.get_integer(result, "exit", -1) if exit != 0 Builtins.y2warning("Command %1 failed, exit: %2", cmd, exit) return {} end out = Builtins.splitstring(Ops.get_string(result, "stdout", ""), "\n") # ignore header on the first line line = Ops.get_string(out, 1, "") device = Builtins.regexpsub( line, "^([^ ]*) +([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+%", "\\1" ) total = Builtins.regexpsub( line, "^([^ ]*) +([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+%", "\\2" ) used = Builtins.regexpsub( line, "^([^ ]*) +([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+%", "\\3" ) free = Builtins.regexpsub( line, "^([^ ]*) +([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+%", "\\4" ) { "device" => device, "total" => Builtins.tointeger(total), "used" => Builtins.tointeger(used), "free" => Builtins.tointeger(free) } end |
- (String) GetBaseName(file)
Get base file name without extension
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File '../../src/include/backup/functions.rb', line 467 def GetBaseName(file) result = "" return result if file == nil || file == "" dirs = Builtins.splitstring(file, "/") filename = Ops.get(dirs, Ops.subtract(Builtins.size(dirs), 1), "") parts = Builtins.splitstring(filename, ".") if Ops.greater_than(Builtins.size(parts), 1) # remove last part (extension) parts = Builtins.remove(parts, Ops.subtract(Builtins.size(parts), 1)) filename = Builtins.mergestring(parts, ".") end result = filename result end |
- (Array<String>) GetInstallPackages
Read packages available on the installation sources (Requires at least one installation source, otherwise return empty list)
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 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 |
# File '../../src/include/backup/functions.rb', line 758 def GetInstallPackages # function returns empty list return [] Builtins.y2milestone("--- backup_get_packages ---") # was: return (list <string>) WFM::call("backup_get_packages", []); # bugzilla #224899, saves memory occupied by zypp data (packager) temporary_file = Builtins.sformat( "%1/backup-list-of-packages", Directory.tmpdir ) if FileUtils.Exists(temporary_file) SCR.Execute(path(".target.remove"), temporary_file) end yastbin = "" if FileUtils.Exists("/sbin/yast") yastbin = "/sbin/yast" elsif FileUtils.Exists("/sbin/yast2") yastbin = "/sbin/yast2" else Builtins.y2error("Neither /sbin/yast nor /sbin/yast2 exist") return [] end # breaks ncurses cmd = Builtins.sformat( "%1 backup_get_packages %2 1>/dev/null 2>/dev/null", yastbin, temporary_file ) Builtins.y2milestone("Running command: '%1'", cmd) command = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) ret = [] if Ops.get(command, "exit") != 0 Builtins.y2error("Unexpected error: %1", command) ret = [] else if FileUtils.Exists(temporary_file) ret = Convert.convert( SCR.Read(path(".target.ycp"), temporary_file), :from => "any", :to => "list <string>" ) SCR.Execute(path(".target.remove"), temporary_file) if ret == nil ret = [] Builtins.y2error("Error while reading %1", temporary_file) else Builtins.y2milestone("backup_get_packages found %1 packages", ret) end end end Builtins.y2debug("Client returned %1", ret) Builtins.y2milestone("--- backup_get_packages ---") deep_copy(ret) end |
- (Array) GetListWithFlags(_in, selected)
This function reads two lists: full list and selection list (contains subset of items in full list). Returned list can be used in MultiSelectionBox widget.
246 247 248 249 250 251 252 253 254 |
# File '../../src/include/backup/functions.rb', line 246 def GetListWithFlags(_in, selected) _in = deep_copy(_in) selected = deep_copy(selected) return [] if _in == nil Builtins.maplist(_in) do |i| Item(Id(i), i, Builtins.contains(selected, i) ? true : false) end end |
- (Array) GetMountedFilesystems
Returns list of mounted file systems types.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File '../../src/include/backup/functions.rb', line 171 def GetMountedFilesystems mounted = Convert.convert( SCR.Read(path(".proc.mounts")), :from => "any", :to => "list <map <string, any>>" ) result = [] return [] if mounted == nil Builtins.foreach(mounted) do |m| fs = Ops.get_string(m, "vfstype") Ops.set(result, Builtins.size(result), fs) if fs != nil end Builtins.toset(result) end |
- (Object) initialize_backup_functions(include_target)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File '../../src/include/backup/functions.rb', line 17 def initialize_backup_functions(include_target) Yast.import "UI" Yast.import "Label" Yast.import "Report" Yast.import "Nfs" Yast.import "Popup" Yast.import "FileUtils" Yast.import "Mode" Yast.import "Directory" Yast.import "String" textdomain "backup" end |
- (Object) IsPossibleToCreateDirectoryOrExists(directory)
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 |
# File '../../src/include/backup/functions.rb', line 1055 def IsPossibleToCreateDirectoryOrExists(directory) = "" directory_path = Builtins.splitstring(directory, "/") tested_directory = "" Builtins.foreach(directory_path) do |dir| tested_directory = Ops.add( Ops.add(tested_directory, tested_directory != "/" ? "/" : ""), dir ) Builtins.y2debug("TESTING: %1", tested_directory) # directory exists if FileUtils.Exists(tested_directory) # exists, but it isn't a directory, can't create archive 'inside' if !FileUtils.IsDirectory(tested_directory) Builtins.y2error( "Cannot create backup archive in '%1', '%2' is not a directory.", directory, tested_directory ) = Builtins.sformat( # Popup error message, %1 is a directory somewhere under %2, %2 was tested for existency _( "Cannot create backup archive in %1.\n" + "%2 is not a directory.\n" + "Enter another one or remove %2." ), directory, tested_directory ) raise Break end # directory doesn't exist, will be created else raise Break end end end |
- (Array) MediaList2UIList(media)
Convert media description list to ComboBox items list
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File '../../src/include/backup/functions.rb', line 315 def MediaList2UIList(media) media = deep_copy(media) result = [] return [] if media == nil Builtins.foreach(media) do |v| i = Ops.get_symbol(v, "symbol") l = Ops.get_string(v, "label") result = Builtins.add(result, Item(Id(i), l)) if i != nil && l != nil end deep_copy(result) end |
- (Array) MpointTableContents(selected, all, description)
Create table content with detected mount points
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 |
# File '../../src/include/backup/functions.rb', line 907 def MpointTableContents(selected, all, description) selected = deep_copy(selected) all = deep_copy(all) description = deep_copy(description) Builtins.y2milestone( "selected: %1, description: %2", selected, description ) Yast.import "FileSystems" ret = [] processed = {} if Ops.greater_than(Builtins.size(description), 0) Builtins.foreach(description) do |device, info| dir = Ops.get_string(info, "mpoint", "") fs = FileSystems.GetName( Ops.get_symbol(info, "fs", :unknown), _("Unknown file system") ) mark = Builtins.contains(selected, dir) ? "X" : " " Ops.set(processed, dir, true) ret = Builtins.add( ret, Item(Id(dir), mark, Ops.add(dir, " "), Ops.add(device, " "), fs) ) end end if Ops.greater_than(Builtins.size(all), 0) # check for user defined directories Builtins.foreach(all) do |d| if Ops.get_boolean(processed, d, false) == false ret = Builtins.add( ret, Item(Id(d), Builtins.contains(selected, d) ? "X" : " ", d, "", "") ) end end end deep_copy(ret) end |
- (String) NFSfile(server, share, filename)
Create NFS file description string
989 990 991 992 993 994 995 996 997 998 999 |
# File '../../src/include/backup/functions.rb', line 989 def NFSfile(server, share, filename) if Builtins.size(server) == 0 || Builtins.size(share) == 0 || Builtins.size(filename) == 0 return nil end # check if filename begins with '/' character slash = Builtins.substring(filename, 0, 1) == "/" ? "" : "/" Ops.add(Ops.add(Ops.add(Ops.add(server, ":"), share), slash), filename) end |
- (Boolean) NFSFileExists(server, share, filename)
Check whether file on the NFS server exists
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
# File '../../src/include/backup/functions.rb', line 959 def NFSFileExists(server, share, filename) if Builtins.size(server) == 0 || Builtins.size(share) == 0 || Builtins.size(filename) == 0 return nil end mpoint = Nfs.Mount(server, share, nil, "", "") return nil if mpoint == nil ret = Ops.greater_or_equal( Convert.to_integer( SCR.Read( path(".target.size"), Ops.add(Ops.add(mpoint, "/"), filename) ) ), 0 ) Nfs.Unmount(mpoint) ret end |
- (String) SecondsToDateString(sec)
Convert number of second since 1.1.1970 to string. Result has format YYYYMMDDHHMMSS
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
# File '../../src/include/backup/functions.rb', line 727 def SecondsToDateString(sec) # convert seconds to time string - use localtime function in perl result = Convert.to_map( SCR.Execute( path(".target.bash_output"), Ops.add( Ops.add( "/usr/bin/perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(", Builtins.sformat("%1", sec) ), ");\n" + "$mon++;\n" + "$year += 1900;\n" + "printf (\"%d%02d%02d%02d%02d%02d\", $year, $mon, $mday, $hour, $min, $sec);'" ) ) ) ret = Ops.get_integer(result, "exit", -1) == 0 ? Ops.get_string(result, "stdout", Builtins.sformat("%1", sec)) : Builtins.sformat("%1", sec) Builtins.y2debug("time string: %1", ret) ret end |
- (Boolean) SendMail(user, subject, message)
Send mail to specified user
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File '../../src/include/backup/functions.rb', line 493 def SendMail(user, subject, ) # check user return false if user == "" || user == nil # get temporary directory d = Convert.to_string(SCR.Read(path(".target.tmpdir"))) if d == "" || d == nil Builtins.y2security("Using /tmp directory for temporary files!") d = "/tmp" end mail_file = Ops.add(d, "/mail") # write mail body to the temporary file if SCR.Write(path(".target.string"), mail_file, ) == false return false end # send mail - set UTF-8 charset for message text SCR.Execute( path(".target.bash"), Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( "export charset=UTF-8; export ttycharset=UTF-8; /bin/cat ", mail_file ), " | /usr/bin/mail " ), user ), " -s '" ), subject ), "'" ) ) == 0 end |
- (Boolean) SendSummary(remove_result, cron_profile, backup_result, backup_details)
Send summary mail of the backup process to root.
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 713 714 715 716 717 718 719 720 721 722 |
# File '../../src/include/backup/functions.rb', line 555 def SendSummary(remove_result, cron_profile, backup_result, backup_details) remove_result = deep_copy(remove_result) br = "\n" # e-mail subject - %1 is profile name subject = Builtins.sformat(_("YaST Automatic Backup (%1)"), cron_profile) # get all warnings and errors from Report module reported = Report.GetMessages( Ops.greater_than(Report.NumWarnings, 0), Ops.greater_than(Report.NumErrors, 0), false, false ) # TODO: remove richtext tags from Report:: result if Ops.greater_than(Report.NumErrors, 0) # text added to the subject if an error occured subject = Ops.add(subject, _(": FAILED")) end Builtins.y2debug("remove_result: %1", remove_result) removed = "" if Ops.greater_than( Builtins.size(Ops.get_list(remove_result, "removed", [])), 0 ) # header in email body followed by list of files removed = Ops.add(_("Removed Old Archives:"), br) Builtins.foreach(Ops.get_list(remove_result, "removed", [])) do |f| removed = Ops.add(Ops.add(removed, f), br) end end renamed = "" if Ops.greater_than( Builtins.size(Ops.get_map(remove_result, "renamed", {})), 0 ) # header in email body followed by list of files renamed = Ops.add(_("Renamed Old Archives:"), br) Builtins.foreach(Ops.get_map(remove_result, "renamed", {})) do |from, to| renamed = Ops.add( Ops.add(Ops.add(Ops.add(renamed, from), " -> "), to), br ) end end # header in email body oldarch = _("Changed Existing Archives:") ren_header = Ops.greater_than(Builtins.size(renamed), 0) || Ops.greater_than(Builtins.size(removed), 0) ? Ops.add(Ops.add(oldarch, br), CreateUnderLine(oldarch, "=")) : "" # header in email body summary_heading = _("Summary:") # header in email body detail_heading = _("Details:") # header in email body body = Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Builtins.sformat( _("BACKUP REPORT for Profile %1"), cron_profile ), br ), br ), br ), # header in email body followed by errors or warnings Ops.greater_than(Builtins.size(reported), 0) ? Ops.add( Ops.add( Ops.add( Ops.add( _( "Problems During Automatic Backup:" ), br ), reported ), br ), br ) : "" ), summary_heading ), br ), CreateUnderLine(summary_heading, "=") ), br ), br ), backup_result ), br ), Ops.greater_than(Builtins.size(ren_header), 0) ? Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Ops.add(Ops.add(ren_header, br), br), renamed ), br ), br ), removed ), br ), br ) : "" ), detail_heading ), br ), CreateUnderLine(detail_heading, "=") ), br ), br ), backup_details ) if SendMail("root", subject, body) == false Builtins.y2error("Cannot send report") return false end true end |
- (void) SetMultiWidgetsState
This method returns an undefined value.
Set state of depending widgets in Multiple volume options dialog
335 336 337 338 339 340 341 342 343 344 345 |
# File '../../src/include/backup/functions.rb', line 335 def SetMultiWidgetsState tmp_multi = Convert.to_boolean(UI.QueryWidget(Id(:multi_volume), :Value)) UI.ChangeWidget(Id(:vol), :Enabled, tmp_multi) user = tmp_multi && Convert.to_symbol(UI.QueryWidget(Id(:vol), :Value)) == :user_defined UI.ChangeWidget(Id(:user_size), :Enabled, user) UI.ChangeWidget(Id(:user_unit), :Enabled, user) nil end |
- (Object) ShowEditBrowseDialog(label, value)
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File '../../src/include/backup/functions.rb', line 122 def ShowEditBrowseDialog(label, value) label = "" if label == nil value = "" if value == nil UI.OpenDialog( VBox( HBox( InputField(Id(:te), Opt(:hstretch), label, value), HSpacing(1.0), VBox(VSpacing(0.9), PushButton(Id(:browse), Label.BrowseButton)) ), VSpacing(1.0), HBox( PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton), PushButton(Id(:cancel), Opt(:key_F9), Label.CancelButton) ) ) ) UI.SetFocus(Id(:te)) input = nil while true input = Convert.to_symbol(UI.UserInput) if input == :browse start_dir = value == "" ? "/" : value new_dir = UI.AskForExistingDirectory( start_dir, _("Select a directory to be included...") ) UI.ChangeWidget(Id(:te), :Value, new_dir) if new_dir != nil elsif input == :ok || input == :cancel break end end text = Convert.to_string(UI.QueryWidget(Id(:te), :Value)) UI.CloseDialog { "text" => text, "clicked" => input } end |
- (Hash) ShowEditDialog(label, value, values, forbidden_letters)
Ask user for some value: display dialog with label, text entry and OK/Cancel buttons.
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 |
# File '../../src/include/backup/functions.rb', line 75 def ShowEditDialog(label, value, values, forbidden_letters) values = deep_copy(values) forbidden_letters = deep_copy(forbidden_letters) label = "" if label == nil value = "" if value == nil combo_content = [] if values != nil && Ops.greater_than(Builtins.size(values), 0) combo_content = Builtins.maplist(values) do |v| Item(Id(v), v, v == value) end end UI.OpenDialog( VBox( Ops.greater_than(Builtins.size(combo_content), 0) ? ComboBox(Id(:te), Opt(:hstretch, :editable), label, combo_content) : InputField(Id(:te), Opt(:hstretch), label, value), VSpacing(1.0), HBox( PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton), PushButton(Id(:cancel), Opt(:key_F9), Label.CancelButton) ) ) ) UI.SetFocus(Id(:te)) input = Convert.to_symbol(UI.UserInput) text = Convert.to_string(UI.QueryWidget(Id(:te), :Value)) UI.CloseDialog if forbidden_letters != nil && forbidden_letters != [] Builtins.foreach(forbidden_letters) do |one_letter| text = Builtins.mergestring( Builtins.splitstring(text, one_letter), "" ) end end { "text" => text, "clicked" => input } end |