Skip to content

Commit

Permalink
parse "DISTRO" content value, set "NAME" and "LABEL"
Browse files Browse the repository at this point in the history
write CPE ID to SLP *.reg file
  • Loading branch information
lslezak committed Oct 14, 2014
1 parent 0e4d0f3 commit d30a373
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
59 changes: 45 additions & 14 deletions src/include/instserver/routines.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# encoding: utf-8

# File: include/instserver/complex.ycp
# File: include/instserver/routines.rb
# Package: Configuration of instserver
# Summary: Dialogs definitions
# Summary: Helper methods
# Authors: Anas Nashif <nashif@suse.de>
#
# $Id$
module Yast
module InstserverRoutinesInclude
def initialize_instserver_routines(include_target)
include Yast::Logger

def initialize_instserver_routines(include_target)
textdomain "instserver"

Yast.import "String"
end

def ReadMediaFile(media)
Expand All @@ -27,21 +25,54 @@ def ReadMediaFile(media)
end
end

# Split CPE ID and distro label (separated by comma)
# @param [String] distro "DISTRO" value from content file
# @return [Hash<String,String>,nil] parsed value, map: { "name" => <string>, "cpeid" => <string> }
# or nil if the input value is nil or does not contain a comma
def distro_map(distro)
if !distro
log.warn "Received nil distro value"
return nil
end

# split at the first comma, resulting in 2 parts at max.
parsed = distro.split(",", 2)

if parsed.size != 2
log.warn "Cannot parse DISTRO value: #{distro}"
return nil
end

{ "cpeid" => parsed[0], "name" => parsed[1] }
end

def ReadContentFile(content)
Builtins.y2debug("Reading content %1", content)

contentmap = Convert.convert(
SCR.Read(path(".content_file"), content),
:from => "any",
:to => "map <string, string>"
)
contentmap = SCR.Read(path(".content_file"), content)
contentmap.each { |key, value| value.strip! }

# "DISTRO" flag is used in SLE12, "NAME" and "LABEL" are missing
# format: "<cpeid>,<product_name>", CPE ID is defined here:
# http://csrc.nist.gov/publications/nistir/ir7695/NISTIR-7695-CPE-Naming.pdf
distro = contentmap["DISTRO"]

contentmap = Builtins.mapmap(contentmap) do |key, value|
{ key => String.CutBlanks(value) }
if distro
distro_values = distro_map(distro)

if distro_values
# name is displayed in overview
contentmap["NAME"] = distro_values["name"]
# label is written to SLP config
contentmap["LABEL"] = distro_values["name"].dup

contentmap["CPEID"] = distro_values["cpeid"]
end
end

Builtins.y2milestone("Read content file %1: %2", content, contentmap)

deep_copy(contentmap)
contentmap
end

end
Expand Down
9 changes: 3 additions & 6 deletions src/modules/Instserver.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# encoding: utf-8

# File: modules/Instserver.ycp
# File: modules/Instserver.rb
# Package: Configuration of Installation Server
# Summary: Installation Server settings, input and output functions
# Authors: Anas Nashif <nashif@suse.de>
#
# $Id$
#
# Representation of the configuration of Installation Server.
# Input and output routines.
require "yast"
Expand Down Expand Up @@ -833,6 +831,7 @@ def WriteSLPReg(cm)
attr = {}
Builtins.foreach(
[
"CPEID",
"LABEL",
"VERSION",
"VENDOR",
Expand Down Expand Up @@ -880,8 +879,6 @@ def WriteSLPReg(cm)
end
end


machine = ""
machines = []
Builtins.foreach(cm) do |k, v|
Builtins.y2debug("Read Key: '%1'", k)
Expand Down Expand Up @@ -975,7 +972,7 @@ def WriteSLPReg(cm)

# replace the machine option after escaping,
# it actually _is_ a list so "," is valid here
Ops.set(attr, "machine", machines_string)
attr["machine"] = machines_string unless machines_string.empty?
Builtins.y2milestone("machine: %1", Ops.get(attr, "machine", ""))

Builtins.y2milestone(
Expand Down

0 comments on commit d30a373

Please sign in to comment.