util

package
v0.0.0-...-2f3f924 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 19 Imported by: 182

Documentation

Index

Constants

View Source
const (
	VERBOSITY_SILENT  = 0
	VERBOSITY_QUIET   = 1
	VERBOSITY_DEFAULT = 2
	VERBOSITY_VERBOSE = 3
)

Variables

View Source
var EscapeShellCmds bool
View Source
var ExecuteShell bool
View Source
var InjectSyscfg string
View Source
var PrintShellCmds bool
View Source
var ShallowCloneDepth int
View Source
var SkipNewtCompat bool
View Source
var SkipSyscfgRepoHash bool
View Source
var Verbosity int

Functions

func AtoiNoOct

func AtoiNoOct(s string) (int, error)

Converts the specified string to an integer. The string can be in base-10 or base-16. This is equivalent to the "0" base used in the standard conversion functions, except octal is not supported (a leading zero implies decimal).

func AtoiNoOctTry

func AtoiNoOctTry(s string) (int, bool)

Converts the specified string to an integer. The string can be in base-10 or base-16. This is equivalent to the "0" base used in the standard conversion functions, except octal is not supported (a leading zero implies decimal).

The second return value is true on success.

func CIdentifier

func CIdentifier(s string) string

func CallInDir

func CallInDir(path string, execFunc func() error) error

func ChildDirs

func ChildDirs(path string) ([]string, error)

func CopyDir

func CopyDir(srcDirStr, dstDirStr string) error

func CopyFile

func CopyFile(srcFile string, dstFile string) error

func DirsAreEqual

func DirsAreEqual(dira string, dirb string) (bool, error)

DirsAreEqual compares the contents of two directories. Directories are equal if 1) their subdirectory structures are identical, and 2) they contain the exact same set of files (same names and contents).

func EnvVarsToSlice

func EnvVarsToSlice(env map[string]string) []string

EnvVarsToSlice converts an environment variable map into a slice of `k=v` strings.

func EnvironAsMap

func EnvironAsMap() (map[string]string, error)

EnvironAsMap gathers the current process's set of environment variables and returns them as a map.

func ErrorMessage

func ErrorMessage(level int, message string, args ...interface{})

Print Silent, Quiet and Verbose aware status messages to stderr.

func FileContains

func FileContains(contents []byte, path string) (bool, error)

FileContains indicates whether the specified file's contents are equal to the provided byte slice.

func FileContentsChanged

func FileContentsChanged(path string, newContents []byte) (bool, error)

func FileModificationTime

func FileModificationTime(path string) (time.Time, error)

func FilenameFromPath

func FilenameFromPath(s string) string

func Init

func Init(logLevel log.Level, logFile string, verbosity int) error

Initialize the util module

func IntMax

func IntMax(a, b int) int

func IntMin

func IntMin(a, b int) int

func IsExit

func IsExit(err error) bool

Indicates whether the provided error is of type *exec.ExitError (raised when a child process exits with a non-zero status code).

func IsNotExist

func IsNotExist(err error) bool

func LogShellCmd

func LogShellCmd(cmdStrs []string, env map[string]string)

func MarshalJSONStringer

func MarshalJSONStringer(sr fmt.Stringer) ([]byte, error)

func Max

func Max(x, y int) int

func Min

func Min(x, y int) int

func MoveDir

func MoveDir(srcDir string, destDir string) error

func MoveFile

func MoveFile(srcFile string, destFile string) error

func NodeExist

func NodeExist(path string) bool

func NodeNotExist

func NodeNotExist(path string) bool

Check whether the node (either dir or file) specified by path exists

func OneTimeWarning

func OneTimeWarning(text string, args ...interface{})

Displays the specified warning if it has not been displayed yet.

func OneTimeWarningError

func OneTimeWarningError(err error)

OneTimeWarningError displays the text of the specified error as a warning if it has not been displayed yet. No-op if nil is passed in.

func ParseEqualsPair

func ParseEqualsPair(v string) (string, string, error)

func PrintStacks

func PrintStacks()

func ReadLines

func ReadLines(path string) ([]string, error)

Reads each line from the specified text file into an array of strings. If a line ends with a backslash, it is concatenated with the following line.

func ShellCommand

func ShellCommand(cmdStrs []string, env map[string]string) ([]byte, error)

Execute the specified process and block until it completes.

