File: constants.go

package info (click to toggle)
android-platform-tools 29.0.6-28
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 365,224 kB
  • sloc: cpp: 1,049,638; java: 460,532; ansic: 375,452; asm: 301,257; xml: 134,509; python: 92,731; perl: 62,008; sh: 26,753; makefile: 3,210; javascript: 3,172; yacc: 1,403; lex: 455; awk: 368; ruby: 183; sql: 140
file content (77 lines) | stat: -rw-r--r-- 1,646 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package constants

import (
	"fmt"

	"github.com/pkg/errors"
	"github.com/satori/go.uuid"
)

const (
	StatusIntact         = 1
	StatusDownstreamOnly = 2
	StatusModified       = 3
	StatusUpstream       = 4
	StatusForked         = 5
)

const (
	JobStatusNotStarted = "Not Started"
	JobStatusRunning    = "Running"
	JobStatusFailed     = "Failed"
	JobStatusComplete   = "Completed"
)

var StatusToDisplay = map[int]string{
	StatusIntact:         "Intact Projects",
	StatusDownstreamOnly: "Downstream Only Projects",
	StatusModified:       "Modified Projects",
	StatusUpstream:       "Upstream Only Projects",
	StatusForked:         "Forked Projects",
}

type ProjectType int

var Empty ProjectType = 0
var DifferentialSpecific ProjectType = 1
var Global ProjectType = 2

var ProjectTypeToDisplay = map[ProjectType]string{
	Empty:                "Empty",
	DifferentialSpecific: "Differential Specific",
	Global:               "Global",
}

var displayToStatus map[string]int

func makeDisplayToStatus() map[string]int {
	return invertMap(StatusToDisplay)
}

func GetStatusEnum(displayStatus string) (int, error) {
	if displayToStatus == nil {
		displayToStatus = makeDisplayToStatus()
	}
	val, ok := displayToStatus[displayStatus]
	if !ok {
		return 0, errors.New(
			fmt.Sprintf("No matching enum for %s", displayStatus),
		)
	}
	return val, nil
}

func invertMap(m map[int]string) map[string]int {
	inverted := make(map[string]int, len(m))
	for k := range StatusToDisplay {
		v := StatusToDisplay[k]
		inverted[v] = k
	}
	return inverted
}

func NullUUID() uuid.UUID {
	emptyBytes := make([]byte, 16)
	u, _ := uuid.FromBytes(emptyBytes)
	return u
}