Skip to content

Commit

Permalink
add ability to import single section and replace old code
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jun 30, 2020
1 parent 059f9ac commit 9366ad0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 102 deletions.
23 changes: 9 additions & 14 deletions src/clients/inst_autosetup.rb
Expand Up @@ -24,8 +24,8 @@
# Uwe Gansert <ug@suse.de>
#
# $Id$
require "autoinstall/module_config_builder"
require "autoinstall/autosetup_helpers"
require "autoinstall/entries/importer"

module Yast
import "AutoinstConfig"
Expand Down Expand Up @@ -59,7 +59,6 @@ def main
Yast.import "Language"
Yast.import "Console"
Yast.import "ServicesManager"
Yast.import "Y2ModuleConfig"
Yast.import "AutoinstFunctions"
Yast.import "Wizard"

Expand Down Expand Up @@ -440,30 +439,26 @@ def main

# Import Users configuration from profile
def autosetup_users
users_config = ModuleConfigBuilder.build(
Y2ModuleConfig.getModuleConfig("users"), Profile.current
)
if users_config
Profile.remove_sections(users_config.keys)
Call.Function("users_auto", ["Import", users_config])
importer.import_entry("users").each do |e|
Profile.remove_sections(e)
end
end

# Import security settings from profile
def autosetup_security
security_config = Profile.current["security"]
if security_config
# Do not start it in second installation stage again.
# Writing will be called in inst_finish.
Profile.remove_sections("security")
Call.Function("security_auto", ["Import", security_config])
importer.import_entry("security").each do |e|
Profile.remove_sections(e)
end
end

# Add YaST2 packages dependencies
def add_yast2_dependencies
AutoinstSoftware.AddYdepsFromProfile(Profile.current.keys)
end

def importer
Y2Autoinstallation::Entries::Importer.new(Profile.current)
end
end
end

Expand Down
7 changes: 6 additions & 1 deletion src/lib/autoinstall/entries/description.rb
Expand Up @@ -33,7 +33,8 @@ class Description
"X-SuSE-YaST-AutoInstClonable",
"X-SuSE-YaST-AutoInstClient",
"X-SuSE-YaST-AutoInst",
"Hidden"
"Hidden",
"Name"
].freeze

# creates new description with values passed
Expand All @@ -42,6 +43,10 @@ def initialize(values)
@values = values
end

def name
values["Name"]
end

def mode
values["X-SuSE-YaST-AutoInst"]
end
Expand Down
44 changes: 44 additions & 0 deletions src/lib/autoinstall/entries/importer.rb
Expand Up @@ -83,6 +83,50 @@ def import_sections
end
end

# Import just keys for given entry
# @param entry [String | Description] to import
# @return [Array<String>] keys that are imported
def import_entry(entry)
res = []

description = if entry.is_a?(Description)
entry
else
registry.descriptions.find { |d| d.resource_name == entry }
end

if description
data = if description.managed_keys.size == 1
resource = description.managed_keys.first
if profile.key?(resource)
res << resource
profile[description.managed_keys.first]
else
key = description.aliases.find { |a| profile.key?(a) }
next unless key

res << key
profile[key]
end
else # for multiple section prepare profile
selection = profile.select { |k, _| description.managed_keys.include?(k) }
res.concat(selection.keys)
selection
end

Yast::WFM.CallFunction(description.client_name, ["Import", data]) if data
else
raise "Unknown entry #{entry}" unless WFM.ClientExists("#{entry}_auto")
data = profile[entry]
if data
Yast::WFM.CallFunction("#{entry}_auto", ["Import", data])
res << entry
end
end

res
end

private

attr_reader :profile
Expand Down
87 changes: 0 additions & 87 deletions src/lib/autoinstall/module_config_builder.rb

This file was deleted.

0 comments on commit 9366ad0

Please sign in to comment.