Class: Yast::SysconfigClass
- Inherits:
-
Module
- Object
- Module
- Yast::SysconfigClass
- Includes:
- Logger
- Defined in:
- ../../src/modules/Sysconfig.rb
Instance Method Summary (collapse)
-
- (Symbol) ConfirmationDialog(message)
Display confirmation dialog.
-
- (Array) Export
Dump the sysconfig settings to a single map (For use by autoinstallation.).
-
- (Array) get_all
Get list of all variables.
-
- (Hash) get_all_names
Get map of all variables.
-
- (Hash) get_description(varid)
Get description of selected variable.
-
- (String) get_file_from_id(id)
Get file name where is variable located from variable identification.
-
- (String) get_location_from_id(id)
Get variable location in tree widget from variable identification.
-
- (Array<String>) get_metadata(input)
Get metadata lines from input string.
-
- (Array) get_modified
Get list of modified variables.
-
- (String) get_name_from_id(id)
Get variable name from variable identification or empty string if input is invalid.
-
- (String) get_only_comment(input)
Get comment without metadata.
-
- (Boolean) Import(settings)
Set all sysconfig settings from the list and read information from files (For use by autoinstallation.).
- - (Object) inspect
- - (Object) main
-
- (Boolean) modified(varid)
Return modification status of variable.
-
- (Object) Modified
Data was modified?.
-
- (Hash) parse_metadata(comment)
Parse metadata from comment.
-
- (Object) Read
Read all sysconfig variables.
-
- (Object) RegisterAgents
Register .syseditor path (use INI agent in multiple file mode).
-
- (String) remove_whitespaces(input)
Remove white spaces at beginning or at the end of string.
-
- (Array<String>) Search(params, show_progress)
Search in syscnfig files for value.
-
- (Object) Set(settings)
Set all sysconfig settings from the list (For use by autoinstallation.).
-
- (Symbol) set_value(variable, new_value, force, force_change)
Set new variable value.
- - (Object) SetModified
-
- (Object) Summary
Create a textual summary.
-
- (Boolean) Write
Write all sysconfig settings.
Instance Method Details
- (Symbol) ConfirmationDialog(message)
Display confirmation dialog
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 |
# File '../../src/modules/Sysconfig.rb', line 870 def ConfirmationDialog() msg_lines = .lines.map {|l| Label(l) } UI.OpenDialog( Opt(:decorated), VBox( *msg_lines, VSpacing(0.5), HBox( PushButton(Id(:cont), Label.ContinueButton), # button label PushButton(Id(:skip), _("S&kip")), PushButton(Id(:abort), Label.AbortButton) ) ) ) ret = nil while ![:cont, :skip, :abort].include?(ret) ret = UI.UserInput ret = :abort if ret == :close end UI.CloseDialog ret end |
- (Array) Export
Dump the sysconfig settings to a single map (For use by autoinstallation.)
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
# File '../../src/modules/Sysconfig.rb', line 1024 def Export # return structured map (for 8.1 compatibility) ret = [] if Ops.greater_than(Builtins.size(@modified_variables), 0) Builtins.foreach(@modified_variables) do |varid, val| n = get_name_from_id(varid) f = get_file_from_id(varid) m = { "sysconfig_key" => n, "sysconfig_path" => f, "sysconfig_value" => val } ret = Builtins.add(ret, m) end end deep_copy(ret) end |
- (Array) get_all
Get list of all variables
729 730 731 732 733 734 735 736 737 738 |
# File '../../src/modules/Sysconfig.rb', line 729 def get_all ret = [] Builtins.foreach(@variable_locations) do |varid, new_value| ret = Builtins.add(ret, varid) end deep_copy(ret) end |
- (Hash) get_all_names
Get map of all variables
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
# File '../../src/modules/Sysconfig.rb', line 742 def get_all_names ret = {} Builtins.foreach(@variable_locations) do |varid, new_value| name = get_name_from_id(varid) if Builtins.haskey(ret, name) == true ret = Builtins.add( ret, name, Builtins.add(Ops.get(ret, name, []), varid) ) else ret = Builtins.add(ret, name, [varid]) end end deep_copy(ret) end |
- (Hash) get_description(varid)
Get description of selected variable
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
# File '../../src/modules/Sysconfig.rb', line 385 def get_description(varid) varname = get_name_from_id(varid) fname = get_file_from_id(varid) comment_path = Builtins.add( Builtins.add(path(".syseditor.value_comment"), fname), varname ) value_path = Builtins.add( Builtins.add(path(".syseditor.value"), fname), varname ) comment = Convert.to_string(SCR.Read(comment_path)) all_variables = SCR.Dir(Builtins.add(path(".syseditor.value"), fname)) used_comment = varname # no comment present if comment != nil && Builtins.size(comment) == 0 && !Builtins.regexpmatch(fname, "^/etc/sysconfig/network/ifcfg-.*") Builtins.y2warning("Comment for variable %1 is missing", varid) reversed = [] i = 0 found = false while Ops.less_than(i, Builtins.size(all_variables)) && found == false v = Ops.get(all_variables, i, "") if v == varname found = true else reversed = Builtins.prepend(reversed, v) end i = Ops.add(i, 1) end if found == true i = 0 comment = "" v = "" Builtins.y2debug("reversed: %1", reversed) while Ops.less_than(i, Builtins.size(reversed)) && comment == "" v = Ops.get(reversed, i, "") used_comment = v comment = Convert.to_string( SCR.Read( Builtins.add( Builtins.add(path(".syseditor.value_comment"), fname), v ) ) ) i = Ops.add(i, 1) end Builtins.y2warning( "Variable: %1 Using comment from variable: %2", varname, v ) end end # remove config file header at the beginning of the file # header is comment from beginning of the file to the empty line if used_comment == Ops.get(all_variables, 0, "") && comment != nil Builtins.y2debug("Reading first variable from the file") # comment is read from the first variable # remove header if it's present Builtins.y2debug("Whole comment: %1", comment) lines = Builtins.splitstring(comment, "\n") filtered = [] # remove last empty string from list (caused by last new line char) if Ops.get(lines, Ops.subtract(Builtins.size(lines), 1)) == "" lines = Builtins.remove(lines, Ops.subtract(Builtins.size(lines), 1)) end if Builtins.contains(lines, "") == true Builtins.y2milestone("Header comment detected") adding = false # filter out variables before empty line filtered = Builtins.filter(lines) do |line| if line == "" adding = true elsif adding == true next true end false end # merge strings comment = Builtins.mergestring(filtered, "\n") end end = (comment) template_only_comment = "" # for network configuration file read comments from configuration template if Builtins.regexpmatch(fname, "^/etc/sysconfig/network/ifcfg-.*") template_comment = Convert.to_string( SCR.Read( Builtins.add( Builtins.add(path(".sysconfig.network.template"), "value_comment"), varname ) ) ) = (template_comment) if Ops.greater_than(Builtins.size(), 0) # add missing metadata values from template Builtins.foreach() do |key, value| Ops.set(, key, value) if !Builtins.haskey(, key) end end template_only_comment = get_only_comment(template_comment) if Ops.greater_than(Builtins.size(template_only_comment), 0) template_only_comment = Ops.add(template_only_comment, "\n") end Builtins.y2milestone( "Comment read from template: %1", template_only_comment ) Builtins.y2milestone("Meta read from template: %1", ) end deflt = Ops.get_string(, "Default") if deflt != nil parsed = String.ParseOptions(deflt, @parse_param) Ops.set(, "Default", Ops.get_string(parsed, 0, "")) Builtins.y2debug( "Read default value: %1", Ops.get_string(parsed, 0, "") ) end new_value = Ops.get(@modified_variables, varid) # check if value was changed Ops.set(, "new_value", new_value) if new_value != nil Ops.set(, "name", varname) Ops.set(, "file", get_file_from_id(varid)) Ops.set( , "location", varname != "" ? get_location_from_id(varid) : varid ) Ops.set( , "comment", varname != "" ? Ops.add(template_only_comment, get_only_comment(comment)) : Ops.get_string(@node_comments, varid, "") ) Ops.set(, "value", SCR.Read(value_path)) # add action commands if Ops.greater_than(Builtins.size(Ops.get_map(@actions, varid, {})), 0) Ops.set(, "actions", Ops.get_map(@actions, varid, {})) end deep_copy() end |
- (String) get_file_from_id(id)
Get file name where is variable located from variable identification
110 111 112 113 114 115 116 117 118 119 120 |
# File '../../src/modules/Sysconfig.rb', line 110 def get_file_from_id(id) return "" if id == nil pos = Builtins.findfirstof(id, "$") if pos != nil && Ops.greater_or_equal(pos, 0) return Builtins.substring(id, Ops.add(pos, 1)) else return "" end end |
- (String) get_location_from_id(id)
Get variable location in tree widget from variable identification
378 379 380 |
# File '../../src/modules/Sysconfig.rb', line 378 def get_location_from_id(id) Ops.get(@variable_locations, id, "") end |
- (Array<String>) get_metadata(input)
Get metadata lines from input string
273 274 275 276 277 278 |
# File '../../src/modules/Sysconfig.rb', line 273 def (input) return [] if input == nil || input == "" lines = Builtins.splitstring(input, "\n") Builtins.filter(lines) { |line| Builtins.regexpmatch(line, "^##.*") } end |
- (Array) get_modified
Get list of modified variables
716 717 718 719 720 721 722 723 724 725 |
# File '../../src/modules/Sysconfig.rb', line 716 def get_modified ret = [] Builtins.foreach(@modified_variables) do |varid, new_value| ret = Builtins.add(ret, varid) end deep_copy(ret) end |
- (String) get_name_from_id(id)
Get variable name from variable identification or empty string if input is invalid
94 95 96 97 98 99 100 101 102 103 104 |
# File '../../src/modules/Sysconfig.rb', line 94 def get_name_from_id(id) return "" if id == nil pos = Builtins.findfirstof(id, "$") if pos != nil && Ops.greater_or_equal(pos, 0) return Builtins.substring(id, 0, Builtins.findfirstof(id, "$")) else return "" end end |
- (String) get_only_comment(input)
Get comment without metadata
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File '../../src/modules/Sysconfig.rb', line 125 def get_only_comment(input) return "" if input == nil || input == "" lines = Builtins.splitstring(input, "\n") ret = "" Builtins.foreach(lines) do |line| com_line = Builtins.regexpsub(line, "^#([^#].*)", "\\1") if com_line == nil # add empty lines if Builtins.regexpmatch(line, "^#[ \t]*$") == true ret = Ops.add(ret, "\n") end else ret = Ops.add(Ops.add(ret, com_line), "\n") end end ret end |
- (Boolean) Import(settings)
Set all sysconfig settings from the list and read information from files (For use by autoinstallation.)
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 |
# File '../../src/modules/Sysconfig.rb', line 1007 def Import(settings) settings = deep_copy(settings) settings_maps = Convert.convert( settings, :from => "list", :to => "list <map>" ) # set values in the list Set(settings_maps) # register agent for user defined files, read values true end |
- (Object) inspect
74 75 76 |
# File '../../src/modules/Sysconfig.rb', line 74 def inspect "<#{self} @configfiles=#{@configfiles} >" end |
- (Object) main
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 |
# File '../../src/modules/Sysconfig.rb', line 18 def main Yast.import "UI" textdomain "sysconfig" Yast.import "Progress" Yast.import "Report" Yast.import "Summary" Yast.import "Directory" Yast.import "Label" Yast.import "IP" Yast.import "String" Yast.import "Service" Yast.import "Mode" Yast.import "SystemdService" @configfiles = [ "/etc/sysconfig/*", "/etc/sysconfig/network/ifcfg-*", "/etc/sysconfig/network/dhcp", "/etc/sysconfig/network/config", Ops.add(Directory.ydatadir, "/descriptions"), "/etc/sysconfig/powersave/*", "/etc/sysconfig/uml/*" ] # Additional files from Import @custom_files = [] # modified variables @modified_variables = {} # comment for non-variable nodes @node_comments = {} # location for each variable @variable_locations = {} @parse_param = { "separator" => ",", "unique" => true, "remove_whitespace" => true } @write_only = false @tree_content = [] # map of actions to start when variable is modified @actions = {} @ConfirmActions = false @config_modified = false end |
- (Boolean) modified(varid)
Return modification status of variable
710 711 712 |
# File '../../src/modules/Sysconfig.rb', line 710 def modified(varid) Builtins.haskey(@modified_variables, varid) end |
- (Object) Modified
Data was modified?
80 81 82 |
# File '../../src/modules/Sysconfig.rb', line 80 def Modified Ops.greater_than(Builtins.size(@modified_variables), 0) || @config_modified end |
- (Hash) parse_metadata(comment)
Parse metadata from comment
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 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 |
# File '../../src/modules/Sysconfig.rb', line 283 def (comment) ret = {} # get metadata part of comment = (comment) joined_multilines = [] multiline = "" Builtins.y2debug("metadata: %1", ) # join multi line metadata lines Builtins.foreach() do || if Builtins.substring( , Ops.subtract(Builtins.size(), 1), 1 ) != "\\" if multiline != "" # this not first multiline so remove comment mark without_comment = Builtins.regexpsub(, "^##(.*)", "\\1") = without_comment if without_comment != nil end joined_multilines = Builtins.add( joined_multilines, Ops.add(multiline, ) ) multiline = "" else part = Builtins.substring( , 0, Ops.subtract(Builtins.size(), 1) ) if multiline != "" # this not first multiline so remove comment mark without_comment = Builtins.regexpsub(part, "^##(.*)", "\\1") part = without_comment if without_comment != nil end # add line to the previous lines multiline = Ops.add(multiline, part) end end Builtins.y2debug( "metadata after multiline joining: %1", joined_multilines ) # parse each metadata line Builtins.foreach(joined_multilines) do || # Ignore lines with ### -- general comments next if Builtins.regexpmatch(, "^###") = Builtins.regexpsub(, "^##[ \t]*(.*)", "\\1") # split sting to the tag and value part colon_pos = Builtins.findfirstof(, ":") tag = "" val = "" if colon_pos == nil # colon is missing tag = else tag = Builtins.substring(, 0, colon_pos) if Ops.greater_than(Builtins.size(), Ops.add(colon_pos, 1)) val = Builtins.substring(, Ops.add(colon_pos, 1)) end end # remove whitespaces from parts tag = remove_whitespaces(tag) val = remove_whitespaces(val) Builtins.y2milestone("tag: %1 val: '%2'", tag, val) # add tag and value to map if they are present in comment if tag != "" ret = Builtins.add(ret, tag, val) else # ignore separator lines if !Builtins.regexpmatch(, "^#*$") Builtins.y2warning("Unknown metadata line: %1", ) end end end deep_copy(ret) end |
- (Object) Read
Read all sysconfig variables
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 |
# File '../../src/modules/Sysconfig.rb', line 792 def Read # TODO: solve custom_files parameter problem (used in Import) # read only powerteak config or all sysconfig files files = deep_copy(@configfiles) tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir"))) if tmpdir == nil || tmpdir == "" Builtins.y2security("Using /tmp directory !") tmpdir = "/tmp" end # register .syseditor path RegisterAgents() # register agent for reading network template agentdef = Ops.add( Builtins.sformat( ".sysconfig.network.template,\n" + "\n" + "`ag_ini(`IniAgent(\"/etc/sysconfig/network/ifcfg.template\"\n" + "," ), Convert.to_string( SCR.Read( path(".target.string"), Ops.add(Directory.ydatadir, "/sysedit.agent") ) ) ) tmp = Ops.add(tmpdir, "/sysconfig-template-agent.scr") SCR.Write(path(".target.string"), tmp, agentdef) SCR.RegisterAgent(path(".sysconfig.network.template"), tmp) # list of all config files Builtins.y2milestone( "Registered config files: %1", SCR.Dir(path(".syseditor.section")) ) # create script options param = "" Builtins.foreach(files) do |par| param = Ops.add(Ops.add(Ops.add(param, "'"), par), "' ") end # create tree definition list and description map using external Perl script SCR.Execute( path(".target.bash"), "#{Directory.bindir}/parse_configs.pl #{param} > #{tmpdir}/treedef.ycp" ) # read list parsed_output = Convert.to_list( SCR.Read(path(".target.ycp"), Ops.add(tmpdir, "/treedef.ycp")) ) @tree_content = Ops.get_list(parsed_output, 0, []) @node_comments = Ops.get_map(parsed_output, 1, {}) @variable_locations = Ops.get_map(parsed_output, 2, {}) # redefined variables (variables which are defined in more files) redefined_vars = Ops.get_map(parsed_output, 3, {}) if Ops.greater_than(Builtins.size(redefined_vars), 0) Builtins.y2warning("Redefined variables: %1", redefined_vars) end # read map with activation commands @actions = Ops.get_map(parsed_output, 4, {}) true end |
- (Object) RegisterAgents
Register .syseditor path (use INI agent in multiple file mode)
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 |
# File '../../src/modules/Sysconfig.rb', line 763 def RegisterAgents files = deep_copy(@configfiles) tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir"))) if tmpdir == nil || tmpdir == "" Builtins.y2security("Using /tmp directory !") tmpdir = "/tmp" end # register configuration files in SCR using INI-agent agentdef = Ops.add( Builtins.sformat(".syseditor\n\n`ag_ini(`IniAgent( %1,\n", files), Convert.to_string( SCR.Read( path(".target.string"), Ops.add(Directory.ydatadir, "/sysedit.agent") ) ) ) tmp = Ops.add(tmpdir, "/sysconfig-agent.scr") SCR.Write(path(".target.string"), tmp, agentdef) SCR.RegisterAgent(path(".syseditor"), tmp) nil end |
- (String) remove_whitespaces(input)
Remove white spaces at beginning or at the end of string
258 259 260 261 262 263 264 265 266 267 268 |
# File '../../src/modules/Sysconfig.rb', line 258 def remove_whitespaces(input) return nil if input == nil removed_whitespaces = Builtins.regexpsub( input, "^[ \t]*(([^ \t]*[ \t]*[^ \t]+)*)[ \t]*$", "\\1" ) removed_whitespaces != nil ? removed_whitespaces : input end |
- (Array<String>) Search(params, show_progress)
Search in syscnfig files for value
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File '../../src/modules/Sysconfig.rb', line 152 def Search(params, show_progress) params = deep_copy(params) found = [] # get all configuration files files = SCR.Dir(path(".syseditor.section")) if show_progress == true # Translation: Progress bar label UI.OpenDialog( ProgressBar(Id(:progress), _("Searching..."), Builtins.size(files), 0) ) end search_varname = Ops.get_boolean(params, "varname", true) search_description = Ops.get_boolean(params, "description", false) search_value = Ops.get_boolean(params, "value", false) case_insensitive = Ops.get_boolean(params, "insensitive", false) search_string = Ops.get_string(params, "search", "") if search_string == "" UI.CloseDialog return deep_copy(found) end if case_insensitive == true search_string = Builtins.tolower(search_string) end index = 0 Builtins.foreach(files) do |file| # skip backup files if Builtins.regexpmatch(file, "\\.bak$") || Builtins.regexpmatch(file, "~$") Builtins.y2milestone("Ignoring backup file %1", file) next end # get all variables in file var_path = Builtins.add(path(".syseditor.value"), file) variables = SCR.Dir(var_path) Builtins.y2debug("Searching in file %1", file) Builtins.foreach(variables) do |var| already_found = false Builtins.y2debug("Searching in variable %1", var) if search_varname == true var2 = var var2 = Builtins.tolower(var) if case_insensitive if Builtins.issubstring(var2, search_string) found = Builtins.add(found, Ops.add(Ops.add(var, "$"), file)) already_found = true end end # search in variable value if it is requested and previous check was unsuccessful if search_value == true && already_found == false read_value = Convert.to_string( SCR.Read( Builtins.add(Builtins.add(path(".syseditor.value"), file), var) ) ) read_value = Builtins.tolower(read_value) if case_insensitive if Builtins.issubstring(read_value, search_string) found = Builtins.add(found, Ops.add(Ops.add(var, "$"), file)) already_found = true end end if search_description == true && already_found == false # read comment without metadata read_comment = get_only_comment( Convert.to_string( SCR.Read( Builtins.add( Builtins.add(path(".syseditor.value_comment"), file), var ) ) ) ) read_comment = Builtins.tolower(read_comment) if case_insensitive if Builtins.issubstring(read_comment, search_string) found = Builtins.add(found, Ops.add(Ops.add(var, "$"), file)) end end end if show_progress == true index = Ops.add(index, 1) UI.ChangeWidget(Id(:progress), :Value, index) end end UI.CloseDialog if show_progress == true Builtins.y2debug("Found: %1", found) deep_copy(found) end |
- (Object) Set(settings)
Set all sysconfig settings from the list (For use by autoinstallation.)
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 |
# File '../../src/modules/Sysconfig.rb', line 976 def Set(settings) settings = deep_copy(settings) if settings != nil @modified_variables = {} @custom_files = deep_copy(@configfiles) # convert from 8.1 export format Builtins.foreach(settings) do |setting| n = Ops.get_string(setting, "sysconfig_key", "") f = Ops.get_string(setting, "sysconfig_path", "") v = Ops.get_string(setting, "sysconfig_value", "") # compatibility mode for older release with relative path if Builtins.findfirstof(f, "/") != 0 f = Builtins.sformat("/etc/sysconfig/%1", f) end key = Builtins.sformat("%1$%2", n, f) @modified_variables = Builtins.add(@modified_variables, key, v) # add configuration file if it isn't already specified if !Builtins.contains(@custom_files, f) @custom_files = Builtins.add(@custom_files, f) end end end nil end |
- (Symbol) set_value(variable, new_value, force, force_change)
Set new variable value
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 |
# File '../../src/modules/Sysconfig.rb', line 571 def set_value(variable, new_value, force, force_change) desc = get_description(variable) name = get_name_from_id(variable) return :not_found if name == "" modif = Ops.get(@modified_variables, variable) old = Ops.get_string(desc, "value", "") # use default value (or emty string) instead of the curent value in autoyast if Mode.config old = Builtins.haskey(desc, "Default") ? Ops.get_string(desc, "Default", "") : "" end curr_val = modif != nil ? modif : old if force_change || new_value != curr_val Builtins.y2milestone( "variable: %1 changed from: %2 to: %3", variable, curr_val, new_value ) if new_value == old && !force_change # variable was reset to the original value, remove it from map of modified Builtins.y2debug( "Variable %1 was reset to the original value", variable ) @modified_variables = Builtins.remove(@modified_variables, variable) else valid = false if force == false # check data type type = Ops.get_string(desc, "Type", "string") if type == "string" || Builtins.regexpmatch(type, "^string\\(.*\\)$") == true # string type is valid always valid = true elsif type == "yesno" valid = new_value == "yes" || new_value == "no" elsif type == "boolean" valid = new_value == "true" || new_value == "false" elsif type == "integer" valid = Builtins.regexpmatch(new_value, "^-{0,1}[0-9]*$") elsif Builtins.regexpmatch(type, "^list\\(.*\\)$") listopt = Builtins.regexpsub(type, "^list\\((.*)\\)$", "\\1") parsed_opts = String.ParseOptions(listopt, @parse_param) valid = Builtins.contains(parsed_opts, new_value) elsif Builtins.regexpmatch( type, "^integer\\(-{0,1}[0-9]*:-{0,1}[0-9]*\\)$" ) # check if input is integer valid = Builtins.regexpmatch(new_value, "^-{0,1}[0-9]*$") if valid == true # it is integer, check range min = Builtins.regexpsub( type, "^integer\\((-{0,1}[0-9]*):-{0,1}[0-9]*\\)$", "\\1" ) max = Builtins.regexpsub( type, "^integer\\(-{0,1}[0-9]*:(-{0,1}[0-9]*)\\)$", "\\1" ) Builtins.y2milestone("min: %1 max: %2", min, max) min_int = Builtins.tointeger(min) max_int = Builtins.tointeger(max) new_int = Builtins.tointeger(new_value) Builtins.y2milestone( "min_int: %1 max_int: %2", min_int, max_int ) if max != "" && min != "" valid = Ops.greater_or_equal(new_int, min_int) && Ops.less_or_equal(new_int, max_int) elsif max == "" valid = Ops.greater_or_equal(new_int, min_int) elsif min == "" valid = Ops.less_or_equal(new_int, max_int) else # empty range, valid is set to true Builtins.y2warning( "empty integer range, assuming any integer" ) end end elsif Builtins.regexpmatch(type, "^regexp\\(.*\\)$") regex = Builtins.regexpsub(type, "^regexp\\((.*)\\)$", "\\1") valid = Builtins.regexpmatch(new_value, regex) elsif type == "ip" # check IP adress using function from network/ip.ycp include valid = IP.Check(new_value) elsif type == "ip4" # check IP adress using function from network/ip.ycp include valid = IP.Check4(new_value) elsif type == "ip6" # check IP adress using function from network/ip.ycp include valid = IP.Check6(new_value) else Builtins.y2warning( "Unknown data type %1 for variable %2", type, name ) end end if valid == false && force == false return :not_valid else Ops.set(@modified_variables, variable, new_value) return :ok end end end # value was not changed => OK :ok end |
- (Object) SetModified
84 85 86 87 88 |
# File '../../src/modules/Sysconfig.rb', line 84 def SetModified @config_modified = true nil end |
- (Object) Summary
Create a textual summary
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 |
# File '../../src/modules/Sysconfig.rb', line 1046 def Summary # configuration summary headline summary = Summary.AddHeader("", _("Configuration Summary")) Builtins.y2milestone("Summary: %1", @modified_variables) if Ops.greater_than(Builtins.size(@modified_variables), 0) Builtins.foreach(@modified_variables) do |varid, newval| varnam = get_name_from_id(varid) filename = get_file_from_id(varid) summary = Summary.AddLine( summary, Builtins.sformat("%1=\"%2\" (%3)", varnam, newval, filename) ) end else summary = Summary.AddLine(summary, Summary.NotConfigured) end summary end |
- (Boolean) Write
Write all sysconfig settings
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 |
# File '../../src/modules/Sysconfig.rb', line 902 def Write return false unless exec_pre_actions # remember all actions - start each action only once post_actions = calculate_post_actions # write dialog caption caption = _("Saving sysconfig Configuration") # set the right number of stages steps = @modified_variables.size + post_actions.values.flatten.size + 4 # 1 for flushing the cache plus 3 stages # We do not set help text here, because it was set outside Progress.New( caption, " ", steps, [ # progress bar item _("Write the new settings"), _("Activate the changes") ], nil, "" ) Progress.NextStage ret = save_modified_variables Progress.Title(_("Saving changes to the files...")) # flush changes SCR.Write(path(".syseditor"), nil) Progress.NextStep # now start required activation commands Progress.NextStage # reload required services post_actions[:reload].each do |servicename| Progress.NextStep next unless service_active?(servicename) return false if exec_service_action(servicename, :reload) == :abort end # restart required services post_actions[:restart].each do |servicename| Progress.NextStep next unless service_active?(servicename) return false if exec_service_action(servicename, :restart) == :abort end # start generic commands post_actions[:cmd].each do |cmd| Progress.NextStep next if cmd.nil? || cmd.size == 0 return false if exec_cmd_action(cmd) == :abort end Progress.NextStep Progress.Title(_("Finished")) # set "finished" mark for the last stage Progress.Finish ret end |