forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
55 lines (47 loc) · 1.6 KB
/
test.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2017年5月7日
@author: Irony."[讽刺]
@site: alyl.vip, orzorz.vip, irony.coding.me , irony.iask.in , mzone.iask.in
@email: [email protected]
@file: 自动更新.test
@description:
'''
import sys
sys.path.append("mylibs")
import os
from time import sleep
from zipfile import ZipFile
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: [email protected]"
__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
def update():
# 更新
from mylibs import testlibs # @UnresolvedImport
v1 = testlibs.version() # 获取本地模块版本
v2 = "0.0.2" # 模拟新版本(也可以从网络中检测)
if v1 != v2: # 需要更新
print("发现新版本:0.0.2")
# 模拟从网络中下载更新包并解压(也可以包含图片等其它文件)
with ZipFile("mylibs2.zip", "r") as zf:
zf.extractall(os.path.dirname(sys.executable)) # 解压到当前目录
return 1
return 0
def main():
from mylibs import testlibs # @UnresolvedImport
testlibs.test()
print("当前版本:", testlibs.version())
if update():
print("更新完毕,即将重启")
import platform
if platform.system() == "Windows":
import ctypes
ctypes.windll.user32.MessageBoxW(
0, "更新完毕,关闭对话框即将重启", "提示", 0x0000030)
sleep(0.5)
os.startfile(sys.executable) # 重启
sys.exit() # 退出本身
if __name__ == "__main__":
main()
input("press any key exit")