Class: Yast::SysconfigClass
- Inherits:
-
Module
- Object
- Module
- Yast::SysconfigClass
- Defined in:
- ../../src/modules/Sysconfig.rb
Instance Method Summary (collapse)
-
- (Symbol) ConfirmationDialog(message, command)
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
-
- (Symbol) StartCommand(start_command, label, error, confirm, confirmaction)
Start activation command, ask user to confirm it when it is required.
-
- (Object) Summary
Create a textual summary.
-
- (Boolean) Write
Write all sysconfig settings.
Instance Method Details
- (Symbol) ConfirmationDialog(message, command)
Display confirmation dialog
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 |
# File '../../src/modules/Sysconfig.rb', line 877 def ConfirmationDialog(, command) UI.OpenDialog( Opt(:decorated), VBox( Label(), Ops.greater_than(Builtins.size(command), 0) ? Label(Ops.add(_("Command: "), command)) : Empty(), VSpacing(0.5), HBox( PushButton(Id(:cont), Label.ContinueButton), # button label PushButton(Id(:skip), _("S&kip")), PushButton(Id(:abort), Label.AbortButton) ) ) ) ret = nil while ret != :cont && ret != :skip && ret != :abort ret = Convert.to_symbol(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.)
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 |
# File '../../src/modules/Sysconfig.rb', line 1245 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
726 727 728 729 730 731 732 733 734 735 |
# File '../../src/modules/Sysconfig.rb', line 726 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
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
# File '../../src/modules/Sysconfig.rb', line 739 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
382 383 384 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 |
# File '../../src/modules/Sysconfig.rb', line 382 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
107 108 109 110 111 112 113 114 115 116 117 |
# File '../../src/modules/Sysconfig.rb', line 107 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
375 376 377 |
# File '../../src/modules/Sysconfig.rb', line 375 def get_location_from_id(id) Ops.get(@variable_locations, id, "") end |
- (Array<String>) get_metadata(input)
Get metadata lines from input string
270 271 272 273 274 275 |
# File '../../src/modules/Sysconfig.rb', line 270 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
713 714 715 716 717 718 719 720 721 722 |
# File '../../src/modules/Sysconfig.rb', line 713 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
91 92 93 94 95 96 97 98 99 100 101 |
# File '../../src/modules/Sysconfig.rb', line 91 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
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File '../../src/modules/Sysconfig.rb', line 122 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.)
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 |
# File '../../src/modules/Sysconfig.rb', line 1228 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
71 72 73 |
# File '../../src/modules/Sysconfig.rb', line 71 def inspect "<#{self} @configfiles=#{@configfiles} >" end |
- (Object) main
16 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 |
# File '../../src/modules/Sysconfig.rb', line 16 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" @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
707 708 709 |
# File '../../src/modules/Sysconfig.rb', line 707 def modified(varid) Builtins.haskey(@modified_variables, varid) end |
- (Object) Modified
Data was modified?
77 78 79 |
# File '../../src/modules/Sysconfig.rb', line 77 def Modified Ops.greater_than(Builtins.size(@modified_variables), 0) || @config_modified end |
- (Hash) parse_metadata(comment)
Parse metadata from comment
280 281 282 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 |
# File '../../src/modules/Sysconfig.rb', line 280 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
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 |
# File '../../src/modules/Sysconfig.rb', line 789 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"), Ops.add( Ops.add( Ops.add( Ops.add(Ops.add(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)
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 |
# File '../../src/modules/Sysconfig.rb', line 760 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
255 256 257 258 259 260 261 262 263 264 265 |
# File '../../src/modules/Sysconfig.rb', line 255 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
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 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 |
# File '../../src/modules/Sysconfig.rb', line 149 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.)
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 |
# File '../../src/modules/Sysconfig.rb', line 1197 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
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 |
# File '../../src/modules/Sysconfig.rb', line 568 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
81 82 83 84 85 |
# File '../../src/modules/Sysconfig.rb', line 81 def SetModified @config_modified = true nil end |
- (Symbol) StartCommand(start_command, label, error, confirm, confirmaction)
Start activation command, ask user to confirm it when it is required.
Display specified error message when the command fails. skip -
command was skipped,
abort - command starting was aborted
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 |
# File '../../src/modules/Sysconfig.rb', line 917 def StartCommand(start_command, label, error, confirm, confirmaction) return :success if Builtins.size(start_command) == 0 # set progress bar label Progress.Title(label) if confirmaction == true # show confirmation dialog input = ConfirmationDialog(confirm, start_command) return input if input != :cont end Builtins.y2milestone("Starting: %1", start_command) exit = Convert.to_integer( SCR.Execute( path(".target.bash"), Ops.add(start_command, " > /dev/null 2> /dev/null") ) ) Builtins.y2milestone("Result: %1", exit) if exit != 0 Report.Error(error) return :failed end :success end |
- (Object) Summary
Create a textual summary
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 |
# File '../../src/modules/Sysconfig.rb', line 1267 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
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 |
# File '../../src/modules/Sysconfig.rb', line 952 def Write # remember all actions - start each action only once _Restarted = {} _Reloaded = {} _Commands = {} # aborted? abort = false # start presave commands Builtins.foreach(@modified_variables) do |vid, new_val| next if abort # get activation map for variable presave = Ops.get_string(@actions, [vid, "Pre"]) if presave != nil && Ops.greater_than(Builtins.size(presave), 0) confirm = _("A command will be executed") label = Builtins.sformat(_("Starting command: %1..."), presave) error = Builtins.sformat(_("Command %1 failed"), presave) precommandresult = StartCommand( presave, label, error, confirm, @ConfirmActions ) abort = true if precommandresult == :abort end end return false if abort Builtins.foreach(@modified_variables) do |vid, new_val| # get activation map for variable activate = Ops.get_map(@actions, vid, {}) restart_service = Ops.get_string(activate, "Rest") reload_service = Ops.get_string(activate, "Reld") bash_command = Ops.get_string(activate, "Cmd") if restart_service != nil && Ops.greater_than(Builtins.size(restart_service), 0) parsed = String.ParseOptions(restart_service, @parse_param) Builtins.foreach(parsed) { |s| Ops.set(_Restarted, s, true) } end if reload_service != nil && Ops.greater_than(Builtins.size(reload_service), 0) parsed = String.ParseOptions(reload_service, @parse_param) Builtins.foreach(parsed) { |s| Ops.set(_Reloaded, s, true) } end if bash_command != nil && Ops.greater_than(Builtins.size(bash_command), 0) Ops.set(_Commands, bash_command, true) end end # write dialog caption caption = _("Saving sysconfig Configuration") # set the right number of stages steps = Ops.add( Ops.add( Ops.add( Ops.add( Ops.add( Builtins.size(@modified_variables), Builtins.size(_Restarted) ), Builtins.size(_Reloaded) ), Builtins.size(_Commands) ), 1 ), # flush 3 ) # 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 = true # save each changed variable Builtins.foreach(@modified_variables) do |vid, new_val| file = get_file_from_id(vid) name = get_name_from_id(vid) value_path = Builtins.add( Builtins.add(path(".syseditor.value"), file), name ) written = SCR.Write(value_path, new_val) if written == false # error popup: %1 - variable name (e.g. DISPLAYMANAGER), %2 - file name (/etc/sysconfig/displaymanager) Report.Error( Builtins.sformat( _("Saving variable %1 to the file %2 failed."), name, file ) ) ret = false end # progress bar label, %1 is variable name (e.g. DISPLAYMANAGER) Progress.Title(Builtins.sformat(_("Saving variable %1..."), name)) Progress.NextStep end Progress.Title(_("Saving changes to the files...")) # flush changes SCR.Write(path(".syseditor"), nil) Progress.NextStep # now start required activation commands Progress.NextStage return false if abort if Ops.greater_than(Builtins.size(_Reloaded), 0) # restart required services Builtins.foreach(_Reloaded) do |servicename, dummy| next if abort # check whether service is running check_command = Builtins.sformat("/etc/init.d/%1 status", servicename) result = Convert.to_integer( SCR.Execute(path(".target.bash"), check_command) ) Builtins.y2milestone("%1 service status: %2", servicename, result) if result == 0 # service is running, reload it start_command = Builtins.sformat( "/etc/init.d/%1 reload", servicename ) confirm = Builtins.sformat( _("Service %1 will be reloaded"), servicename ) label = Builtins.sformat(_("Reloading service %1..."), servicename) error = Builtins.sformat( _("Reload of the service %1 failed"), servicename ) Progress.NextStep if StartCommand( start_command, label, error, confirm, @ConfirmActions ) == :abort abort = true end end end end return false if abort if Ops.greater_than(Builtins.size(_Restarted), 0) # restart required services Builtins.foreach(_Restarted) do |servicename, dummy| # check whether service is running check_command = Builtins.sformat("/etc/init.d/%1 status", servicename) result = Convert.to_integer( SCR.Execute(path(".target.bash"), check_command) ) Builtins.y2milestone("%1 service status: %2", servicename, result) Progress.NextStep if result == 0 # service is running, restart it start_command = Builtins.sformat( "/etc/init.d/%1 restart", servicename ) confirm = Builtins.sformat( _("Service %1 will be restarted"), servicename ) label = Builtins.sformat(_("Restarting service %1..."), servicename) error = Builtins.sformat( _("Restart of the service %1 failed"), servicename ) if StartCommand( start_command, label, error, confirm, @ConfirmActions ) == :abort abort = true end end end end if Ops.greater_than(Builtins.size(_Commands), 0) # start generic commands Builtins.foreach(_Commands) do |cmd, dummy| Builtins.y2milestone("Command: %1", cmd) Progress.NextStep if Ops.greater_than(Builtins.size(cmd), 0) confirm = _("A command will be executed") label = Builtins.sformat(_("Starting command: %1..."), cmd) error = Builtins.sformat(_("Command %1 failed"), cmd) if StartCommand(cmd, label, error, confirm, @ConfirmActions) == :abort abort = true end end end end return false if abort # set 100% in progress bar Progress.NextStep Progress.Title(_("Finished")) # set "finished" mark for the last stage Progress.NextStage ret end |