eztools

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: Apache-2.0 Imports: 22 Imported by: 3

README

EZ Tools

UI - ui.go

Debugging and Verbose to control interaction and verbose levels.

Xml - cfg.go

It reads from an xml into a structure.

App self-update - appup.go

It gets server info from database and updates in background. The next time the app is run, it will be in the new version.

LDAP - auth.go

It gets server info, including DN structure, from database and tries to bind to check for authentication.

DB - conn.go, tbl.go, pair.go

It provides operations to connect, insert, search from databases. pair.go is for id(int)-str(string) tables, while tbl.go is for more various types of tables.

Restful APIs - rest.go

Use this to send and receive through Restful APIs. Based on the needs for Jira and Gerrit.

Contacts - teams/, contacts

It provides operations to manage contacts and teams in databases.

tables

Miscellaneous CREATE TABLE chore (id CHAR(50) NOT NULL UNIQUE, str TINYTEXT, PRIMARY KEY(id));

For Google tests CREATE TABLE google (id TINYINT AUTO_INCREMENT, tool TINYINT, android TINYINT, ver TINYINT, req DATE, exp DATE, PRIMARY KEY(id)); CREATE TABLE prodgle (google TINYINT, product TINYINT); CREATE TABLE tool (id TINYINT AUTO_INCREMENT, str TINYTEXT, PRIMARY KEY(id)); CREATE TABLE product (id TINYINT, str TINYTEXT); CREATE TABLE bit (id TINYINT AUTO_INCREMENT, str TINYTEXT, PRIMARY KEY(id)); CREATE TABLE phase (id TINYINT AUTO_INCREMENT, str TINYTEXT, PRIMARY KEY(id)); CREATE TABLE android (id TINYINT AUTO_INCREMENT, str TINYTEXT, PRIMARY KEY(id)); CREATE TABLE prodfo (product TINYINT, bit TINYINT, android TINYINT, phase TINYINT); CREATE TABLE ver (id TINYINT AUTO_INCREMENT, str TINYTEXT, PRIMARY KEY(id));

For SOC CREATE TABLE carrier (id TINYINT, str TINYTEXT); CREATE TABLE soc (carrier TINYTEXT, product TINYTEXT, android TINYTEXT, gms TINYTEXT, section SMALLINT, subsection SMALLINT, identifier TINYTEXT, description VARCHAR(200), team TINYINT, compliance TINYINT, comments VARCHAR(100)); CREATE TABLE sec (id SMALLINT, str TINYTEXT); CREATE TABLE subsec (id SMALLINT, str TINYTEXT); CREATE TABLE compl (id TINYINT, str TINYTEXT);

For contacts CREATE TABLE team (id TINYINT AUTO_INCREMENT, str TINYTEXT, leader TINYINT, PRIMARY KEY(id)); CREATE TABLE contacts (id TINYINT AUTO_INCREMENT, number TINYTEXT, name TINYTEXT NOT NULL, team TINYINT, ext TINYTEXT, phone TINYTEXT, mail TINYTEXT NOT NULL, ldap TINYTEXT, uid TINYTEXT, PRIMARY KEY(id)) CHARSET=utf8;

For weekly reports CREATE TABLE weeklyTaskBars (id TINYINT NOT NULL UNIQUE, str TINYTEXT NOT NULL, PRIMARY KEY(id)); CREATE TABLE weeklyTaskTitles (id TINYINT AUTO_INCREMENT, str TINYTEXT NOT NULL, PRIMARY KEY(id)); CREATE TABLE weeklyTaskCurr (id TINYINT NOT NULL UNIQUE, str TINYINT NOT NULL UNIQUE); CREATE TABLE weeklyTaskNext (id TINYINT NOT NULL UNIQUE, str TINYINT NOT NULL UNIQUE); CREATE TABLE weeklyTaskDesc (id TINYINT AUTO_INCREMENT, str VARCHAR(500) NOT NULL UNIQUE, PRIMARY KEY(id)); CREATE TABLE weeklyTaskWork (id TINYINT AUTO_INCREMENT, str TINYINT NOT NULL, contact TINYINT NOT NULL, section TINYINT NOT NULL, week TINYINT NOT NULL, PRIMARY KEY(id));

