Class: Yast::ProviderClass
- Inherits:
-
Module
- Object
- Module
- Yast::ProviderClass
- Defined in:
- ../../src/modules/Provider.rb
Instance Method Summary (collapse)
-
- (Object) Add(type)
Add a new provider.
- - (Object) CheckType(type)
-
- (Object) Clone(name)
Clone the given provider.
- - (Object) CloneProvider
-
- (Object) CloneSystem(name)
Clone the given system provider.
-
- (Object) Commit
Commit pending operation.
-
- (Object) Delete(name)
Delete the given provider.
-
- (Object) Edit(name)
Edit the given provider.
-
- (Object) Export(type)
Export data.
- - (Object) Filter(providers, type)
- - (Object) FilterNOT(providers, type)
-
- (Array) FilterProviders(provs, type)
Filter providers based on the type.
-
- (Array) GetCountries
Get list of countries.
-
- (Object) GetCountry
This is a single point of dependence on the Language module of yast2-country-data.
-
- (Array) GetProviders(type, country, preselect)
Get providers from a group (country/other).
-
- (Object) Import(type, providers)
Import data.
-
- (Object) IsUnique(name)
Check if provider name is unique.
- - (Object) main
-
- (Object) Modified(type)
Were the providers changed?.
-
- (Object) Overview(type)
Create an overview table with all configured providers.
-
- (Object) ProviderType
Return current provider type.
-
- (Object) Read
Read providers data (custom only) and country mappings.
-
- (Object) Select(name)
Select the given provider.
-
- (Object) SelectSystem(name)
Select the given system provider.
-
- (Object) SortProviders(provs)
Sorts providers alphabeticly (non-case-sensitively) and by priority.
-
- (Object) Summary(type, split)
Create a textual summary and a list of unconfigured providers.
-
- (Object) Write(type)
Write custom providers data.
Instance Method Details
- (Object) Add(type)
Add a new provider
418 419 420 421 422 423 424 425 426 427 |
# File '../../src/modules/Provider.rb', line 418 def Add(type) @operation = nil return false if !CheckType(type) @Type = type return false if Select("") != true return false if CloneProvider() != true @LastCountry = @country @operation = :add true end |
- (Object) CheckType(type)
225 226 227 228 229 230 231 232 |
# File '../../src/modules/Provider.rb', line 225 def CheckType(type) Builtins.y2debug(2, "type=%1", type) if type != "all" && !Builtins.contains(@Supported, type) Builtins.y2error(2, "Unsupported provider type: %1", type) return false end true end |
- (Object) Clone(name)
Clone the given provider
491 492 493 494 495 496 497 |
# File '../../src/modules/Provider.rb', line 491 def Clone(name) @operation = nil return false if Select(name) != true return false if CloneProvider() != true @operation = :add true end |
- (Object) CloneProvider
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/Provider.rb', line 509 def CloneProvider fullname = Ops.get_string(@Current, "PROVIDER", "") Builtins.y2debug("fullname=%1", fullname) # Split possible (1) from the end if Builtins.regexpmatch(fullname, " \\([0-9]+\\)$") fullname = Builtins.regexpsub(fullname, "(.*) \\([0-9]+\\)$", "\\1") Builtins.y2debug("fullname=%1", fullname) end # Generate unique full name (Current["PROVIDER"]) suffix = 0 gen = fullname forbidden = Builtins.maplist(@Providers) do |k, v| Ops.get_string(v, "PROVIDER", "") end while Builtins.contains(forbidden, gen) suffix = Ops.add(suffix, 1) gen = Builtins.sformat("%1 (%2)", fullname, suffix) end Ops.set(@Current, "PROVIDER", gen) Builtins.y2debug("fullname=%1", gen) # Generate unique Name suffix = 0 name = @Name Builtins.y2debug("Name=%1", @Name) # Split possible number from the end if Builtins.regexpmatch(name, "[0-9]+$") name = Builtins.regexpsub(name, "(.*)[0-9]+", "\\1") Builtins.y2debug("name=%1", name) end # Sensible defaults for new providers gen = name if gen == "" gen = "provider0" name = "provider" end gen = "provider0" if gen == "provider" # Generate unique name (Name) forbidden = Map.Keys(@Providers) while Builtins.contains(forbidden, gen) suffix = Ops.add(suffix, 1) gen = Builtins.sformat("%1%2", name, suffix) end @Name = gen Builtins.y2debug("Name=%1", @Name) true end |
- (Object) CloneSystem(name)
Clone the given system provider
502 503 504 505 506 507 508 |
# File '../../src/modules/Provider.rb', line 502 def CloneSystem(name) @operation = nil return false if SelectSystem(name) != true return false if CloneProvider() != true @operation = :add true end |
- (Object) Commit
Commit pending operation
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File '../../src/modules/Provider.rb', line 460 def Commit Builtins.y2debug("operation=%1", @operation) if @operation == :add || @operation == :edit Builtins.y2debug("Providers=%1", @Providers) Ops.set(@Providers, @Name, @Current) Builtins.y2debug("Providers=%1", @Providers) elsif @operation == :delete if !Builtins.haskey(@Providers, @Name) Builtins.y2error("Key not found: %1", @Name) return false end @Providers = Builtins.remove(@Providers, @Name) Ops.set(@Deleted, Builtins.size(@Deleted), @Name) else Builtins.y2error("Unknown operation: %1 (%2)", @operation, @Name) return false end @Name = "" @Type = "" @Current = {} @operation = nil @LastCountry = @country Builtins.y2debug("LastCountry=%1", @LastCountry) true end |
- (Object) Delete(name)
Delete the given provider
444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File '../../src/modules/Provider.rb', line 444 def Delete(name) @operation = nil Builtins.y2debug("Delete(%1)", name) if !Builtins.haskey(@Providers, name) Builtins.y2error("Key not found: %1", name) return false end @Name = name @operation = :delete true end |
- (Object) Edit(name)
Edit the given provider
432 433 434 435 436 437 438 439 |
# File '../../src/modules/Provider.rb', line 432 def Edit(name) @operation = nil @Type = "" return false if Select(name) != true @LastCountry = "_custom" @operation = :edit true end |
- (Object) Export(type)
Export data
343 344 345 346 347 348 |
# File '../../src/modules/Provider.rb', line 343 def Export(type) return {} if !CheckType(type) _Provs = Filter(@Providers, type) Builtins.y2debug("Provs=%1", _Provs) deep_copy(_Provs) end |
- (Object) Filter(providers, type)
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File '../../src/modules/Provider.rb', line 193 def Filter(providers, type) providers = deep_copy(providers) if providers == nil || type == nil || type == "" || type == "all" return deep_copy(providers) end Builtins.filter(providers) do |k, v| Builtins.y2debug( "%1 %2", Ops.get_string(v, "PROVIDER", ""), Ops.get_string(v, Ops.add(Builtins.toupper(type), "SUPPORTED"), "no") ) Ops.get_string(v, Ops.add(Builtins.toupper(type), "SUPPORTED"), "no") == "yes" end end |
- (Object) FilterNOT(providers, type)
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File '../../src/modules/Provider.rb', line 210 def FilterNOT(providers, type) providers = deep_copy(providers) if providers == nil || type == nil || type == "" || type == "all" return {} end Builtins.filter(providers) do |k, v| Builtins.y2debug( "%1 %2", Ops.get_string(v, "PROVIDER", ""), Ops.get_string(v, Ops.add(Builtins.toupper(type), "SUPPORTED"), "no") ) Ops.get_string(v, Ops.add(Builtins.toupper(type), "SUPPORTED"), "no") == "no" end end |
- (Array) FilterProviders(provs, type)
Filter providers based on the type
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 |
# File '../../src/modules/Provider.rb', line 718 def FilterProviders(provs, type) provs = deep_copy(provs) Builtins.y2debug("provs,type=%1,%2", provs, type) supported = Ops.add(Builtins.toupper(type), "SUPPORTED") etst = false if type == "rawip" || type == "syncppp" supported = "ISDNSUPPORTED" etst = true end Builtins.y2debug("supported=%1", supported) Builtins.filter(provs) do |i| Builtins.y2debug("i=%1", i) if Ops.is_string?(i) p = Ops.get(@Providers, Convert.to_string(i), {}) if Ops.get_string(p, supported, "no") == "yes" if etst next Ops.get_string(p, "ENCAP", "_nodef") == type else next true end else next false end elsif SCR.Read( Ops.add( Convert.to_path(i), Builtins.topath(Ops.add(".", supported)) ) ) == "yes" if etst next SCR.Read( Ops.add(Convert.to_path(i), Builtins.topath(".ENCAP")) ) == type else next true end else next false end end end |
- (Array) GetCountries
Get list of countries
682 683 684 |
# File '../../src/modules/Provider.rb', line 682 def GetCountries deep_copy(@Countries) end |
- (Object) GetCountry
This is a single point of dependence on the Language module of yast2-country-data
189 190 191 192 |
# File '../../src/modules/Provider.rb', line 189 def GetCountry Yast.import "Language" Language.GetLanguageCountry end |
- (Array) GetProviders(type, country, preselect)
Get providers from a group (country/other)
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 |
# File '../../src/modules/Provider.rb', line 820 def GetProviders(type, country, preselect) provs = [] Builtins.y2debug("%1-%2", country, preselect) # Custom providers if country == "_custom" Builtins.foreach(@Providers) do |k, v| Ops.set(provs, Builtins.size(provs), k) end else dir = SCR.Dir(Builtins.add(path(".providers.s"), country)) base = Builtins.add(path(".providers.v"), country) provs = Builtins.maplist(dir) { |i| Builtins.add(base, i) } end Builtins.y2debug("type=%1", type) Builtins.y2debug("provs=%1", provs) # Filter only desired providers provs = [] if provs == nil provs = FilterProviders(provs, type) Builtins.y2debug("provs=%1", provs) # Sort and create divider (line) provs = SortProviders(provs) Builtins.y2debug("provs=%1", provs) index = -1 # i is either string or path Builtins.maplist(provs) do |i| index = Ops.add(index, 1) if Ops.is_string?(i) next Item( Id(i), Ops.get(@Providers, [Convert.to_string(i), "PROVIDER"], i), index == 0 || preselect == i ) elsif path(".\"--\"") == i next Item(Id(i), "----------------") else next Item( Id(i), SCR.Read(Ops.add(Convert.to_path(i), path(".PROVIDER"))), 0 == index ) end end end |
- (Object) Import(type, providers)
Import data
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File '../../src/modules/Provider.rb', line 323 def Import(type, providers) providers = deep_copy(providers) return {} if !CheckType(type) _Provs = FilterNOT(@Providers, type) Builtins.y2debug("Provs=%1", _Provs) @Name = "" @Current = {} @Providers = Convert.convert( Builtins.union(_Provs, providers), :from => "map", :to => "map <string, map>" ) @OriginalProviders = nil nil end |
- (Object) IsUnique(name)
Check if provider name is unique
689 690 691 692 693 694 |
# File '../../src/modules/Provider.rb', line 689 def IsUnique(name) forbidden = Builtins.maplist(@Providers) do |k, v| Ops.get_string(v, "PROVIDER", "") end !Builtins.contains(forbidden, name) end |
- (Object) main
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File '../../src/modules/Provider.rb', line 40 def main textdomain "network" Yast.import "HTML" Yast.import "Map" Yast.import "String" Yast.import "Summary" #------------------ # GLOBAL VARIABLES # Current provider name @Name = "" # Current provider # structure depends on Type. See providers.rpm @Current = {} # Current provider type @Type = "modem" # Last selected country @LastCountry = nil #----------------- # LOCAL VARIABLES # Supported provider types @Supported = ["modem", "isdn", "dsl"] # Custom providers # (system ones are too many and thus read on demand) @Providers = {} # Custom providers (initial copy) @OriginalProviders = {} # Countries list @Countries = [] # Deleted providers @Deleted = [] # Pending operation (nil = none) @operation = nil # True if providers are already read @initialized = false # Country @country = nil end |
- (Object) Modified(type)
Were the providers changed?
95 96 97 98 99 100 101 |
# File '../../src/modules/Provider.rb', line 95 def Modified(type) return false if !CheckType(type) _OriginalProvs = Filter(@OriginalProviders, type) _Provs = Filter(@Providers, type) diff = _Provs != _OriginalProvs diff end |
- (Object) Overview(type)
Create an overview table with all configured providers
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 |
# File '../../src/modules/Provider.rb', line 565 def Overview(type) return [] if !CheckType(type) _Provs = Convert.convert( Filter(@Providers, type), :from => "map", :to => "map <string, map <string, string>>" ) Builtins.y2debug("Provs=%1", _Provs) overview = [] Builtins.maplist(_Provs) do |name, provmap| Builtins.y2debug("provider(%1): %2", name, provmap) it = { "id" => name, "table_descr" => [name, Ops.get_string(provmap, "PROVIDER", "")] } if type != "dsl" Ops.set( it, "table_descr", Builtins.add( Ops.get_list(it, "table_descr", []), Ops.get_string(provmap, "PHONE", "") ) ) end # build the rich text: rich = Ops.add( Ops.add( HTML.Bold( # translators: Header of a rich text description for a provider # %1 is the provider name, %2 is the homepage Builtins.sformat( "%1 (%2)", Ops.get_string(provmap, "PROVIDER", ""), Ops.get_locale(provmap, "HOMEPAGE", _("No home page")) ) ), "<br>" ), HTML.List( [ Builtins.sformat( _("Product Name: %1"), Ops.get_locale(provmap, "PRODUCT", _("Unknown")) ), Builtins.sformat( _("Username: %1"), Ops.get_string(provmap, "USERNAME", "") ) ] ) ) Ops.set(it, "rich_descr", rich) overview = Builtins.add(overview, it) end Builtins.y2debug("overview=%1", overview) deep_copy(overview) end |
- (Object) ProviderType
Return current provider type
698 699 700 701 702 703 704 705 706 707 708 |
# File '../../src/modules/Provider.rb', line 698 def ProviderType supp = Builtins.filter(@Supported) do |t| Ops.get_string( @Current, Builtins.toupper(Ops.add(t, "SUPPORTED")), "no" ) == "yes" end Builtins.y2debug("supp=%1", supp) Ops.get_string(supp, 0, "modem") end |
- (Object) Read
Read providers data (custom only) and country mappings
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 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 |
# File '../../src/modules/Provider.rb', line 105 def Read ret = true return true if @initialized # Read custom providers @Providers = {} dir = SCR.Dir(path(".sysconfig.network.providers.s")) # Filter away backups (files with ~) dir = Builtins.filter(dir) { |file| !Builtins.regexpmatch(file, "[~]") } # Fill the Providers map Builtins.foreach(dir) do |name| prov = Builtins.add(path(".sysconfig.network.providers.v"), name) p = Builtins.listmap(SCR.Dir(prov)) do |i| ii = {} # TODO: quoting should be improved everywhere Ops.set( ii, i, String.UnQuote(Convert.to_string(SCR.Read(Builtins.add(prov, i)))) ) deep_copy(ii) end Ops.set(@Providers, name, p) end @OriginalProviders = deep_copy(@Providers) # Read countries country_names = Convert.to_map( Builtins.eval(SCR.Read(path(".target.yast2"), "country.ycp")) ) if country_names == nil #Report:Error(_("Country database not found")); Builtins.y2error("Country database not found") country_names = {} ret = false end textdomain "country" country_names = Builtins.eval(country_names) textdomain "network" # Country heuristics @country = GetCountry() @LastCountry = @country Builtins.y2debug("LastCountry=%1", @LastCountry) # Initialize the countries selection box @Countries = [] index = -1 @Countries = SCR.Dir(path(".providers.s")) @Countries = [] if @Countries == nil Builtins.y2debug("Countries=%1", @Countries) @LastCountry = "CZ" if !Builtins.contains(@Countries, @LastCountry) @Countries = Builtins.maplist( Convert.convert(@Countries, :from => "list", :to => "list <string>") ) do |i| index = Ops.add(index, 1) Item(Id(i), Ops.get_string(country_names, i, i), i == @LastCountry) end Builtins.y2debug("Countries=%1", @Countries) # Read system providers # Slow -- better read them upon request (SelectSystem) # map P = $[]; # P = listmap(string cs, SCR::Dir(.providers.s), { # path pp = add(.providers.s, cs); # // y2debug("--- (%1), %2 ---", pp, SCR::Dir(pp)); # return [ cs, listmap(string c, SCR::Dir(pp), { # pp = add(add(.providers.v, cs), c); # // y2debug("--- %1 ---", SCR::Dir(pp)); # return [ c, # listmap(string vs, SCR::Dir(pp), { # // y2debug("%1=%2", vs, SCR::Read(add(pp, vs))); # return [ vs, SCR::Read(add(pp, vs)) ]; # }) ]; # }) ]; # }); @initialized = true ret end |
- (Object) Select(name)
Select the given provider
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 |
# File '../../src/modules/Provider.rb', line 384 def Select(name) @Name = "" @Current = {} Builtins.y2debug("name=%1", name) if name != "" && !Builtins.haskey(@Providers, name) Builtins.y2error("No such provider: %1", name) return false end @Name = name @Current = Builtins.eval(Ops.get(@Providers, @Name, {})) @Type = ProviderType() if name != "" if @Current == {} # Default provider map @Current = # FIXME: remaining items {} # Variable key -> not functional #16701 Ops.set(@Current, Ops.add(Builtins.toupper(@Type), "SUPPORTED"), "yes") end Builtins.y2debug("Name=%1", @Name) Builtins.y2debug("Type=%1", @Type) Builtins.y2debug("Current=%1", @Current) true end |
- (Object) SelectSystem(name)
Select the given system provider
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 |
# File '../../src/modules/Provider.rb', line 353 def SelectSystem(name) Builtins.y2debug("name=%1", name) @Name = Builtins.sformat("%1", name) if Builtins.findlastof(@Name, ".") != -1 @Name = Builtins.regexpsub(@Name, "^.*\\.([^.]*)", "\\1") end @Name = "" if @Name == nil if "\"" == Builtins.substring(@Name, 0, 1) @Name = Builtins.substring( @Name, 1, Ops.subtract(Builtins.size(@Name), 2) ) end values = SCR.Dir(name) @Current = Builtins.listmap(values) do |value| { value => SCR.Read(Builtins.add(name, value)) } end Builtins.y2debug("Name=%1", @Name) Builtins.y2debug("Current=%1", @Current) true end |
- (Object) SortProviders(provs)
Sorts providers alphabeticly (non-case-sensitively) and by priority. In the first step, priority and name of each provider is obtained. List of strings built from these values is created. Item lists are: "<1-character-priority><34-characters-provider-name><provider-identifier>" This list is sorted, result is correctly sorted, by priority and alphabeticaly. I did not use builtin sort with sort code because it uses bubble sort -- it was bloody slow.
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 |
# File '../../src/modules/Provider.rb', line 771 def SortProviders(provs) provs = deep_copy(provs) pre = Builtins.sort(Builtins.maplist(Builtins.add(provs, "--")) do |i| next "9 .\"--\"" if "--" == i if Ops.is_string?(i) next Ops.add( "x ", Convert.to_string(i) ) else tmp = Convert.to_string( SCR.Read(Ops.add(Convert.to_path(i), path(".PRIORITY"))) ) tmp = "-1" if nil == tmp p = Ops.subtract(8, Builtins.tointeger(tmp)) if Ops.less_than(p, 0) || Ops.greater_than(p, 9) Builtins.y2error( "Wrong priority (%1), you must change the algorithm! [%2]", p, tmp ) end tmp = Ops.add( Builtins.tolower( Convert.to_string( SCR.Read(Ops.add(Convert.to_path(i), path(".PROVIDER"))) ) ), " " ) tmp = Ops.add(Builtins.sformat("%1", p), tmp) next Builtins.sformat("%1%2", Builtins.substring(tmp, 0, 35), i) end end) if ".\"--\"" == Builtins.substring(Ops.get_string(pre, 0, ""), 35) pre = Builtins.remove(pre, 0) end Builtins.maplist( Convert.convert(pre, :from => "list", :to => "list <string>") ) do |i| next Builtins.substring(i, 35) if "x" == Builtins.substring(i, 0, 1) Builtins.topath(Builtins.substring(i, 35)) end end |
- (Object) Summary(type, split)
Create a textual summary and a list of unconfigured providers
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 |
# File '../../src/modules/Provider.rb', line 629 def Summary(type, split) return [] if !CheckType(type) _Provs = Convert.convert( Filter(@Providers, type), :from => "map", :to => "map <string, map <string, string>>" ) Builtins.y2debug("Provs=%1", _Provs) summary = "" if Ops.less_than(Builtins.size(_Provs), 1) # Summary text summary = Summary.AddHeader("", _("Nothing is configured.")) else # Summary text summary = Summary.AddHeader("", _("Configured Providers:")) end provs = [] Builtins.maplist(_Provs) do |name, provmap| # Summary text description (%1 is provider name) descr = Builtins.sformat(_("Configured as %1"), name) phone = Ops.get_string(provmap, "PHONE", "") if phone != "" && phone != nil # Summary text description (%1 is provider name) descr = Builtins.sformat( _("Configured as %1 (phone %2)"), name, phone ) end provs = Builtins.add( provs, Summary.Device(Ops.get_string(provmap, "PROVIDER", ""), descr) ) end summary = Summary.DevicesList(provs) [ summary, [ # List item to providers summary Item(Id("modem"), _("Modem Provider"), true), # List item to providers summary Item(Id("isdn"), _("ISDN Provider")), # List item to providers summary Item(Id("dsl"), _("DSL Provider")) ] ] end |
- (Object) Write(type)
Write custom providers data
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 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 |
# File '../../src/modules/Provider.rb', line 237 def Write(type) Builtins.y2milestone("Writing configuration") ret = true return false if !CheckType(type) _OriginalProvs = Convert.convert( Filter(@OriginalProviders, type), :from => "map", :to => "map <string, map>" ) _Provs = Convert.convert( Filter(@Providers, type), :from => "map", :to => "map <string, map <string, string>>" ) Builtins.y2debug("OriginalProvs=%1", _OriginalProvs) Builtins.y2debug("Provs=%1", _Provs) # Check for changes if _Provs == _OriginalProvs Builtins.y2milestone( "No changes to %1 providers -> nothing to write", type ) return true end # Remove deleted custom providers Builtins.foreach(@Deleted) do |provider| next if !Builtins.haskey(_OriginalProvs, provider) p = Builtins.add(path(".sysconfig.network.providers.section"), provider) Builtins.y2debug("deleting: %1", p) SCR.Write(p, nil) end @Deleted = Builtins.filter(@Deleted) do |prov| Builtins.haskey(_OriginalProvs, prov) end Builtins.y2debug("Deleted=%1", @Deleted) # Write custom providers Builtins.foreach(_Provs) do |name, provider| name = Builtins.filterchars( name, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-." ) base = Builtins.add(path(".sysconfig.network.providers.v"), name) # Ensure all neccesary items are present if !Builtins.haskey(provider, "MODEMSUPPORTED") Ops.set(provider, "MODEMSUPPORTED", "yes") end if !Builtins.haskey(provider, "ISDNSUPPORTED") Ops.set(provider, "ISDNSUPPORTED", "no") end if !Builtins.haskey(provider, "DSLSUPPORTED") Ops.set(provider, "DSLSUPPORTED", "no") end # Write all values Builtins.foreach(provider) do |k, v| # Adjust some values if k == "ASKPASSWORD" || k == "STUPIDMODE" || k == "COMPUSERVE" || k == "ISDNSUPPORTED" || k == "DSLSUPPORTED" || k == "MODEMSUPPORTED" if v == "0" v = "no" elsif v == "1" v = "yes" elsif v != "no" && v != "yes" v = Builtins.search(v, "no") != nil ? "no" : "yes" end end # Do the write SCR.Write(Builtins.add(base, k), String.Quote(v)) end end # Flush SCR.Write(path(".sysconfig.network.providers"), nil) ret end |