Changeset 3261
- Timestamp:
- 07/18/07 17:13:33 (1 year ago)
- Files:
-
- trunk/dabo/dApp.py (modified) (5 diffs)
- trunk/dabo/dLocalize.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/dApp.py
r3237 r3261 355 355 return ret 356 356 357 358 def _checkForUpdates(self): 357 358 def checkForUpdates(self, evt=None): 359 """Public interface to the web updates mechanism.""" 360 return self.uiApp.checkForUpdates(force=True) 361 362 363 def _checkForUpdates(self, force=False): 359 364 ret = False 360 365 prf = self._frameworkPrefs 361 366 val = prf.getValue 367 runCheck = False 362 368 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 369 if not force: 370 webUpdate = val("web_update") 371 if webUpdate: 372 checkInterval = val("update_interval") 373 if checkInterval is None: 374 # Default to one day 375 checkInterval = 24 * 60 376 mins = datetime.timedelta(minutes=checkInterval) 377 lastCheck = val("last_check") 378 if lastCheck is None: 379 lastCheck = datetime.datetime(1900, 1, 1) 380 runCheck = (now > (lastCheck + mins)) 381 if runCheck: 382 # See if there is a later version 383 url = "http://dabodev.com/frameworkVersions/latest" 384 try: 385 vers = int(urllib.urlopen(url).read()) 386 except: 387 vers = -1 388 localVers = self._currentUpdateVersion() 389 ret = localVers < vers 385 390 prf.setValue("last_check", now) 386 391 return ret … … 413 418 except StandardError, e: 414 419 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 420 urllib.urlcleanup() 421 422 423 def _setWebUpdate(self, auto, interval=None): 424 """Sets the web update settings for the entire framework. If set to True, the 419 425 interval is expected to be in minutes between checks. 420 426 """ 421 427 prf = self._frameworkPrefs 422 prf.setValue(" auto_update", auto)428 prf.setValue("web_update", auto) 423 429 if auto: 424 430 if interval is None: … … 426 432 interval = 0 427 433 prf.setValue("update_interval", interval) 434 435 436 def getWebUpdateInfo(self): 437 """Returns a 2-tuple that reflects the current settings for web updates. 438 The first position is a boolean that reflects whether auto-checking is turned 439 on; the second is the update frequency in minutes. 440 """ 441 return (self._frameworkPrefs.web_update, self._frameworkPrefs.update_interval) 428 442 429 443 … … 682 696 self.dbConnectionDefs[k] = ci 683 697 self.dbConnectionNameToFiles[k] = connFile 684 698 699 700 def setLanguage(self, lang, charset=None): 701 """Allows you to change the language used for localization. If the language 702 passed is not one for which there is a translation file, an IOError exception 703 will be raised. You may optionally pass a character set to use. 704 """ 705 dabo.dLocalize.setLanguage(lang, charset) 706 707 685 708 def showCommandWindow(self, context=None): 686 709 """Shows a command window with a full Python interpreter. … … 764 787 765 788 789 def onWebUpdatePrefs(self, evt): 790 self.uiApp.onWebUpdatePrefs(evt) 791 792 766 793 def onHelpAbout(self, evt): 767 794 about = self.AboutFormClass trunk/dabo/dLocalize.py
r3054 r3261 1 1 # -*- coding: utf-8 -*- 2 import gettext, os 2 import gettext 3 import locale 4 import os 5 import re 3 6 import dabo 4 from dabo.__version__ import version5 7 6 __domain = "dabo"7 __localedir = "locale"8 8 9 def __translation(domain, version=None, dirs=[]):10 """ Try to find """11 dirs = [os.path.join(d, __localedir) for d in dirs]12 dirs.append(None) # tell to search in system dirs also13 domains = [domain]14 version and domains.insert(0, "-".join([domain, version]))9 def getLanguages(): 10 # Probably need to add more 11 langs = gettext.find("dabo", daboLocaleDir, languages=_trans.keys(), all=True) 12 langPat = re.compile(".+/locale/([a-z]{2})/LC_MESSAGES.+") 13 ret = [langPat.sub(r"\1", lang) for lang in langs] 14 return ret 15 15 16 for domain in domains: 17 for dir in dirs: 16 17 def setLanguage(lang=None, charset=None): 18 global defLang, defCharset, _trans 19 if charset is None: 20 charset = defCharset 21 if lang is None: 22 lang = defLang 23 else: 24 lang = lang.lower() 25 # It might be the full name instead of the two-letter abbreviation 26 if lang not in getLanguages(): 18 27 try: 19 return gettext.translation(domain, localedir=dir) 20 except IOError: 28 lang = {"english": "en", 29 "spanish": "es", "espanol": "es", "español": "es", 30 "french": "fr", "francais": "fr", "français": "fr", 31 "portuguese": "pt", "portuguése": "pt", 32 "russian": "ru"}[lang] 33 except KeyError: 21 34 pass 22 return None 35 if not lang in getLanguages(): 36 raise IOError, "Invalid language '%s'" % lang 37 38 if _trans.get(lang) is None: 39 _trans[lang] = gettext.translation("dabo", daboLocaleDir, 40 languages=[lang], codeset=charset) 41 defLang = lang 42 43 44 def _(s): 45 global defLang, _trans 46 return _trans[defLang].gettext(s) 47 23 48 24 # set default Dabo translation. File is searched under cwd()/locale/$LANG/LC_MESSAGES25 # and in system default places.26 __trans = __translation(__domain, version["version"], ["."]) or gettext.NullTranslations()27 28 __app_initialized = False29 30 def __add_apptrans():31 global __trans32 try:33 app = dabo.dAppRef34 except AttributeError:35 app = None36 if app:37 appname, appver = [app.getAppInfo(k) for k in ("appName", "appVersion")]38 if appname:39 appname = appname.lower()40 apptrans = __translation(appname, appver, [app.HomeDirectory])41 if apptrans:42 apptrans.add_fallback(__trans)43 __trans = apptrans44 __app_initialized = True45 46 def _(s):47 """ Default localization service. Translation is based on default48 gettext interface. Translation is returned in Unicode.49 50 Messages are searched first in application translations and in Dabo ones after.51 52 Translation files are searched in53 application.HomeDirectory/locale and system default locale54 directories accoding to gettext conventions(files must be55 placed under ${LANG}/LC_MESSAGES subdirectory. File basename must56 be appName or appName-appVersion in lower case.57 58 Default appName is "dabo".59 """60 # application initialized, try to install messages61 if not __app_initialized:62 __add_apptrans()63 64 app = dabo.dAppRef65 if isinstance(s, str) and app is not None:66 ss = app.str2Unicode(s)67 else:68 ss = s69 70 return __trans.ugettext(ss)71 72 73 49 def n_(s): 74 50 """ Use it if you want to tell translation service about string 75 51 but don't want to translate it inplace. 76 52 """ 77 return s 53 global defLang 54 return _trans[defLang].gettext(s) 78 55 56 57 daboLocaleDir = os.path.join(os.path.split(dabo.__file__)[0], "locale") 58 _trans = {"en": None, "fr": None, "es": None, "pt": None, "ru": None} 59 defLang, defCharset = locale.getlocale() 60 if defLang is None: 61 defLang = "en" 62 else: 63 defLang = defLang[:2] 64 if defCharset is None: 65 defCharset = "ISO8859-1" 66 setLanguage()