table field comment example
chore id a string for name googleVer
str a string for value 1.0
sec id one id may relate to multiple strings 5
str Browser
subsec id one id may relate to multiple strings 1
str WAP
team id 2
str BSP
leader id in table contacts 16
compl id one id may relate to multiple strings 3
str Complies
carrier id one id may relate to multiple strings 4
str CMCC
tool id 10
str CTS
ver id 13
str 201805
product id one id may relate to multiple strings 11
str Pixel
bit id 15
str 32/64/go
prodfo product 11
bit 15
android 12
phase 16
phase id 16
str MP
prodgle google 14
product 11
android id if all wanted, apply to all current 12
str 8.1
google id 14
tool id in table tool 10
android id in table android 12
ver id in table ver 13
req date of requirement 20080401
exp date of expiry 20080501
soc carrier string CMCC
product string Pixel
android string 8.1Go
gms string 201805
section id in table sec 5
subsection id in table subsec 1
identifier string MSR19820
description string detail..
team id in table team 2
compliance id in table compl 3
comments string not supp
contacts id 16
number string 007
name string Allen
team id in table team 2
ext string 12345
phone string 1234567890
mail string allen
ldap string of user name for LDAP commands Allen
uid string of user name for code servers allen
weeklyTaskBars id 0, 1 for current & next week 23
str string Tasks Accomplished
weeklyTaskTitles id 17
str string Project 1
weeklyTaskCurr id the tens place is the page number of ppt. the ones place is the order within a page. 18
str id in table weeklyTaskTitles 17
weeklyTaskNext id the tens place is the page number of ppt. the ones place is the order within a page. 19
str id in table weeklyTaskTitles 17
weeklyTaskDesc id 20
str unique work description bug fix
weeklyTaskWork id 21
str id in weeklyTaskDesc 20
contact id in table contacts 16
section id in table weeklyTaskCurr/Next 18
week week number as int 22

table details

chore's ids

  • GoogleUrl: Url of google tool app
  • GoogleUrlDev: Dev Url of google tool app
  • GoogleDir: dir under Url
  • GoogleApp: app name of google tool app
  • GoogleRes: resource request name under Url
  • GooglexxxFolder: root path on the remote or local server. xxx=Svr/Lcl
  • GooglexxxPath_XXX: tool paths on the servers. XXX=CTS/ETS/GTS/STS/VTS/PAB/GMS
  • GooglexxxPath_Android: prefix to Android versions of the paths on the servers
  • GooglexxxSubAndroid: Among CTS, ETS, GTS, STS, VTS, PAB & GMS, which have sub-directories for Android versions, appended by a space for each to separate.
  • GoogleSvrSTS_pre: prefix of files
  • GoogleSvrVTS_pre: prefix of files all bits need
  • GoogleSvrPAB_scr: prefix of script files all bits need
  • GoogleSvrPAB_img: prefix of image files different bits need
  • LogTran: log file name for file transport. comma separated csv format with no headers and columns are source file name and destination file name
  • LogSize: log file size. usage reserved
  • WeeklyPptUrl: Url of weekly report app
  • WeeklyPptDir: dir under Url
  • WeeklyPptApp: app name of weekly report tool app
  • WeeklyPptUrlDev: dev url of weekly report tool app
  • WeeklyPptStaticPath: dir of PPT on static server
  • WeeklyPptStaticSuf: suffix of PPT on static server. defaults to .pptx
  • AuthIP: IP of authentication server
  • AuthRootD: former part of root bind dn before user name
  • AuthRootN: latter part of root bind dn after user name

Documentation

Index

Constants

