使用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()