-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathupdate-console.py
executable file
·59 lines (56 loc) · 1.78 KB
/
update-console.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
#!/usr/bin/env python3
import os
import sys
import json
import shutil
import requests
import traceback
# 读取文本文档
def read_txt(path):
f = open(path,"r") # 设置文件对象
str = f.read() # 获取内容
f.close() # 关闭文本对象
return str # 返回结果
def GetPackageUpdateInformation():
global setting
global package
for i in allJson['Program']:
if i['Package'] == package:
return i
try:
setting = json.loads(read_txt("{}/setting.json".format(os.path.split(os.path.realpath(__file__))[0])))
except:
traceback.print_exc()
print("配置文件无法访问!")
package = setting['Package']
nowVersion = setting['Version']
try:
jsons = requests.get(setting["Url"])
except:
traceback.print_exc()
print("服务器出现错误!")
sys.exit(1)
allJson = json.loads(jsons.text)
updateInformation = GetPackageUpdateInformation()
name = updateInformation['Name']
newVersion = updateInformation['Version']
print("更新程序:{}".format(name))
print("最新版本:{}".format(newVersion))
print("目前版本:{}".format(nowVersion))
if nowVersion == newVersion:
print("目前是最新版本,无需更新!")
quit()
print("更新内容:")
print(updateInformation['New Things'])
choose = input("更新?[Y/N]")
if choose.upper() == "N":
quit()
if os.path.exists("/tmp/update-console-{}".format(package)):
shutil.rmtree("/tmp/update-console-{}".format(package))
os.mkdir("/tmp/update-console-{}".format(package))
if updateInformation["Linux App Url"][0] == None:
print("没有可用包源")
quit()
os.system("wget '{}' -P '/tmp/update-console-{}'".format(updateInformation["Linux App Url"][0], package))
os.system("sudo dpkg -i /tmp/update-console-{}/*".format(package))
os.system("sudo apt install -f -y")