View Source
const (

	// DefID is the default ID
	DefID = 0
	// AllID stands for all items
	AllID = DefID - 1
	// InvalidID better to be negative to be different from a normal ID
	InvalidID = DefID - 2 //pairs defined some related
)
View Source
const (
	AUTH_NONE = iota
	AUTH_PLAIN
	AUTH_BASIC
	AUTH_DIGEST
	METHOD_GET  = "GET"
	METHOD_PUT  = "PUT"
	METHOD_POST = "POST"
)
View Source
const (
	// TblCHORE contains misc items
	TblCHORE = "chore"
	// TblTOOL contains xTS names
	TblTOOL = "tool"
	// TblVER contains versions of xTS
	TblVER = "ver"
	// TblANDROID contains android versions
	TblANDROID = "android"
	// TblGOOGLE contains xTS requirements
	TblGOOGLE = "google"
	// TblPRODUCT contains product names
	TblPRODUCT = "product"
	// TblPRODGLE contains matches of products and requirements
	TblPRODGLE = "prodgle"
	// TblPRODFO contains matches of products and info
	TblPRODFO = "prodfo"
	// TblBIT contains bit info
	TblBIT = "bit"
	// TblPHASE contains phase info
	TblPHASE = "phase"
	// TblTEAM contains team names
	TblTEAM = "team"
	// TblCONTACTS contains contact info
	TblCONTACTS = "contacts"
	// TblWEEKLYTASKBARS contains bars in report
	TblWEEKLYTASKBARS = "weeklyTaskBars"
	// TblWEEKLYTASKTITLES contains titles in report
	TblWEEKLYTASKTITLES = "weeklyTaskTitles"
	// TblWEEKLYTASKCURR contains titles of current week
	TblWEEKLYTASKCURR = "weeklyTaskCurr"
	// TblWEEKLYTASKNEXT contains titles of next week
	TblWEEKLYTASKNEXT = "weeklyTaskNext"
	// TblWEEKLYTASKDESC contains descriptions of tasks
	TblWEEKLYTASKDESC = "weeklyTaskDesc"
	// TblWEEKLYTASKWORK contains items of tasks
	TblWEEKLYTASKWORK = "weeklyTaskWork"

	// FldID is the name of field id
	FldID = "id"
	// FldSTR is the name of field str
	FldSTR = "str"

	// FldPHASE is the name of field phase
	FldPHASE = "phase"
	// FldTOOL is the name of field tool
	FldTOOL = "tool"
	// FldANDROID is the name of field android
	FldANDROID = "android"
	// FldPRODUCT is the name of field product
	FldPRODUCT = "product"
	// FldGOOGLE is the name of field google
	FldGOOGLE = "google"
	// FldVER is the name of field versions
	FldVER = "ver"
	// FldREQ is the name of field requirements
	FldREQ = "req"
	// FldEXP is the name of field expiry
	FldEXP = "exp"
	// FldBIT is the name of field bit
	FldBIT = "bit"

	// contacts
	// FldLEADER is the name of field leader
	FldLEADER = "leader"
	// FldNUMBER is the name of field number
	FldNUMBER = "number"
	// FldNAME is the name of field name
	FldNAME = "name"
	// FldTEAM is the name of field team
	FldTEAM = "team"
	// FldEXT is the name of field ext
	FldEXT = "ext"
	// FldPHONE is the name of field phone
	FldPHONE = "phone"
	// FldMAIL is the name of field mail
	FldMAIL = "mail"
	// FldLDAP is the name of field ldap
	FldLDAP = "ldap"
	// FldUID is the name of field uid
	FldUID = "uid"
	// FldNICK is the name of field nick
	FldNICK = "nick"

	// FldSECTION is the name of field section
	FldSECTION = "section"
)

Variables

View Source
var (
	// ErrNoValidResults stands for no valid results
	ErrNoValidResults = errors.New("No Valid results")
	// ErrOutOfBound stands for out of bound
	ErrOutOfBound = errors.New("Out of bound")
	// ErrInvalidInput stands for invalid input
	ErrInvalidInput = errors.New("Invalid input")
	// ErrInExistence stands for result for input already in existence
	ErrInExistence = errors.New("In Existence")
)
View Source
var (
	// Debugging marks debugging mode
	Debugging bool // whether more debug procedures
	// Verbose marse debugging output level
	Verbose = 0
)

