Changeset 3233

Show
Ignore:
Timestamp:
07/09/07 18:04:35 (1 year ago)
Author:
ed
Message:

This commit adds auto-update functionality to the Dabo framework. I've added some web services to dabodev.com that will report on the current status of the framework, and allow updates to be retrieved.

While the user interface for this is not set yet, a Dabo developer will be able to download the framework once without Subversion or any other software, and then control how often the framework will check the website for updates. If updates are available, the user will be given the option of downloading them and re-launching their app, or ignoring them for the time being.

Still lots of stuff to add, but this is working pretty well from within my domain. Next we need others to test it.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/dApp.py

    r3200 r3233  
    88import ConfigParser 
    99import inspect 
    10 import dabo, dabo.ui, dabo.db 
     10import datetime 
     11import urllib 
     12import shutil 
     13import dabo 
     14import dabo.ui 
     15import dabo.db 
    1116from dabo.lib.connParser import importConnections 
    1217import dSecurityManager 
     
    155160        dabo.dAppRef = self 
    156161        self._beforeInit() 
     162         
    157163        # If we are displaying a splash screen, these attributes control 
    158164        # its appearance. Extract them before the super call. 
     
    177183        self._tempFileHolder = TempFileHolder() 
    178184        self.getTempFile = self._tempFileHolder.getTempFile 
     185        # Create the framework-level preference manager 
     186        self._frameworkPrefs = dabo.dPref(key="dabo_framework") 
    179187 
    180188        # List of form classes to open on App Startup 
     
    337345 
    338346 
     347    def _currentUpdateVersion(self): 
     348        localVers = dabo.version["revision"] 
     349        try: 
     350            localVers = localVers.split(":")[1] 
     351        except: 
     352            # Not a mixed version 
     353            pass 
     354        ret = int("".join([ch for ch in localVers if ch.isdigit()])) 
     355        return ret 
     356 
     357         
     358    def _checkForUpdates(self): 
     359        ret = False 
     360        prf = self._frameworkPrefs 
     361        val = prf.getValue 
     362        now = datetime.datetime.now() 
     363        autoUpdate = val("auto_update") 
     364        if autoUpdate: 
     365            checkInterval = val("update_interval") 
     366            if checkInterval is None: 
     367                # Default to one day 
     368                checkInterval = 24 * 60 
     369            mins = datetime.timedelta(minutes=checkInterval) 
     370            lastCheck = val("last_check") 
     371            if lastCheck is None: 
     372                lastCheck = datetime.datetime(1900, 1, 1) 
     373            if now > (lastCheck + mins): 
     374                # See if there is a later version 
     375                url = "http://dabodev.com/frameworkVersions/latest" 
     376                try: 
     377                    vers = int(urllib.urlopen(url).read()) 
     378                except: 
     379                    vers = -1 
     380                localVers = self._currentUpdateVersion() 
     381                ret = localVers < vers 
     382                 
     383                print "LOCAL V", localVers 
     384                print "WEB VER", vers 
     385        prf.setValue("last_check", now) 
     386        return ret 
     387 
     388 
     389    def _updateFramework(self): 
     390        """Get any changed files from the dabodev.com server, and replace the local copies with them.""" 
     391        url = "http://dabodev.com/frameworkVersions/changedFiles/%s" % self._currentUpdateVersion() 
     392        try: 
     393            resp = urllib.urlopen(url) 
     394        except: 
     395            # No internet access, or Dabo site is down. 
     396            return 
     397        flist = eval(resp.read()) 
     398        basePth = os.path.split(dabo.__file__)[0] 
     399        url = "http://dabodev.com/versions/dabo/%s" 
     400        for mtype, fpth in flist: 
     401            localFile = os.path.join(basePth, fpth) 
     402            localPath = os.path.split(localFile)[0] 
     403            if mtype == "D" and os.path.exists(localFile): 
     404                if os.path.isdir(localFile): 
     405                    shutil.rmtree(localFile) 
     406                else: 
     407                    os.remove(localFile) 
     408            else: 
     409                if not os.path.isdir(localPath): 
     410                    os.mkdirs(localPath) 
     411                try: 
     412                    urllib.urlretrieve(url % fpth, localFile) 
     413                except StandardError, e: 
     414                    dabo.errorLog.write(_("Cannot update file: '%s'. Error: %s") % (fpth, e)) 
     415         
     416 
     417    def _setAutoUpdate(self, auto, interval=None): 
     418        """Sets the auto-update settings for the entire framework. If set to True, the  
     419        interval is expected to be in minutes between checks. 
     420        """ 
     421        prf = self._frameworkPrefs 
     422        prf.setValue("auto_update", auto) 
     423        if auto: 
     424            if interval is None: 
     425                # They want it checked every time 
     426                interval = 0 
     427            prf.setValue("update_interval", interval) 
     428         
     429         
    339430    def getUserSettingKeys(self, spec): 
    340431        """Return a list of all keys underneath <spec> in the user settings table. 
  • trunk/dabo/ui/uiwx/uiApp.py

    r3200 r3233  
    165165        del self.callback 
    166166        self.Bind(wx.EVT_KEY_DOWN, self._onKeyPress) 
    167         return True 
    168      
     167        return self.__checkForUpdates() 
     168 
     169 
     170    def __checkForUpdates(self): 
     171        answer = False 
     172        if self.dApp._checkForUpdates(): 
     173            answer = dabo.ui.areYouSure(_("Framework updates are available. Do you want to update now?"), 
     174                    title=_("Dabo Updates"), cancelButton=False) 
     175            if answer: 
     176                self.dApp._updateFramework() 
     177                dabo.ui.info(_("The app will now exit. Please re-run the application.")) 
     178        return not answer 
     179         
    169180     
    170181    def _onKeyPress(self, evt):