dabo Commit
Revision 3233
Date: 2007-07-09 18:04:35 -0700 (Mon, 09 Jul 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3233

Changed:
U   trunk/dabo/dApp.py
U   trunk/dabo/ui/uiwx/uiApp.py

Log:
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.


Diff:
Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py  2007-07-10 00:39:39 UTC (rev 3232)
+++ trunk/dabo/dApp.py  2007-07-10 01:04:35 UTC (rev 3233)
@@ -7,7 +7,12 @@
 import tempfile
 import ConfigParser
 import inspect
-import dabo, dabo.ui, dabo.db
+import datetime
+import urllib
+import shutil
+import dabo
+import dabo.ui
+import dabo.db
 from dabo.lib.connParser import importConnections
 import dSecurityManager
 from dLocalize import _
@@ -154,6 +159,7 @@
                self._uiAlreadySet = False
                dabo.dAppRef = self
                self._beforeInit()
+               
                # If we are displaying a splash screen, these attributes control
                # its appearance. Extract them before the super call.
                self.showSplashScreen = self._extractKey(kwargs, 
"showSplashScreen", False)
@@ -176,6 +182,8 @@
                # Create the temp file handlers.
                self._tempFileHolder = TempFileHolder()
                self.getTempFile = self._tempFileHolder.getTempFile
+               # Create the framework-level preference manager
+               self._frameworkPrefs = dabo.dPref(key="dabo_framework")
 
                # List of form classes to open on App Startup
                self.formsToOpen = []  
@@ -336,6 +344,89 @@
                self._appInfo[item] = value
 
 
+       def _currentUpdateVersion(self):
+               localVers = dabo.version["revision"]
+               try:
+                       localVers = localVers.split(":")[1]
+               except:
+                       # Not a mixed version
+                       pass
+               ret = int("".join([ch for ch in localVers if ch.isdigit()]))
+               return ret
+
+               
+       def _checkForUpdates(self):
+               ret = False
+               prf = self._frameworkPrefs
+               val = prf.getValue
+               now = datetime.datetime.now()
+               autoUpdate = val("auto_update")
+               if autoUpdate:
+                       checkInterval = val("update_interval")
+                       if checkInterval is None:
+                               # Default to one day
+                               checkInterval = 24 * 60
+                       mins = datetime.timedelta(minutes=checkInterval)
+                       lastCheck = val("last_check")
+                       if lastCheck is None:
+                               lastCheck = datetime.datetime(1900, 1, 1)
+                       if now > (lastCheck + mins):
+                               # See if there is a later version
+                               url = 
"http://dabodev.com/frameworkVersions/latest";
+                               try:
+                                       vers = int(urllib.urlopen(url).read())
+                               except:
+                                       vers = -1
+                               localVers = self._currentUpdateVersion()
+                               ret = localVers < vers
+                               
+                               print "LOCAL V", localVers
+                               print "WEB VER", vers
+               prf.setValue("last_check", now)
+               return ret
+
+
+       def _updateFramework(self):
+               """Get any changed files from the dabodev.com server, and 
replace the local copies with them."""
+               url = "http://dabodev.com/frameworkVersions/changedFiles/%s"; % 
self._currentUpdateVersion()
+               try:
+                       resp = urllib.urlopen(url)
+               except:
+                       # No internet access, or Dabo site is down.
+                       return
+               flist = eval(resp.read())
+               basePth = os.path.split(dabo.__file__)[0]
+               url = "http://dabodev.com/versions/dabo/%s";
+               for mtype, fpth in flist:
+                       localFile = os.path.join(basePth, fpth)
+                       localPath = os.path.split(localFile)[0]
+                       if mtype == "D" and os.path.exists(localFile):
+                               if os.path.isdir(localFile):
+                                       shutil.rmtree(localFile)
+                               else:
+                                       os.remove(localFile)
+                       else:
+                               if not os.path.isdir(localPath):
+                                       os.mkdirs(localPath)
+                               try:
+                                       urllib.urlretrieve(url % fpth, 
localFile)
+                               except StandardError, e:
+                                       dabo.errorLog.write(_("Cannot update 
file: '%s'. Error: %s") % (fpth, e))
+               
+
+       def _setAutoUpdate(self, auto, interval=None):
+               """Sets the auto-update settings for the entire framework. If 
set to True, the 
+               interval is expected to be in minutes between checks.
+               """
+               prf = self._frameworkPrefs
+               prf.setValue("auto_update", auto)
+               if auto:
+                       if interval is None:
+                               # They want it checked every time
+                               interval = 0
+                       prf.setValue("update_interval", interval)
+               
+               
        def getUserSettingKeys(self, spec):
                """Return a list of all keys underneath <spec> in the user 
settings table.
                

Modified: trunk/dabo/ui/uiwx/uiApp.py
===================================================================
--- trunk/dabo/ui/uiwx/uiApp.py 2007-07-10 00:39:39 UTC (rev 3232)
+++ trunk/dabo/ui/uiwx/uiApp.py 2007-07-10 01:04:35 UTC (rev 3233)
@@ -164,9 +164,20 @@
                        wx.CallAfter(self.callback)
                del self.callback
                self.Bind(wx.EVT_KEY_DOWN, self._onKeyPress)
-               return True
+               return self.__checkForUpdates()
+
+
+       def __checkForUpdates(self):
+               answer = False
+               if self.dApp._checkForUpdates():
+                       answer = dabo.ui.areYouSure(_("Framework updates are 
available. Do you want to update now?"),
+                                       title=_("Dabo Updates"), 
cancelButton=False)
+                       if answer:
+                               self.dApp._updateFramework()
+                               dabo.ui.info(_("The app will now exit. Please 
re-run the application."))
+               return not answer
+               
        
-       
        def _onKeyPress(self, evt):
                ## Zoom In / Out / Normal:
                alt = evt.AltDown()




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]

Reply via email to