Skip to content

Commit c6a7141

Browse files
author
litongjava
committed
v1.0.0
0 parents  commit c6a7141

File tree

7 files changed

+490
-0
lines changed

7 files changed

+490
-0
lines changed

.gitignore

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
### Eclipse template
2+
*.pydevproject
3+
.metadata
4+
.gradle*
5+
classes/
6+
bin/
7+
tmp/
8+
*.tmp
9+
*.bak
10+
*.swp
11+
*~.nib
12+
local.properties
13+
.settings/
14+
.loadpath
15+
rebel.xml
16+
17+
# Eclipse Core
18+
.project
19+
20+
generatedsources
21+
22+
# External tool builders
23+
.externalToolBuilders/
24+
25+
# Locally stored "Eclipse launch configurations"
26+
*.launch
27+
28+
# CDT-specific
29+
.cproject
30+
31+
# JDT-specific (Eclipse Java Development Tools)
32+
.classpath
33+
34+
# PDT-specific
35+
.buildpath
36+
37+
# sbteclipse plugin
38+
.target
39+
40+
# TeXlipse plugin
41+
.texlipse
42+
43+
44+
45+
### JetBrains template
46+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
47+
48+
*.iml
49+
.flattened-pom.xml
50+
## Directory-based project format:
51+
.idea/
52+
# if you remove the above rule, at least ignore the following:
53+
54+
# User-specific stuff:
55+
# .idea/workspace.xml
56+
# .idea/tasks.xml
57+
# .idea/dictionaries
58+
59+
# Sensitive or high-churn files:
60+
# .idea/dataSources.ids
61+
# .idea/dataSources.xml
62+
# .idea/sqlDataSources.xml
63+
# .idea/dynamic.xml
64+
# .idea/uiDesigner.xml
65+
66+
# Gradle:
67+
# .idea/gradle.xml
68+
# .idea/libraries
69+
70+
# Mongo Explorer plugin:
71+
# .idea/mongoSettings.xml
72+
73+
## File-based project format:
74+
*.ipr
75+
*.iws
76+
77+
## Plugin-specific files:
78+
79+
# IntelliJ
80+
/out/
81+
82+
# mpeltonen/sbt-idea plugin
83+
.idea_modules/
84+
85+
# JIRA plugin
86+
atlassian-ide-plugin.xml
87+
88+
# Crashlytics plugin (for Android Studio and IntelliJ)
89+
com_crashlytics_export_strings.xml
90+
crashlytics.properties
91+
crashlytics-build.properties
92+
93+
build/
94+
95+
# Ignore Gradle GUI config
96+
gradle-app.setting
97+
98+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
99+
!gradle-wrapper.jar
100+
101+
db
102+
103+
### Java template
104+
*.class
105+
106+
# Mobile Tools for Java (J2ME)
107+
.mtj.tmp/
108+
109+
# Package Files #
110+
#*.jar
111+
112+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
113+
hs_err_pid*
114+
115+
116+
### Leiningen template
117+
classes/
118+
target/
119+
logs/
120+
checkouts/
121+
.lein-deps-sum
122+
.lein-repl-history
123+
.lein-plugins/
124+
.lein-failures
125+
.nrepl-port
126+
127+
querydsl/
128+
129+
.DS_Store
130+
131+
*.exe
132+
*.out
133+
134+
*.log
135+
node_modules/
136+
dist/
137+
dist.zip
138+
package-lock.json
139+
*.lock
140+
local.properties
141+
.cxx
142+
.externalNativeBuild
143+
/captures
144+
/build
145+
__pycache__/
146+
*.pyc
147+
148+
149+
cmake-build-debug/
150+
cmake-build-debug-mingw/
151+
venv/
152+
.vs/
153+
Debug/
154+
vcpkg_installed/
155+
.env

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Tong Li
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module mpip
2+
3+
go 1.21.1
4+
5+
require github.com/cloudwego/hertz v0.9.0

