txtparser

package
v0.0.0-...-12ea192 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperatorLessThan      = "<"
	OperatorLessThanEqual = "<="
	OperatorMoreThan      = ">"
	OperatorMoreThanEqual = ">="
	OperatorEqual         = "="
)

Operator definitions

View Source
const OverrideTuningSheets = "/etc/saptune/override/"

OverrideTuningSheets defines saptunes override directory

Variables

View Source
var RegexKeyOperatorValue = regexp.MustCompile(`([\w.+_-]+)\s*([<=>]+)\s*["']*(.*?)["']*$`)

RegexKeyOperatorValue breaks up a line into key, operator, value.

Functions

func CalculateOptimumValue

func CalculateOptimumValue(operator Operator, currentValue string, expectedValue string) (string, error)

CalculateOptimumValue calculates optimum parameter value given the current value, comparison operator, and expected value. Return optimised value.

func GetINIFileDescriptiveName

func GetINIFileDescriptiveName(fileName string) string

GetINIFileDescriptiveName return the descriptive name of the Note

func GetINIFileVersionSectionEntry

func GetINIFileVersionSectionEntry(fileName, entryName string) string

GetINIFileVersionSectionEntry returns the field 'entryName' from the version section of the Note configuration file

func GetINIFileVersionSectionRefs

func GetINIFileVersionSectionRefs(fileName string) []string

GetINIFileVersionSectionRefs returns the reference field from the version section of the Note configuration file

func GetSysctlExcludes

func GetSysctlExcludes(skipFiles string)

GetSysctlExcludes gets the content of the /etc/sysconfig/saptune variable 'SKIP_SYSCTL_FILES' and provides it as slice

func ResetVersionSectCnts

func ResetVersionSectCnts(tag string)

ResetVersionSectCnts resets the counters to control the error message of missing or wrong version section the warning message for the use of old style version section needed for staging to get the Warnings and Errors displayed

func StoreSectionInfo

func StoreSectionInfo(obj *INIFile, file, ID string, overwriteExisting bool) error

StoreSectionInfo stores INIFile section information to section directory

Types

type INIEntry

type INIEntry struct {
	Section  string
	Key      string
	Operator Operator
	Value    string
}

INIEntry contains a single key-value pair in INI file.

type INIFile

type INIFile struct {
	AllValues []INIEntry
	KeyValue  map[string]map[string]INIEntry
}

INIFile contains all key-value pairs of an INI file.

func GetOverrides

func GetOverrides(filetype, ID string) (bool, *INIFile)

GetOverrides is looking for an override file and parse the content

func GetSectionInfo

func GetSectionInfo(initype, ID string, fileSelect bool) (*INIFile, error)

GetSectionInfo reads content of stored INIFile information. Return the content as INIFile

func ParseINI

func ParseINI(input string) *INIFile

ParseINI parse the content of the configuration file

func ParseINIFile

func ParseINIFile(fileName string, autoCreate bool) (*INIFile, error)

ParseINIFile read the content of the configuration file

type Operator

type Operator string

Operator is the comparison or assignment operator used in an INI file entry

type Sysconfig

type Sysconfig struct {
	AllValues []*SysconfigEntry // All key-value pairs in the orignal order.
	KeyValue  map[string]*SysconfigEntry
}

Sysconfig contains key-value pairs of a sysconfig file. It is able to convert back to original text in the original key order.

func ParseSysconfig

func ParseSysconfig(input string) (*Sysconfig, error)

ParseSysconfig read sysconfig text and parse the text into memory structures.

func ParseSysconfigFile

func ParseSysconfigFile(fileName string, autoCreate bool) (*Sysconfig, error)

ParseSysconfigFile read sysconfig file and parse the file content into memory structures.

func (*Sysconfig) GetBool

func (conf *Sysconfig) GetBool(key string, defaultValue bool) bool

GetBool return bool value that belongs to the key, or the default value if key does not exist. True values are "yes" or "true".

func (*Sysconfig) GetInt

func (conf *Sysconfig) GetInt(key string, defaultValue int) int

GetInt return integer value that belongs to the key, or the default value if the key does not exist or value is not an integer.

func (*Sysconfig) GetIntArray

func (conf *Sysconfig) GetIntArray(key string, defaultValue []int) (ret []int)

GetIntArray assume the key carries a space-separated array of integers, return the array. Discard malformed integers.

func (*Sysconfig) GetString

func (conf *Sysconfig) GetString(key, defaultValue string) string

GetString return string value that belongs to the key, or the default value if the key does not exist.

func (*Sysconfig) GetStringArray

func (conf *Sysconfig) GetStringArray(key string, defaultValue []string) (ret []string)

GetStringArray assume the key carries a space-separated array value, return the value array.

func (*Sysconfig) GetUint64

func (conf *Sysconfig) GetUint64(key string, defaultValue uint64) uint64

GetUint64 return uint64 value that belongs to the key, or the default value if the key does not exist or value is not an integer.

func (*Sysconfig) IsKeyAvail

func (conf *Sysconfig) IsKeyAvail(key string) bool

IsKeyAvail return true, if the key is available. false, if the key does not exist.

func (*Sysconfig) Set

func (conf *Sysconfig) Set(key string, value interface{})

Set value for a key. If the key does not yet exist, it is created.

func (*Sysconfig) SetIntArray

func (conf *Sysconfig) SetIntArray(key string, values []int)

SetIntArray give a space-separated integer array value to a key. If the key does not yet exist, it is created.

func (*Sysconfig) SetStrArray

func (conf *Sysconfig) SetStrArray(key string, values []string)

SetStrArray give a space-separated string array value to a key. If the key does not yet exist, it is created.

func (*Sysconfig) ToText

func (conf *Sysconfig) ToText() string

ToText convert key-value pairs back into text. Values are always surrounded by double-quotes.

type SysconfigEntry

type SysconfigEntry struct {
	LeadingComments []string // The comment lines leading to the key-value pair, including prefix '#', excluding end-of-line.
	Key             string   // The key.
	Value           string   // The value, excluding '=' character and double-quotes. Values will always come in double-quotes when converted to text.
}

SysconfigEntry contains a single key-value pair in sysconfig file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL