libdconf

package module
v0.0.0-...-ce196b1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

libdconf

pkg.go.dev goreportcard License Liberapay patrons Patreon

libdconf is a Go library for the parsing, manipulation, and dumping of dconf schemas.

Building

To compile libdconf, ensure you have Golang 1.16+ installed and run go build

Testing

To test libdconf, run go test

License

libdconf is licensed under the Apache-2.0 license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyAlreadyExists is an error we return when we already have a key in a schema key-value store. Mostly useful for validating during section adding.
	ErrKeyAlreadyExists = errors.New("key already exists in schemakv")

	// ErrKeyNotExists is an error we return when we do not have a key in a schema
	ErrKeyNotExists = errors.New("key does not exist")

	// ErrModCannotDoReplace is an error we return when we cannot do a replacement of a value
	ErrModCannotDoReplace = errors.New("cannot perform replace modification, schematype is not of ArrayAsString or string")

	// ErrModNoReplaceValueOrValue is an error we return if we cannot perform a modification without a value
	ErrModNoReplaceValueOrValue = errors.New("cannot perform modification, no replacevalue or value specified")

	// ErrNoContentProvided is an error we return when no content is provided when attempt to import
	ErrNoContentProvided error = errors.New("no content provided as a byte slice")

	// ErrNoDconfInPath is an error we return if we could not find dconf in the path during a dconf operation
	ErrNoDconfInPath error = errors.New("no dconf found in path")

	// ErrSectionDoesNotExist is an error we return if a section requested does not exist
	ErrSectionDoesNotExist = errors.New("section does not exist")

	// ErrSectionExists is an error we return if a section exists
	ErrSectionExists = errors.New("section exists")
)
View Source
var (
	// SectionRegexp is our regular expression for a section name
	SectionRegexp = regexp.MustCompile(`^\[([A-Za-z0-9-_\:\.\/{}]+)\]`)
)

Functions

func DconfDump

func DconfDump(path string) (content []byte, dumpErr error)

DconfDump will attempt to dump the contents of the provided path If no path is provided, / (root) is used

func RemoveFromStringArr

func RemoveFromStringArr(arr []string, removeString string) []string

RemoveFromStringArr will remove the specified string from our array

func TrimSectionSlashes

func TrimSectionSlashes(section string) string

TrimSectionSlashes will trim the provided section string of any prefixed and suffixed forward slash

Types

type Modification

type Modification struct {
	// ReplaceValues is an array of RegExp (regular expression) for search to the replacement value
	// This is expected to be a length of two, the first being the value we are looking for and the second is the value we are replacing it with
	// The first value can be an exact string or regex
	ReplaceValues []string `toml:"replaceValue"`

	// Value is the raw value we are applying as the value for the modification
	Value string `toml:"value"`
}

Modification defines a desired change to a SchemaType

type Schema

type Schema struct {
	Order []string             // Our fixed order
	Map   map[string]*SchemaKV // Our Map of Sections (like com/solus-project/budgie-desktop/instance/icon-tasklist)
	Path  string               // Path for the Schema
}

Schema is a map of paths to key values

func NewSchema

func NewSchema(path string, content []byte) (schema *Schema, readErr error)

NewSchema will attempt to create a new Schema based on the root of the dconf directory content is optional. If no content is specified, we will attempt to do a dconf dump instead This will be done user running the command. If we fail to dump or parse the schema, we will return an error

func (*Schema) AddSection

func (schema *Schema) AddSection(section string, sT *SchemaKV) (addErr error)

AddSection will attempt to add the provided SchemaKV as the provided section name This will return an error if the section already exists

func (*Schema) DeleteSections

func (schema *Schema) DeleteSections(sections ...string)

DeleteSections will delete all sections specified should they match exactly If you want to match by prefix, use the DeleteSectionsWithPrefix func

func (*Schema) DeleteSectionsWithPrefix

func (schema *Schema) DeleteSectionsWithPrefix(sections ...string)

DeleteSectionsWithPrefix will delete all sections specified and all sections which begin with the section prefixed

func (*Schema) GetSection

func (schema *Schema) GetSection(section string) (kv *SchemaKV, getErr error)

GetSection will attempt to get the SchemaKV associated with the provided section

func (*Schema) HasSection

func (schema *Schema) HasSection(section string) (exists bool)

HasSection will check if our Schema has the provided section

func (*Schema) ImportIntoDconf

func (schema *Schema) ImportIntoDconf() (importErr error)

ImportIntoDconf will import this Schema into its path via dconf load

func (*Schema) MigrateSectionsWithName

func (schema *Schema) MigrateSectionsWithName(source string, dest string, exact bool)

MigrateSectionsWithName will migrate sections with the source prefix specified, remapping them to have the destination prefix. If exact is set to true, we will only migrate the section if it is an exact match

func (*Schema) String

func (schema *Schema) String() (schemaString string)

String will convert our Schema back to a String

type SchemaKV

type SchemaKV struct {
	Order []string               // Our fixed order
	Keys  map[string]*SchemaType // Our Map of Keys in each Section
}

SchemaKV is a map of keys to our SchemaType

func (*SchemaKV) AddKey

func (kv *SchemaKV) AddKey(key string, t *SchemaType) error

AddKey will attempt to add the SchemaType for the provided key to the SchemaKV This will return an error if the key already exists

func (*SchemaKV) DeleteKeys

func (kv *SchemaKV) DeleteKeys(keys ...string)

DeleteKeys will delete all specified keys from a SchemaKV

func (*SchemaKV) Duplicate

func (kv *SchemaKV) Duplicate() *SchemaKV

Duplicate will duplicate this SchemaKV into a new SchemaKV

func (*SchemaKV) GetVal

func (kv *SchemaKV) GetVal(key string) (*SchemaType, error)

GetVal will get the SchemaType value for the provided key, or return an error

func (*SchemaKV) HasKey

func (kv *SchemaKV) HasKey(key string) bool

HasKey returns if we have this key

func (*SchemaKV) ModifyKey

func (kv *SchemaKV) ModifyKey(key string, mod Modification) (modErr error)

ModifyKey will attempt to modify a SchemaType specified by key, with the provided Modification

func (*SchemaKV) MoveKey

func (kv *SchemaKV) MoveKey(source string, dest string) error

MoveKey will attempt to move the source key to the destination. If the source does not exist or the destination already exists, returns an error

type SchemaType

type SchemaType struct {
	Type string

	BoolVal              bool
	FloatHadTrailingZero bool
	FloatVal             float64
	IntVal               int32
	UintVal              uint32
	Val                  string
}

SchemaType is our defined type This type will have a defined Type (e.g. "bool") as Type and the designated type set This allows us to perform less type checking and reflection during marshal and unmarshalling

func NewSchemaType

func NewSchemaType(rawVal string) (sT *SchemaType, parseErr error)

NewSchemaType will attempt to convert the provided key/val into a SchemaType

func ParseSchemaLine

func ParseSchemaLine(line string) (key string, t *SchemaType)

ParseSchemaLine will parse our key=val line in an attempt to figure out its type

func (*SchemaType) Duplicate

func (sT *SchemaType) Duplicate() *SchemaType

Duplicate will duplicate this SchemaType

func (*SchemaType) Matches

func (sT *SchemaType) Matches(oST *SchemaType) (matches bool)

Matches will check if the provided SchemaType matches this one

func (*SchemaType) String

func (sT *SchemaType) String() string

String will convert our SchemaType back to a string Note this only converts the value itself and not the key

Jump to

Keyboard shortcuts

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