MCPcopy Index your code
hub / github.com/XmirrorSecurity/OpenSCA-cli / pipenvGraph

Function pipenvGraph

opensca/sca/python/env.go:58–124  ·  view source on GitHub ↗
(ctx context.Context, dir string)

Source from the content-addressed store, hash-verified

56}
57
58func pipenvGraph(ctx context.Context, dir string) *model.DepGraph {
59
60 data, ok := runCmd(ctx, dir, "pipenv", "graph")
61 if !ok || len(data) == 0 {
62 return nil
63 }
64
65 root := &model.DepGraph{}
66
67 s := bufio.NewScanner(bytes.NewReader(data))
68 tops := []*model.DepGraph{}
69
70 for s.Scan() {
71
72 line := strings.TrimRight(s.Text(), "\r\n")
73
74 // 当前层级
75 level := 0
76 // 空格个数
77 space := 0
78 for i := range line {
79 if ('a' <= line[i] && line[i] <= 'z') || ('A' <= line[i] && line[i] <= 'Z') {
80 level = (space + 3) / 4
81 line = line[i:]
82 break
83 }
84 if line[i] == ' ' {
85 space++
86 }
87 }
88
89 dep := &model.DepGraph{}
90
91 if level == 0 {
92 tags := strings.Split(line, "==")
93 if len(tags) == 2 {
94 dep.Name = tags[0]
95 dep.Version = tags[1]
96 } else {
97 logs.Warnf("parse pipenv graph err in line: %s", line)
98 dep.Name = line
99 }
100 root.AppendChild(dep)
101 } else {
102 i := strings.Index(line, " ")
103 if i == -1 {
104 logs.Warnf("parse pipenv graph err in line: %s", line)
105 dep.Name = line
106 } else {
107 dep.Name = line[:i]
108 }
109 line = strings.Trim(line[i+1:], "[]")
110 i = strings.LastIndex(line, "installed: ")
111 if i != -1 {
112 dep.Version = line[i+len("installed: "):]
113 }
114 }
115

Callers 1

ParsePythonWithEnvFunction · 0.85

Calls 5

AppendChildMethod · 0.95
WarnfFunction · 0.92
runCmdFunction · 0.85
ScanMethod · 0.80
IndexMethod · 0.80

Tested by

no test coverage detected