python程序在线更新_Python 实现简单的C/S在线更新程序

使用urllib 直接下载html

服务端 Respones把 安装包msi 的二进制流 输出,客户端判断下载下来的文件大小,

一般很小 就有可能是404等信息,只需判断文件大小来决定是否运行更新程序即可

如果为空则输出版本号,放到一个后台线程中运行 就OK了,只用更新服务端文件,

客户端登录自动安装更新,部分代码

class UpdateTimer(threading.Thread):

Runing=False

def __init__(self):

threading.Thread.__init__(self)

self.setDaemon(True)

#self.start()

def start(self):

if UpdateTimer.Runing:return

UpdateTimer.Runing=True

threading.Thread.start(self)

def run(self):

try:

if not Cfg.TestConnection():return

def urlcallback(block_num,bloack_size,total_size):

pass

#if not total_size:return

##print total_size

#prec=100.0*block_num*bloack_size/total_size

#if 100 < prec:prec=100

##print "%.2f%%"%(prec,)

local_path=GetCurrentPath()+'/run.msi'

#if os.path.exists(local_path):os.remove(local_path)

remote_path='http://'+Cfg.c_serveraddr+':81/update.aspx?type=doc&v='+Cfg.version+'&r='+str(Random())

urllib.urlretrieve(remote_path,local_path,urlcallback)

if os.path.getsize(local_path)/(1024*1024)<15:return

if not MessageBoxConfirm("当前检测到新版本客户端,\n现在安装吗?"):return

#os.popen(local_path)

#os.system(local_path)

#'msiexec.exe','*.msi','%systemroot%',SW_SHOWNORMAL

#win32api.ShellExecute(None,"open",local_path,"","",win32con.SW_SHOW)

win32api.ShellExecute(None,'open','msiexec.exe',' /a run.msi','%systemroot%',win32con.SW_SHOW);

finally:

UpdateTimer.Runing=False

def CheckForUpdate():

UpdateTimer().start()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值