forked from lcw2004/one
-
Notifications
You must be signed in to change notification settings - Fork 0
/
One.py
113 lines (83 loc) · 2.87 KB
/
One.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: UTF-8 -*-
# !/usr/bin/python
import os
import subprocess
import shutil
import time
BASE_PATH = "/root/Files/WorkSpace/one"
GIT_USER_NAME = "test"
GIT_PASSWORD = "test"
ONE_UI = BASE_PATH + "/one-ui"
ONE_MAIN = BASE_PATH + "/one-main"
ONE_MAIN_STATIC_PATH = ONE_MAIN + "/src/main/resources/static"
ONE_UI_DIST_PATH = ONE_UI + "/dist"
CMD_START_ONE_MAIN = "nohup java -jar {}/one-main/target/one-main-0.0.1-SNAPSHOT.jar --server.port=8090 --file.path=/root/Files/temp --logging.path=/var/log/one &".format(
BASE_PATH)
def exe_cmd(cmd):
start_time = time.time()
print('*********************************************')
print('执行命令:{}'.format(cmd))
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return_code = p.poll()
while return_code is None:
line = p.stdout.readline()
return_code = p.poll()
line = line.strip()
if line != '':
print(line)
end_time = time.time()
if return_code == 0:
print('执行完毕,耗时:{}秒'.format(int((end_time - start_time))))
else:
print('ERROR: 命令{}执行失败'.format(cmd))
print('*********************************************')
def del_dir(path):
print('Delete Dir:' + path)
if os.path.exists(path):
shutil.rmtree(path)
def make_dir(path):
print('Make Dir:' + path)
if not os.path.exists(path):
os.makedirs(path)
def copy_dir(src, dst):
print('Copy Dir: {} ==> {}'.format(src, dst))
shutil.copytree(src, dst)
def print_line(src):
print("====================================================")
print(src)
print("====================================================")
def kill_progress_by(arg):
exe_cmd("ps -ef | grep \'{}\' | grep -v grep | awk \'{{print $2}}\' | xargs kill".format(arg))
def kill_progress():
kill_progress_by("one/one-main/target/one-main-0.0.1-SNAPSHOT.jar")
def git_pull_origin():
print_line("Step 1, Git Pull Origin, Start")
# Git pull
os.chdir(BASE_PATH)
exe_cmd('git pull https://github.com/lcw2004/one.git master')
print_line("Step 1, Git Pull Origin, End")
def build_one_ui():
print_line("Step 2, Build One-ui, Start")
# 编译one-ui
os.chdir(ONE_UI)
exe_cmd('npm install')
exe_cmd('npm run dll')
exe_cmd('npm run build')
# 拷贝编译出的文件
del_dir(ONE_MAIN_STATIC_PATH)
copy_dir(ONE_UI_DIST_PATH, ONE_MAIN_STATIC_PATH)
print_line("Step 2, Build One-ui, End")
def build_one_main():
print_line("Step 3, Build One-main, Start")
os.chdir(BASE_PATH)
exe_cmd("mvn clean install -Dmaven.test.skip=true")
print_line("Step 3, Build One-main, End")
def start_up():
os.chdir(ONE_MAIN)
exe_cmd(CMD_START_ONE_MAIN)
if __name__ == '__main__':
git_pull_origin()
kill_progress()
build_one_ui()
build_one_main()
start_up()