1、基于esky实现python应用的自动升级基于esky实现python应用的自动升级一、esky介绍Esky is an auto-update framework for frozen Python applications. It provides a simple API through which apps can find, fetch and install updates, and a bootstrapping mechanism that keeps the app safe in the face of failed or partial updates. Updates
2、can also be sent as differential patches.Esky is currently capable of freezing apps with py2exe, py2app, cxfreeze and bbfreeze. Adding support for other freezer programs should be easy; patches will be gratefully accepted.We are tested and running on Python 2.7 Py2app will work on python3 fine, the
3、other freezers not so much.Esky是一个python编译程序的自动升级框架,提供简单的api实现应用的自动更新(包括比较版本、更新版本),esky支持py2exe,py2app,cxfreeze以及bbfreeze等多种python打包框架。二、esky安装及说明1、pip安装pip install esky2、esky说明3、esky教学视频http:/pyvideo.org/pycon-au-2010/pyconau-2010-esky-keep-your-frozen-apps-fresh.html三、esky用法示例esky用起来比较简单,我们这里以常用的基
4、于wx的windows应用举例。wxpython下有个wx.lib.softwareupdate 类,对wxpython应用的esky升级进行了二次封装。网上有个现成的示范例子,具体网址:http:/www.blog.pythonlibrary.org/2013/07/12/wxpython-updating-your-application-with-esky/代码很简单,对其中的关键部分进行注释说明(红色字体部分):复制代码# -# image_viewer2.py# Created 03-20-2010# Author: Mike Driscoll# -import globimport
5、 osimport wxfrom wx.lib.pubsub import setuparg1 from wx.lib.pubsub import pub as Publisher #申明语句from wx.lib.softwareupdate import SoftwareUpdateimport version#class ViewerPanel(wx.Panel): #- def _init_(self, parent): Constructor wx.Panel._init_(self, parent) width, height = wx.DisplaySize() self.pic
6、Paths = self.currentPicture = 0 self.totalPictures = 0 self.photoMaxSize = height - 200 Publisher.subscribe(self.updateImages, (update images) self.slideTimer = wx.Timer(None) self.slideTimer.Bind(wx.EVT_TIMER, self.update) self.layout() #- def layout(self): Layout the widgets on the panel self.main
7、Sizer = wx.BoxSizer(wx.VERTICAL) btnSizer = wx.BoxSizer(wx.HORIZONTAL) img = wx.EmptyImage(self.photoMaxSize,self.photoMaxSize) self.imageCtrl = wx.StaticBitmap(self, wx.ID_ANY, wx.BitmapFromImage(img) self.mainSizer.Add(self.imageCtrl, 0, wx.ALL|wx.CENTER, 5) self.imageLabel = wx.StaticText(self, l
8、abel=) self.mainSizer.Add(self.imageLabel, 0, wx.ALL|wx.CENTER, 5) btnData = (Previous, btnSizer, self.onPrevious), (Slide Show, btnSizer, self.onSlideShow), (Next, btnSizer, self.onNext) for data in btnData: label, sizer, handler = data self.btnBuilder(label, sizer, handler) self.mainSizer.Add(btnS
9、izer, 0, wx.CENTER) self.SetSizer(self.mainSizer) #- def btnBuilder(self, label, sizer, handler): Builds a button, binds it to an event handler and adds it to a sizer btn = wx.Button(self, label=label) btn.Bind(wx.EVT_BUTTON, handler) sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5) #- def loadImage(self, ima
10、ge): image_name = os.path.basename(image) img = wx.Image(image, wx.BITMAP_TYPE_ANY) # scale the image, preserving the aspect ratio W = img.GetWidth() H = img.GetHeight() if W H: NewW = self.photoMaxSize NewH = self.photoMaxSize * H / W else: NewH = self.photoMaxSize NewW = self.photoMaxSize * W / H
11、img = img.Scale(NewW,NewH) self.imageCtrl.SetBitmap(wx.BitmapFromImage(img) self.imageLabel.SetLabel(image_name) self.Refresh() Publisher.sendMessage(resize, ) #- def nextPicture(self): Loads the next picture in the directory if self.currentPicture = self.totalPictures-1: self.currentPicture = 0 els
12、e: self.currentPicture += 1 self.loadImage(self.picPathsself.currentPicture) #- def previousPicture(self): Displays the previous picture in the directory if self.currentPicture = 0: self.currentPicture = self.totalPictures - 1 else: self.currentPicture -= 1 self.loadImage(self.picPathsself.currentPicture) #- def update(self, event): Called when the slideTimers timer event fires. Loads the next picture from the folder by calling th nextPicture method self.nextPicture() #- def updateImages(self, msg): Updates the picPaths list to contain the current folder
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1