def UpdateTextCache(self, messagePerLanguage, metaDataPerLanguage, labelsDict): """ Update the internal text and label dictionaries with the passed data. The cacheData consists of three dictionaries (as returned by localizationPickleExporter): messagePerLanguage, metaDataPerLanguage, labelsDict """ for language in messagePerLanguage: LogInfo( 'Preparing to update internal text and label cache. The sizes of new data dictionaries are: ', len(messagePerLanguage.get(language, {})), ', ', len(metaDataPerLanguage.get(language, {}))) if eveLocalization.HasLanguage(language): newData = {} for messageID, text in messagePerLanguage.get(language, {}).iteritems(): try: metaData = None ignore, metaData, ignore = eveLocalization.GetMessageDataByID( messageID, language) except KeyError: sys.exc_clear() try: newData[messageID] = (text, metaData, _Tokenize(text)) except: logmodule.LogException() continue try: eveLocalization.LoadMessageData(language, newData) except: logmodule.LogException() continue for language in metaDataPerLanguage: if eveLocalization.HasLanguage(language): newData = {} for messageID, metaData in metaDataPerLanguage.get( language, {}).iteritems(): try: text, ignore, tokens = eveLocalization.GetMessageDataByID( messageID, language) newData[messageID] = (text, metaData, tokens) except KeyError: sys.exc_clear() try: eveLocalization.LoadMessageData(language, newData) except: logmodule.LogException() continue LogInfo('Updating label cache. New data size is ', len(labelsDict)) for label, messageID in labelsDict.iteritems(): self.languageLabels[label.encode('ascii')] = messageID
def CallWrapper(*args, **kwds): current = stackless.getcurrent() current.startTime = blue.os.GetWallclockTimeNow() oldtimer = PushTimer(current.context) exc = None try: try: return method(*args, **kwds) except TaskletExit as e: pass except SystemExit as e: import logmodule as log log.general.Log('system %s exiting with %r' % (stackless.getcurrent(), e), log.LGINFO) except Exception: import logmodule as log log.LogException('Unhandled exception in %r' % stackless.getcurrent()) return except: traceback.print_exc() if exc: traceback.print_exception(exc[0], exc[1], exc[2]) finally: exc = None PopTimer(oldtimer) current.endTime = blue.os.GetWallclockTimeNow()
def GetByMessageID(self, messageID, languageID=None, **kwargs): """ Retrieves and renders a label from the Language data. parameters: messageID - unique & central ID of the label/string languageID - character language code. Exp: 'en-us' for English Note: if no languageID is passed a default one will be picked. **kwargs - variable definitions for dynamic text returns: a [no message:%s] string if no text was found, None if the messageID was None, or the text if it was found. """ if messageID is None: return '' languageID = util.StandardizedLanguageIDOrDefault(languageID) if session and 'player' not in kwargs: kwargs['player'] = session.charid try: textString = self._GetByMessageID(messageID, languageID, **kwargs) return PrepareLocalizationSafeString(textString, messageID=messageID) except KeyError: return u'[no messageID: %s]' % messageID except: logmodule.LogException() try: return self._GetRawByMessageID(messageID) except: return u'[no messageID: %s]' % messageID
def LockCheck(): while 1: each = None blue.pyos.synchro.SleepWallclock(60660) now = blue.os.GetWallclockTime() try: for each in locks.GetLocks(): if each.LockedAt() and each.WaitingTasklets(): problem = now - each.LockedAt() if problem >= 1 * MIN: break else: problem = 0 if not problem: continue with log.general.open(log.LGERR) as s: print >> s, 'Locks have been held for a long time (%ss). Locking conflict log' % (problem / SEC) foundCycles = locks.LockCycleReport(out=s, timeLimit=60) if not foundCycles: print >> s, 'logical analysis found no cycles.' if not foundCycles: print >> s, 'Full dump of locks with waiting tasklets:' locks.OldLockReport(None, out=s) print >> s, 'End of locking conflict log' except StandardError: log.LogException() sys.exc_clear()
def __exit__(self, exc, val, tb): try: self.release() except Exception: if exc: log.LogException('supressed error in ContextMixin.__exit__') else: raise
def RunAll(): stackless.getcurrent().block_trap = True for proc in exitprocs: try: proc() except Exception: import logmodule as log log.LogException('exitproc ' + repr(proc), toAlertSvc=False) sys.exc_clear()
def Terminate(reason = ''): import logmodule as log log.general.Log('bluepy.Terminate - Reason: %s' % reason, log.LGNOTICE) try: if 'sm' in __builtins__: sm.ChainEvent('ProcessShutdown') except: log.LogException() atexit._run_exitfuncs() blue.os.Terminate(0)
def Loop(): while True: try: eventQueue.pump() t = eventQueue.next_delay() if t is not None: blue.pyos.NextScheduledEvent(int(t * 1000)) except Exception: log.LogException() sys.exc_clear() blue.pyos.synchro.Yield()
def RunTestScript(): try: for each in blueArgs: if each.startswith('/test_script'): path = each.split('=')[1] execfile(path, globals()) except Exception as e: import traceback traceback.print_exc() logmodule.LogException() sys.exc_clear()
def _ReadLanguageLocalizationData(self, aLangCode, unPickledObject, dataType): try: LogInfo('Loading all message data for language ', aLangCode) eveLocalization.LoadMessageData(*unPickledObject) except: logmodule.LogException() for x, y in unPickledObject[1].iteritems(): if y[2] is not None and not isinstance(y[2], dict): logmodule.LogError('%s: %s' % (x, repr(y))) return True
def Terminate(reason=''): """Calls some cleanup functions and then blue.os.Terminate. Calls sm.ChainEvent('ProcessShutdown') and then the atexit exit handlers. """ import logmodule as log log.general.Log('bluepy.Terminate - Reason: %s' % reason, log.LGNOTICE) try: if 'sm' in __builtins__: sm.ChainEvent('ProcessShutdown') except: log.LogException() atexit._run_exitfuncs() blue.os.Terminate(0)
def GetByMessageID(self, messageID, languageID=None, **kwargs): if messageID is None: return '' languageID = util.StandardizedLanguageIDOrDefault(languageID) if session and 'player' not in kwargs: kwargs['player'] = session.charid try: textString = self._GetByMessageID(messageID, languageID, **kwargs) return PrepareLocalizationSafeString(textString, messageID=messageID) except KeyError: return u'[no messageID: %s]' % messageID except: logmodule.LogException() try: return self._GetRawByMessageID(messageID) except: return u'[no messageID: %s]' % messageID
def _ExecScript(path, tool): try: rf = blue.classes.CreateInstance('blue.ResFile') rf.OpenAlways(path) try: data = rf.Read() finally: rf.Close() data = data.replace('\r\n', '\n') codeObject = compile(data, path, 'exec') eval(codeObject, globals()) runFunc = globals().get('run', None) if runFunc is not None: runFunc() except Exception as e: traceback.print_exc() logmodule.LogException() _LogAndTerm(str(e), tool)
def CallWrapper(*args, **kwds): current = stackless.getcurrent() current.startTime = blue.os.GetWallclockTimeNow() oldtimer = PushTimer(current.context) exc = None try: try: return method(*args, **kwds) except TaskletExit as e: import logmodule as log t = stackless.getcurrent() log.general.Log( 'tasklet (%s) %s exiting with %r' % (t.tasklet_id, t, e), log.LGINFO) except SystemExit as e: import logmodule as log log.general.Log( 'system %s exiting with %r' % (stackless.getcurrent(), e), log.LGINFO) except Exception: import logmodule as log print >> debugFile, 'Unhandled exception in tasklet', repr( stackless.getcurrent()) traceback.print_exc(file=debugFile) exc = sys.exc_info() log.LogException('Unhandled exception in %r' % stackless.getcurrent()) return except: traceback.print_exc() traceback.print_exc(file=debugFile) if exc: traceback.print_exception(exc[0], exc[1], exc[2]) traceback.print_exception(exc[0], exc[1], exc[2], file=debugFile) finally: exc = None PopTimer(oldtimer) current.endTime = blue.os.GetWallclockTimeNow()
def _ReadLanguageLocalizationData(self, aLangCode, unPickledObject, dataType): """ Worker functions to read Language specific text data from an object. parameters: aLangCode - language id unPickledObject - data structure, usually read from a pickle file, containing language specific data. For example: translated texts and metadata. return True if success, False, otherwise NOTE: this function is being unit tested """ try: LogInfo('Loading all message data for language ', aLangCode) eveLocalization.LoadMessageData(*unPickledObject) except: logmodule.LogException() for x, y in unPickledObject[1].iteritems(): if y[2] is not None and not isinstance(y[2], dict): logmodule.LogError('%s: %s' % (x, repr(y))) return True