Functions

func AddPair

func AddPair(db *sql.DB, table string, id int, str string) (res int, err error)

AddPair adds an item with ID and value

func AddPairNoID

func AddPairNoID(db *sql.DB, table string, str string) (int, error)

AddPairNoID adds an item with value, where ID should be auto generated

func AddWtParams

func AddWtParams(db *sql.DB, table string, fields []string, values []string, yes2all bool) (int, error)

AddWtParams adds "values" to "fields", no matter whether duplicate records in existence. Parameter yes2all = no confirmation in debug mode. Always no confirmation in non-debug mode.

func AddWtParamsUniq

func AddWtParamsUniq(db *sql.DB, table string, fields []string, values []string, yes2all bool) (int, error)

AddWtParamsUniq adds "values" to "fields", if no duplicate records in existence. Parameter yes2all = no confirmation in debug mode. Always no confirmation in non-debug mode.

func AppUpgrade

func AppUpgrade(db *sql.DB, prefix string, ver string, server *chan string, ch chan bool)

AppUpgrade checks for updates and applies the update automatically, which will work next time the app is run.

func Authenticate

func Authenticate(db *sql.DB, username, password string) error

Authenticate checks whether authenticated. Return value: nil if true.

func ChkCfmNPrompt

func ChkCfmNPrompt(noti, exception string) bool

ChkCfmNPrompt checks defaults and return false only when user replied exception program exits when user replied 'q' or 'e' no more confirmations when user replied 'a' or 'c' verbose set when user replied a number, in which case the prompt will show again

func ChooseInts

func ChooseInts(arr [][]string, notif string) (id int)

ChooseInts asks user to choose from a slice Parameters. arr[][0]=id. arr[][1]=string

func ChoosePair

func ChoosePair(db *sql.DB, table string) (int, error)

ChoosePair asks user to choose from a table by ID - value pairs.

func ChoosePairNAddAssociated

func ChoosePairNAddAssociated(db *sql.DB, idTable, strTable string, uniq bool) (int, error)

ChoosePairNAddAssociated asks user to choose by idTable - strTable pairs,

where idTable.str == strTable.id (return value)

Parameter uniq is of no use

func ChoosePairOrAdd

func ChoosePairOrAdd(db *sql.DB, table string, uniq bool) (int, error)

ChoosePairOrAdd asks user to choose from a table by ID - value pairs,

allowing to add one new.

func ChooseStrings

func ChooseStrings(choices []string) (res int)

ChooseStrings asks user to choose from a slice

func ChooseStringsWtIDs added in v0.0.2

func ChooseStringsWtIDs(fL func() int, fI func(int) int,
	fV func(int) string, notif string) (res int)

ChooseStringsWtIDs is for general usage to ask user to choose from a slice parameters.

fL=quantity of elements
fI=get index to match user's input
fV=get message to show for each index
notif=notification string for user

func Connect

func Connect() (*sql.DB, error)

Connect connects to the database using parameters from eztools.xml root element is named "root", elements include "ip", "db", "user" and "pass"

func ConnectWtCfg

func ConnectWtCfg(file string) (*sql.DB, error)

ConnectWtCfg connects to the database using parameters from an xml file root element is named "root", elements include "ip", "db", "user" and "pass"

func ConnectWtParam

func ConnectWtParam(user, pass, ip, database string) (db *sql.DB, err error)

ConnectWtParam connects to the database using parameters.

func DeleteWtID

func DeleteWtID(db *sql.DB, table, id string) error

DeleteWtID by ID

func DeleteWtParams

func DeleteWtParams(db *sql.DB, table, where string) error

DeleteWtParams deletes items with specified WHERE clause

func FindStrMap

func FindStrMap(obj interface{}, key string) (interface{}, bool)
FindStrMap find string key in map[string]interface{} obj,

returning the value and true or nil and false.

func GetDate

func GetDate(info string) string