@param cmdStrs The "argv" strings of the command to execute. @param env Additional key,value pairs to inject into the

child process's environment.  Specify null
to just inherit the parent environment.

@return []byte Combined stdout and stderr output of process. @return error NewtError on failure.

func ShellCommandLimitDbgOutput

func ShellCommandLimitDbgOutput(
	cmdStrs []string, env map[string]string, logCmd bool,
	maxDbgOutputChrs int) ([]byte, error)

Execute the specified process and block until it completes. Additionally, the amount of combined stdout+stderr output to be logged to the debug log can be restricted to a maximum number of characters.

@param cmdStrs The "argv" strings of the command to execute. @param env Additional key,value pairs to inject into the

child process's environment.  Specify null
to just inherit the parent environment.

@param logCmd Whether to log the command being executed. @param maxDbgOutputChrs The maximum number of combined stdout+stderr

characters to write to the debug log.
Specify -1 for no limit; 0 for no output.

@return []byte Combined stdout and stderr output of process. @return error NewtError on failure. Use IsExit() to

determine if the command failed to execute
or if it just returned a non-zero exit
status.

func ShellInteractiveCommand

func ShellInteractiveCommand(cmdStr []string, env map[string]string,
	flagBlock bool) error

Run interactive shell command

func SliceContains

func SliceContains(slice interface{}, elem interface{}) bool

Function that checks if the slice of any type contains a specified value

func SliceToEnvVars

func SliceToEnvVars(slc []string) (map[string]string, error)

SliceToEnvVars converts a slice of `k=v` strings into an environment variable map.

func SortFields

func SortFields(wsSepStrings ...string) []string

Sorts whitespace-delimited lists of strings.

@param wsSepStrings A list of strings; each string contains one or

more whitespace-delimited tokens.

@return A slice containing all the input tokens, sorted

alphabetically.

func StatusMessage

func StatusMessage(level int, message string, args ...interface{})

Print Silent, Quiet and Verbose aware status messages to stdout.

func StringMapStringToItfMapItf

func StringMapStringToItfMapItf(
	sms map[string]string) map[interface{}]interface{}

StringMapStringToItfMapItf converts a map[string]string to the more generic map[interface{}]interface{} type.

func TryRelPath

func TryRelPath(full string) string

Attempts to convert the specified absolute path into a relative path (relative to the current working directory). If the path cannot be converted, it is returned unchanged.

func UniqueStrings

func UniqueStrings(elems []string) []string

Removes all duplicate strings from the specified array, while preserving order.

func WriteMessage

func WriteMessage(f *os.File, level int, message string,
	args ...interface{})

Print Silent, Quiet and Verbose aware status messages to stdout.

Types

type FileInfo

type FileInfo struct {
	Path   string    // Path of configuration file.
	Parent *FileInfo // File that imported this configuration file, if any.
}

FileInfo represents a configuration source. It is intended to help the user understand how the system acquired its configuration, and to aid in tracking down errors in configuration files.

func (*FileInfo) ErrTree

func (fi *FileInfo) ErrTree(err error) error

ErrTree decorates the given error with a description of the configuration file's import hierarchy. If a configuration error is encountered, this function should be called on the configuration file's *parent*.

func (*FileInfo) ImportString

func (fi *FileInfo) ImportString() string

ImportString creates a string describing the import hierarchy of the given FileInfo. It should be called on the *parent* of the file of interest.

type NewtError

type NewtError struct {
	Parent     error
	Text       string
	StackTrace []byte
}

func ChildNewtError

func ChildNewtError(parent error) *NewtError

func FmtChildNewtError

func FmtChildNewtError(parent error, format string,
	args ...interface{}) *NewtError

func FmtNewtError

func FmtNewtError(format string, args ...interface{}) *NewtError

func NewNewtError

func NewNewtError(msg string) *NewtError

func PreNewtError

func PreNewtError(err error, format string, args ...interface{}) *NewtError

func (*NewtError) Error

func (se *NewtError) Error() string

type StaticLib

type StaticLib struct {
	File      string
	WholeArch bool
}

func NewStaticLib

func NewStaticLib(file string, wholeArch bool) StaticLib

func UniqueStaticLib

func UniqueStaticLib(libs []StaticLib) []StaticLib

Removes all duplicate static lib from the specified array, while preserving order.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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