-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_nb_time_github.py
50 lines (31 loc) · 1005 Bytes
/
git_nb_time_github.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
import subprocess
import time
def getstatusoutput(cmd):
try:
data = subprocess.check_output(cmd, shell=True, universal_newlines=True,
stderr=subprocess.STDOUT, encoding='utf8') # 必須設置為utf8, 不然报错了。
exitcode = 0
except subprocess.CalledProcessError as ex:
data = ex.output
exitcode = ex.returncode
if data[-1:] == '\n':
data = data[:-1]
return exitcode, data
def do_cmd(cmd_strx):
print(f'执行 {cmd_strx}')
retx = getstatusoutput(cmd_strx)
print(retx[0])
# if retx[0] !=0:
# raise ValueError('要检查git提交')
print(retx[1], '\n')
return retx
t0 = time.time()
do_cmd('git pull origin')
do_cmd('git diff')
do_cmd('git add ./.')
do_cmd('git commit -m commit')
do_cmd('git push origin')
# print(subprocess.getstatusoutput('git push github'))
print(f'spend_time {time.time() - t0}')
if __name__ == '__main__':
time.sleep(1000000)