GetDate asks user to input a date string

func GetPair

func GetPair(db *sql.DB, table, id, from, to string) (string, error)

GetPair gets "to" field from "from" field in "table" When multiple results got, the first one will be taken. return value error = from db.Query;

ErrNoValidResults when no valid results got,
                  and LogErrPrint will be called.

func GetPairID

func GetPairID(db *sql.DB, table string, str string) (int, error)

GetPairID gets ID (int) from value (string) When multiple results got, the first one will be taken.

func GetPairIDFromInt

func GetPairIDFromInt(db *sql.DB, table string, val int) (int, error)

GetPairIDFromInt gets ID (int) from value (int) When multiple results got, the first one will be taken.

func GetPairInt

func GetPairInt(db *sql.DB, table string, id string) (int, error)

GetPairInt gets value (int) from ID (string)

func GetPairStr

func GetPairStr(db *sql.DB, table string, id string) (string, error)

GetPairStr gets value (string) from ID (string)

func GetPairStrFromInt

func GetPairStrFromInt(db *sql.DB, table string, id int) (string, error)

GetPairStrFromInt gets value (string) from ID (int)

func InitLogger

func InitLogger(out *os.File) error

InitLogger opens log file

func Locate

func Locate(db *sql.DB, table string, str string) (id int, err error)

Locate gets ID (int) from value (string) Deprecated: Use GetPairID instead.

func Log

func Log(out string)

Log logs it

func LogErr

func LogErr(err error)

LogErr logs error

func LogErrFatal

func LogErrFatal(err error)

LogErrFatal logs and prints error and exits

func LogErrPrint

func LogErrPrint(err error)

LogErrPrint logs and prints error

func LogErrPrintWtInfo

func LogErrPrintWtInfo(info string, err error)

LogErrPrintWtInfo logs and prints error with information

func LogErrWtInfo

func LogErrWtInfo(info string, err error)

LogErrWtInfo logs error with information

func LogFatal

func LogFatal(out string)

LogFatal logs and prints it and exits

func LogPrint

func LogPrint(out ...interface{})

LogPrint logs and prints it

func LogPrintWtTime

func LogPrintWtTime(out string)

LogPrintWtTime logs and prints it with time

func PromptInt

func PromptInt(pi string) (res int, err error)

PromptInt prompts user and gets input Return values. zero values are default

func PromptIntStr

func PromptIntStr(pi string, ps string) (i int, s string)

PromptIntStr prompts user and gets two inputs Return values. zero values are default

func PromptPwd

func PromptPwd(ps string) string

PromptPwd prompts user and get password

func PromptStr

func PromptStr(ps string) string

PromptStr prompts user and get input

func RangeStrMap

func RangeStrMap(obj interface{}, fun func(k string, v interface{}) bool) bool
RangeStrMap iterate through map[string]interface{} obj, calling fun for

each element recursively. When fun returns true, it stops. false is returned if no element found.

func RestGet

func RestGet(url string, authInfo AuthInfo, bodyReq io.Reader) (bodyMap interface{}, errNo int, err error)

RestGet sends Restful API request and returns the result.

func RestGetOrPostWtMagic

func RestGetOrPostWtMagic(method, url string, authInfo AuthInfo, bodyReq io.Reader, magic []byte) (bodyMap interface{}, errNo int, err error)

func RestGetWtMagic

func RestGetWtMagic(url string, authInfo AuthInfo, bodyReq io.Reader, magic []byte) (bodyMap interface{}, errNo int, err error)
RestGetWtMagic sends Restful API request and returns the result.

A magic string can be listed to be stripped in the beginning of the result. If magic string is assigned but not found in the result, the result will not be parsed.

func RestPostWtMagic

func RestPostWtMagic(url string, authInfo AuthInfo, bodyReq io.Reader, magic []byte) (bodyMap interface{}, errNo int, err error)
RestPostWtMagic sends Restful API request and returns the result.

A magic string can be listed to be stripped in the beginning of the result. If magic string is assigned but not found in the result, the result will not be parsed.