go.sum

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM=
2+
github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q=
3+
github.com/bytedance/mockey v1.2.1/go.mod h1:+Jm/fzWZAuhEDrPXVjDf/jLM2BlLXJkwk94zf2JZ3X4=
4+
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
5+
github.com/bytedance/sonic v1.8.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
6+
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
7+
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
8+
github.com/cloudwego/hertz v0.9.0 h1:vmgSMSBx3qgB+ZnqbuEwfy+BFMS1cMr1ZSddif9zZ3A=
9+
github.com/cloudwego/hertz v0.9.0/go.mod h1:WliNtVbwihWHHgAaIQEbVXl0O3aWj0ks1eoPrcEAnjs=
10+
github.com/cloudwego/netpoll v0.5.0/go.mod h1:xVefXptcyheopwNDZjDPcfU6kIjZXZ4nY550k1yH9eQ=
11+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13+
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
14+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
15+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
16+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
17+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
18+
github.com/henrylee2cn/ameda v1.4.8/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4=
19+
github.com/henrylee2cn/ameda v1.4.10/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4=
20+
github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8/go.mod h1:Nhe/DM3671a5udlv2AdV2ni/MZzgfv2qrPL5nIi3EGQ=
21+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
22+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
23+
github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U=
24+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
25+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
26+
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
27+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
28+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
29+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
30+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
31+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
32+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
33+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
34+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
35+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
36+
github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
37+
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
38+
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
39+
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
40+
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
41+
golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4=
42+
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
43+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
44+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
45+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
46+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
47+
golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
48+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
49+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
50+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
51+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
52+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
53+
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
54+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
55+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
56+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
57+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
58+
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

main.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"github.com/cloudwego/hertz/pkg/common/hlog"
7+
"os"
8+
"os/exec"
9+
"strings"
10+
)
11+
12+
const requirementsFile = "requirements.txt"
13+
14+
func main() {
15+
if len(os.Args) < 3 {
16+
hlog.Info("Usage: mpip <install|uninstall> <package>")
17+
os.Exit(1)
18+
}
19+
20+
command := os.Args[1]
21+
packageName := os.Args[2]
22+
hlog.Infof("%s %s", command, packageName)
23+
switch command {
24+
case "install":
25+
installPackage(packageName)
26+
case "uninstall":
27+
uninstallPackage(packageName)
28+
default:
29+
hlog.Info("Invalid command. Use 'install' or 'uninstall'.")
30+
os.Exit(1)
31+
}
32+
}
33+
34+
func installPackage(packageName string) {
35+
cmd := exec.Command("pip", "install", packageName)
36+
cmd.Stdout = os.Stdout
37+
cmd.Stderr = os.Stderr
38+
if err := cmd.Run(); err != nil {
39+
hlog.Errorf("Failed to install package %s: %v\n", packageName, err)
40+
os.Exit(1)
41+
}
42+
43+
addPackageToRequirements(packageName)
44+
}
45+
46+
func uninstallPackage(packageName string) {
47+
cmd := exec.Command("pip", "uninstall", "-y", packageName)
48+
cmd.Stdout = os.Stdout
49+
cmd.Stderr = os.Stderr
50+
if err := cmd.Run(); err != nil {
51+
fmt.Printf("Failed to uninstall package %s: %v\n", packageName, err)
52+
os.Exit(1)
53+
}
54+
55+
removePackageFromRequirements(packageName)
56+
}
57+
58+
func addPackageToRequirements(packageName string) {
59+
file, err := os.OpenFile(requirementsFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
60+
if err != nil {
61+
hlog.Errorf("Failed to open %s: %v\n", requirementsFile, err)
62+
os.Exit(1)
63+
}
64+
defer file.Close()
65+
66+
_, err = file.WriteString(packageName + "\n")
67+
if err != nil {
68+
hlog.Errorf("Failed to write to %s: %v\n", requirementsFile, err)
69+
os.Exit(1)
70+
}
71+
}
72+
73+
func removePackageFromRequirements(packageName string) {
74+
file, err := os.Open(requirementsFile)
75+
if err != nil {
76+
hlog.Errorf("Failed to open %s: %v\n", requirementsFile, err)
77+
os.Exit(1)
78+
}
79+
defer file.Close()
80+
81+
var lines []string
82+
scanner := bufio.NewScanner(file)
83+
for scanner.Scan() {
84+
line := scanner.Text()
85+
if strings.TrimSpace(line) != packageName {
86+
lines = append(lines, line)
87+
}
88+
}
89+
90+
if err := scanner.Err(); err != nil {
91+
hlog.Errorf("Failed to read %s: %v\n", requirementsFile, err)
92+
os.Exit(1)
93+
}
94+
95+
file, err = os.Create(requirementsFile)
96+
if err != nil {
97+
hlog.Errorf("Failed to open %s: %v\n", requirementsFile, err)
98+
os.Exit(1)
99+
}
100+
defer file.Close()
101+
102+
for _, line := range lines {
103+
_, err := file.WriteString(line + "\n")
104+
if err != nil {
105+
hlog.Errorf("Failed to write to %s: %v\n", requirementsFile, err)
106+
os.Exit(1)
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)