| | 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 | |
|---|