func Rows2Strings

func Rows2Strings(db *sql.DB, rows *sql.Rows) (res [][]string, err error)

Rows2Strings returns arrays from rows Parameter db not used

func Search(db *sql.DB, table string, cri string, sel []string, more string) ([][]string, error)

Search gets values of fields "sel" from "table", using "cri" as "WHERE",

with "more" appended to SQL command.

Parameters: more: will not be prefixed with space automatically

func ShowArrln

func ShowArrln(arr []string)

ShowArrln prints a slice in one line

func ShowByteln

func ShowByteln(ps []byte)

ShowByteln prints byte slice

func ShowSthln

func ShowSthln(sth ...interface{})

ShowSthln prints all kinds of stuffs with line feed

func ShowStr

func ShowStr(ps string)

ShowStr prints it with no line breaks

func ShowStrln

func ShowStrln(ps string)

ShowStrln prints it with a line break

func TranDate

func TranDate(date string) string

TranDate removes minuses from date string

func UpdatePairID

func UpdatePairID(db *sql.DB, table string, idOld, idNew string) error

UpdatePairID updates ID

func UpdatePairWtParams

func UpdatePairWtParams(db *sql.DB, table string, id, str string) error

UpdatePairWtParams updates value by ID

func UpdateWtParams

func UpdateWtParams(db *sql.DB, table, cri string, fields, values []string, yes2all bool) error

UpdateWtParams updates "fields" in "table" with "values", using "cri" as "WHERE". Parameter yes2all = no confirmation in debug mode. Always no confirmation in non-debug mode.

func XMLRead

func XMLRead(file string, data interface{}, _ bool) error

XMLRead reads file into input structure

func XMLWrite added in v1.1.1

func XMLWrite(file string, data interface{}, createIfNeeded bool) error

XMLWrite writes input structure to file

func XMLWriteNoCreate added in v1.1.1

func XMLWriteNoCreate(file string, cfg interface{}) error

XMLWriteNoCreate writes config file from input structure by a full path (with .xml extension)

func XMLsReadDefault

func XMLsReadDefault(path, file string, cfg interface{},
	createIfNeeded bool) (
	pathFound string, err error)

XMLsReadDefault reads a config file

func XMLsReadDefaultNoCreate added in v1.1.1

func XMLsReadDefaultNoCreate(path, file string, cfg interface{}) (string, error)

XMLsReadDefaultNoCreate reads config file into input structure from given path, or given file name (plus .xml) under current dir or home dir returns full file name with path

Types

type AuthInfo

type AuthInfo struct {
	Type       int
	User, Pass string
}

type PairsInt

type PairsInt struct {
	// contains filtered or unexported fields
}

PairsInt is a collection of pairsI

func GetSortedPairsInt

func GetSortedPairsInt(db *sql.DB, table string) (pi *PairsInt, err error)

GetSortedPairsInt returns all sorted PairsInt from input table

func (*PairsInt) Next

func (pi *PairsInt) Next() (int, int, error)

Next moves to the next item in PairsInt and return the values error=ErrOutOfBound when the end met

func (*PairsInt) Rewind

func (pi *PairsInt) Rewind()

Rewind sets the cursor to the beginning of PairsInt

type PairsStr

type PairsStr struct {
	// contains filtered or unexported fields
}

PairsStr is a collection of pairs

func GetSortedPairsStr

func GetSortedPairsStr(db *sql.DB, table string) (ps *PairsStr, err error)

GetSortedPairsStr returns all sorted PairsStr from input table

func (*PairsStr) FindStr

func (ps *PairsStr) FindStr(s string) (int, error)

FindStr find the first ID where str matches input return value: ErrNoValidResults when none found

func (*PairsStr) Next

func (ps *PairsStr) Next() (int, string, error)

Next moves to the next item in PairsInt and return the values error=ErrOutOfBound when the end met

func (*PairsStr) Rewind

func (ps *PairsStr) Rewind()

Rewind sets the cursor to the beginning of PairsInt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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