Exemple #1
0
 def shortcutAnimation(self, animation):
     """directly set the end value of the animation"""
     if animation.debug:
         logDebug('shortcut {}: UTile {}: clear queuedAnimations'.format(animation, self.name()))
     setattr(self, animation.pName(), animation.endValue())
     self.queuedAnimations = []
     self.setDrawingOrder()
Exemple #2
0
 def start(self, dummyResults='DIREKT'):
     """start the animation, returning its deferred"""
     if not isAlive(self):
         return fail()
     assert self.state() != QAbstractAnimation.Running
     for animation in self.animations:
         graphicsObject = animation.targetObject()
         if not isAlive(animation) or not isAlive(graphicsObject):
             return fail()
         graphicsObject.setActiveAnimation(animation)
         self.addAnimation(animation)
         propName = animation.pName()
         animation.setStartValue(graphicsObject.getValue(propName))
         if propName == 'rotation':
             # change direction if that makes the difference smaller
             endValue = animation.endValue()
             currValue = graphicsObject.rotation
             if endValue - currValue > 180:
                 animation.setStartValue(currValue + 360)
             if currValue - endValue > 180:
                 animation.setStartValue(currValue - 360)
     for animation in self.animations:
         animation.targetObject().setDrawingOrder()
     self.finished.connect(self.allFinished)
     scene = Internal.scene
     scene.focusRect.hide()
     QParallelAnimationGroup.start(
         self,
         QAbstractAnimation.DeleteWhenStopped)
     if self.debug:
         logDebug('%s started with speed %d (%s)' % (
             self, Internal.Preferences.animationSpeed,
             ','.join('A%s' % id4(x) for x in self.animations)))
     return succeed(None).addErrback(logException)
Exemple #3
0
 def setupAnimations(self):
     """move the item to its new place. This puts new Animation
     objects into the queue to be animated by calling animate()"""
     for pName, newValue in self.moveDict().items():
         if self.scene() != Internal.scene:
             # not part of the playing scene, like tiles in tilesetselector
             setattr(self, pName, newValue)
             continue
         animation = self.queuedAnimation(pName)
         if animation:
             curValue = animation.endValue()
             if curValue != newValue:
                 # change a queued animation
                 if self.name() in Debug.animation:
                     logDebug('setEndValue for {}: {}: {}->{}'.format(
                         animation, pName, animation.formatValue(curValue), animation.formatValue(newValue)))
                 animation.setEndValue(newValue)
         else:
             animation = self.activeAnimation.get(pName, None)
             if isAlive(animation):
                 curValue = animation.endValue()
             else:
                 curValue = self.getValue(pName)
             if pName != 'scale' or abs(curValue - newValue) > 0.00001:
                 # ignore rounding differences for scale
                 if curValue != newValue:
                     Animation(self, pName, newValue)
Exemple #4
0
 def cancelAll():
     """cancel all animations"""
     if Debug.quit:
         logDebug('Cancelling all animations')
     for group in ParallelAnimationGroup.running:
         if isAlive(group):
             group.clear()
Exemple #5
0
 def __init__(self, statement, args=None,
              silent=False, mayFail=False, failSilent=False):
     """we take one sql statement.
     Do prepared queries by passing the parameters in args.
     If args is a list of lists, execute the prepared query for every sublist.
     Use Internal.db for db access.
     Else if the default dbHandle (Internal.db) is defined, use it."""
     # pylint: disable=too-many-branches
     silent |= not Debug.sql
     self.msg = None
     self.records = []
     self.statement = statement
     self.args = args
     if Internal.db:
         self.cursor = Internal.db.cursor(
             DBCursor)  # pylint: disable=no-member
         self.cursor.execute(
             statement,
             args,
             silent=silent,
             mayFail=mayFail,
             failSilent=failSilent)
         self.failure = self.cursor.failure
         self.records = list(self.cursor.fetchall())
         if not Internal.db.inTransaction:
             Internal.db.commit()
     else:
         # may happen at shutdown
         self.cursor = None
         self.failure = None
         self.records = list()
     if self.records and Debug.sql:
         logDebug('result set:{}'.format(self.records))
Exemple #6
0
 def createRule(self, name, definition='', **kwargs):
     """shortcut for simpler definition of predefined rulesets"""
     name = unicodeString(name)
     definition = unicodeString(definition)
     defParts = definition.split(u'||')
     rule = None
     description = kwargs.get('description', '')
     for cls in [IntRule, BoolRule, StrRule]:
         if defParts[0].startswith(cls.prefix):
             rule = cls(
                 name,
                 definition,
                 description=description,
                 parameter=kwargs['parameter'])
             break
     if not rule:
         if 'parameter' in kwargs:
             del kwargs['parameter']
         ruleType = type(str(ruleKey(name)) + 'Rule', (Rule, ), {})
         rule = ruleType(name, definition, **kwargs)
         if defParts[0] == 'FCallingHand':
             parts1 = defParts[1].split('=')
             assert parts1[0] == 'Ohand', definition
             ruleClassName = parts1[1] + 'Rule'
             if ruleClassName not in RuleBase.ruleClasses:
                 logDebug(
                     u'we want %s, definition:%s' %
                     (ruleClassName, definition))
                 logDebug(u'we have %s' % RuleBase.ruleClasses.keys())
             ruleType.limitHand = RuleBase.ruleClasses[ruleClassName]
     self.add(rule)
Exemple #7
0
 def remote_newTables(self, tables):
     """update table list"""
     newTables = list(ClientTable(self, *x) for x in tables)
     self.tables.extend(newTables)
     if Debug.table:
         _ = u', '.join(unicode(ClientTable(self, *x)) for x in tables)
         logDebug(u'%s got new tables:%s' % (self.name, _))
 def __init__(self, paginaId, moduleConfig):
     self.teamId = []
     self.sqStatus = ""
     self.sqKpis = ""
     log.logDebug('Processing Sonarqube module for ' + str(paginaId) +
                  ' con config ' + str(moduleConfig))
     self.doRequest(moduleConfig)
Exemple #9
0
 def clientAction(self, dummyClient, move):
     """server sent us voice sounds about somebody else"""
     move.player.voice = Voice(move.md5sum, move.source)
     if Debug.sound:
         logDebug(
             '%s gets voice data %s from server, language=%s' %
             (move.player, move.player.voice, move.player.voice.language()))
Exemple #10
0
 def availableVoices():
     """a list of all voice directories"""
     if not Voice.__availableVoices:
         result = []
         directories = QStandardPaths.locateAll(
             QStandardPaths.AppDataLocation, 'voices',
             QStandardPaths.LocateDirectory)
         directories.insert(0, os.path.join('share', 'kajongg', 'voices'))
         for parentDirectory in directories:
             for (dirpath, _, _) in os.walk(parentDirectory,
                                            followlinks=True):
                 if os.path.exists(os.path.join(dirpath, 's1.ogg')):
                     result.append(Voice(dirpath))
         group = Internal.kajonggrc.group('Locale')
         prefLanguages = uniqueList(':'.join(
             ['local', str(group.readEntry('Language')),
              'en_US']).split(':'))
         prefLanguages = dict(
             (x[1], x[0]) for x in enumerate(prefLanguages))
         result = sorted(
             result, key=lambda x: prefLanguages.get(x.language(), 9999))
         if Debug.sound:
             logDebug('found voices:%s' % [str(x) for x in result])
         Voice.__availableVoices = result
     return Voice.__availableVoices
Exemple #11
0
    def debug(self, msg, btIndent=None, prevHandId=False):
        """
        Log a debug message.

        @param msg: The message.
        @type msg: A string.
        @param btIndent: If given, message is indented by
        depth(backtrace)-btIndent
        @type btIndent: C{int}
        @param prevHandId: If True, do not use current handId but previous
        @type prevHandId: C{bool}
        """
        if self.belongsToRobotPlayer():
            prefix = u'R'
        elif self.belongsToHumanPlayer():
            prefix = u'C'
        elif self.belongsToGameServer():
            prefix = u'S'
        else:
            logDebug(msg, btIndent=btIndent)
            return
        handId = self._prevHandId if prevHandId else self.handId
        handId = unicodeString(handId.prompt(withMoveCount=True))
        logDebug(
            u'%s%s: %s' % (prefix, handId, unicodeString(msg)),
            withGamePrefix=False,
            btIndent=btIndent)
Exemple #12
0
 def clientAction(self, client, move):
     """violation: player may not say mah jongg"""
     move.player.popupMsg(self)
     move.player.mayWin = False
     if Debug.originalCall:
         logDebug('%s: cleared mayWin' % move.player)
     return client.ask(move, [Message.OK])
Exemple #13
0
 def remote_newTables(self, tables):
     """update table list"""
     newTables = list(ClientTable(self, *x) for x in tables)
     self.tables.extend(newTables)
     if Debug.table:
         _ = ', '.join(str(ClientTable(self, *x)) for x in tables)
         logDebug('%s got new tables:%s' % (self.name, _))
Exemple #14
0
 def __startLocalServer(self):
     """start a local server"""
     try:
         args = self.__findServerProgram()
         if self.useSocket or os.name == 'nt':  # for nt --socket tells the server to bind to 127.0.0.1
             args.append('--socket=%s' % socketName())
             if removeIfExists(socketName()):
                 logInfo(
                     i18n('removed stale socket <filename>%1</filename>',
                          socketName()))
         if not self.useSocket:
             args.append('--port=%d' % self.port)
         if self.isLocalGame:
             args.append('--db={}'.format(
                 os.path.normpath(os.path.join(appdataDir(), 'local3.db'))))
         if Debug.argString:
             args.append('--debug=%s' % Debug.argString)
         if os.name == 'nt':
             startupinfo = subprocess.STARTUPINFO()
             startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
         else:
             startupinfo = None
         process = subprocess.Popen(
             args, startupinfo=startupinfo)  # , shell=os.name == 'nt')
         if Debug.connections:
             logDebug(
                 i18n(
                     'started the local kajongg server: pid=<numid>%1</numid> %2',
                     process.pid, ' '.join(args)))
     except OSError as exc:
         exc.filename = ' '.join(args)
         logException(exc)
Exemple #15
0
 def __initTableList(self, dummy):
     """first load of the list. Process options like --demo, --table, --join"""
     self.showTableList()
     if SingleshotOptions.table:
         Internal.autoPlay = False
         self.__requestNewTableFromServer(SingleshotOptions.table).addCallback(
             self.__showTables).addErrback(self.tableError)
         if Debug.table:
             logDebug(
                 '%s: --table lets us open an new table %d' %
                 (self.name, SingleshotOptions.table))
         SingleshotOptions.table = False
     elif SingleshotOptions.join:
         Internal.autoPlay = False
         self.callServer('joinTable', SingleshotOptions.join).addCallback(
             self.__showTables).addErrback(self.tableError)
         if Debug.table:
             logDebug(
                 '%s: --join lets us join table %s' %
                 (self.name, self._tableById(SingleshotOptions.join)))
         SingleshotOptions.join = False
     elif not self.game and (Internal.autoPlay or (not self.tables and self.hasLocalServer())):
         self.__requestNewTableFromServer().addCallback(
             self.__newLocalTable).addErrback(self.tableError)
     else:
         self.__showTables()
Exemple #16
0
 def __init__(self, statement, args=None,
              silent=False, mayFail=False, failSilent=False):
     """we take one sql statement.
     Do prepared queries by passing the parameters in args.
     If args is a list of lists, execute the prepared query for every sublist.
     Use Internal.db for db access.
     Else if the default dbHandle (Internal.db) is defined, use it."""
     # pylint: disable=too-many-branches
     silent |= not Debug.sql
     self.msg = None
     self.records = []
     self.statement = statement
     self.args = args
     if Internal.db:
         self.cursor = Internal.db.cursor(
             DBCursor)  # pylint: disable=no-member
         self.cursor.execute(
             statement,
             args,
             silent=silent,
             mayFail=mayFail,
             failSilent=failSilent)
         self.failure = self.cursor.failure
         self.records = list(self.cursor.fetchall())
         if not Internal.db.inTransaction:
             Internal.db.commit()
     else:
         # may happen at shutdown
         self.cursor = None
         self.failure = None
         self.records = list()
     if self.records and Debug.sql:
         logDebug(u'result set:{}'.format(self.records))
Exemple #17
0
 def removeTable(self, table, reason, message=None, *args):
     """remove a table"""
     assert reason in ('silent', 'tableRemoved', 'gameOver', 'abort')
     # HumanClient implements methods remote_tableRemoved etc.
     message = message or ''
     if Debug.connections or reason == 'abort':
         logDebug('%s%s ' %
                  (('%s:' % table.game.seed) if table.game else '',
                   i18n(message, *args)),
                  withGamePrefix=None)
     if table.tableid in self.tables:
         del self.tables[table.tableid]
         if reason == 'silent':
             tellUsers = []
         else:
             tellUsers = table.users if table.running else self.srvUsers
         for user in tellUsers:
             # this may in turn call removeTable again!
             self.callRemote(user, reason, table.tableid, message, *args)
         for user in table.users:
             table.delUser(user)
         if Debug.table:
             logDebug('removing table %d: %s %s' %
                      (table.tableid, i18n(message, *args), reason))
     if table.game:
         table.game.close()
Exemple #18
0
 def requestAvatarId(self, cred):  # pylint: disable=no-self-use
     """get user id from database"""
     cred.username = cred.username.decode('utf-8')
     args = cred.username.split(SERVERMARK)
     if len(args) > 1:
         if args[0] == 'adduser':
             cred.username = args[1]
             password = args[2]
             query = Query(
                 'insert or ignore into player(name,password) values(?,?)',
                 (cred.username, password))
         elif args[1] == 'deluser':
             pass
     query = Query('select id, password from player where name=?',
                   (cred.username, ))
     if not len(query.records):
         template = 'Wrong username: %1'
         if Debug.connections:
             logDebug(i18n(template, cred.username))
         return fail(
             credError.UnauthorizedLogin(srvMessage(template,
                                                    cred.username)))
     userid, password = query.records[0]
     defer1 = maybeDeferred(cred.checkPassword, password.encode('utf-8'))
     defer1.addCallback(DBPasswordChecker._checkedPassword, userid)
     return defer1
Exemple #19
0
def dictToStringManual(inputDict):
    salida = "'{"
    log.logDebug('Found ' + str(len(inputDict)) + ' items in dictionary')
    subSalida1 = ""
    for key, value in sorted(inputDict.items()):
        if (len(subSalida1) > 0):
            subSalida1 = subSalida1 + ','
        subSalida1 = subSalida1 + '"' + key + '": '
        if str(value) == "{}":
            subSalida1 = subSalida1 + '{}'
            continue
        subSalida1 = subSalida1 + '{'
        valueDict = ast.literal_eval(str(value))
        subSalida2 = ''
        log.logDebug('Found ' + str(len(valueDict)) +
                     ' items in subDictionary')
        for subKey, subValue in sorted(valueDict.items()):
            if (len(subSalida2) > 0):
                subSalida2 = subSalida2 + ','
            subSalida2 = subSalida2 + '"' + subKey + '": '
            if str(subValue) == "":
                subSalida2 = subSalida2 + '{""}'
                continue
            subSalida2 = subSalida2 + str(subValue)
        subSalida1 = subSalida1 + subSalida2 + '}'
    salida = salida + subSalida1
    return salida + "}'"
Exemple #20
0
def extractValue(pagina, paramName):
    paramString = pagina.find(paramName)
    if len(paramString) == 0:
        log.logError('Bad xml syntax: ' + paramName + ' missing')
        return ""
    log.logDebug('Page parameter ' + str(paramName) + ' = ' + str(paramString))
    return paramString.get_text()
Exemple #21
0
 def sendVoiceIds(self):
     """tell each player what voice ids the others have. By now the client has a Game instance!"""
     humanPlayers = [
         x for x in self.game.players if isinstance(self.remotes[x], User)
     ]
     if len(humanPlayers) < 2 or not any(self.remotes[x].voiceId
                                         for x in humanPlayers):
         # no need to pass around voice data
         self.assignVoices()
         return
     block = DeferredBlock(self)
     for player in humanPlayers:
         remote = self.remotes[player]
         if remote.voiceId:
             # send it to other human players:
             others = [x for x in humanPlayers if x != player]
             if Debug.sound:
                 logDebug(
                     'telling other human players that %s has voiceId %s' %
                     (player.name, remote.voiceId))
             block.tell(player,
                        others,
                        Message.VoiceId,
                        source=remote.voiceId)
     block.callback(self.collectVoiceData)
Exemple #22
0
 def buildSubvoice(self, oggName, side):
     """side is 'left' or 'right'."""
     angleDirectory = os.path.join(cacheDir(), 'angleVoices', self.md5sum,
                                   side)
     stdName = os.path.join(self.directory, oggName)
     angleName = os.path.join(angleDirectory, oggName)
     if os.path.exists(stdName) and not os.path.exists(angleName):
         sox = which('sox')
         if not sox:
             return stdName
         if not os.path.exists(angleDirectory):
             os.makedirs(angleDirectory)
         args = [sox, stdName, angleName, 'remix']
         if side == 'left':
             args.extend(['1,2', '0'])
         elif side == 'right':
             args.extend(['0', '1,2'])
         callResult = subprocess.call(args)
         if callResult:
             if Debug.sound:
                 logDebug('failed to build subvoice %s: return code=%s' %
                          (angleName, callResult))
             return stdName
         if Debug.sound:
             logDebug('built subvoice %s' % angleName)
     return angleName
Exemple #23
0
 def serverDisconnected(self, dummyReference):
     """perspective calls us back"""
     if self.connection and (Debug.traffic or Debug.connections):
         logDebug(
             'perspective notifies disconnect: %s' %
             self.connection.url)
     self.remote_serverDisconnects()
Exemple #24
0
 def __init__(self,
              names,
              ruleset,
              gameid=None,
              wantedGame=None,
              client=None,
              playOpen=False,
              autoPlay=False):
     """a new game instance, comes from database if gameid is set"""
     self.__activePlayer = None
     self.prevActivePlayer = None
     self.defaultNameBrush = None
     Game.__init__(self,
                   names,
                   ruleset,
                   gameid,
                   wantedGame=wantedGame,
                   client=client)
     self.playOpen = playOpen
     self.autoPlay = autoPlay
     myself = self.myself
     if self.belongsToHumanPlayer() and myself:
         myself.voice = Voice.locate(myself.name)
         if myself.voice:
             if Debug.sound:
                 logDebug('myself %s gets voice %s' %
                          (myself.name, myself.voice))
         else:
             if Debug.sound:
                 logDebug('myself %s gets no voice' % (myself.name))
Exemple #25
0
 def startServer(self, result, waiting=0):
     """make sure we have a running local server or network connectivity"""
     if self.isLocalHost:
         # just wait for that server to appear
         if self.__serverListening():
             return result
         else:
             if waiting == 0:
                 self.__startLocalServer()
             elif waiting > 30:
                 logDebug(
                     'Game %s: Server %s not available after 30 seconds, aborting'
                     % (SingleshotOptions.game, self))
                 raise CancelledError
             return deferLater(Internal.reactor, 1, self.startServer,
                               result, waiting + 1)
     elif which('qdbus'):
         try:
             stdoutdata, stderrdata = subprocess.Popen(
                 [
                     'qdbus', 'org.kde.kded', '/modules/networkstatus',
                     'org.kde.Solid.Networking.status'
                 ],
                 stdout=subprocess.PIPE,
                 stderr=subprocess.PIPE).communicate(timeout=1)
         except subprocess.TimeoutExpired:
             raise twisted.internet.error.ConnectError()
         stdoutdata = stdoutdata.strip()
         stderrdata = stderrdata.strip()
         if stderrdata == '' and stdoutdata != '4':
             # pylint: disable=nonstandard-exception
             raise twisted.internet.error.ConnectError()
         # if we have stderrdata, qdbus probably does not provide the
         # service we want, so ignore it
     return result
Exemple #26
0
 def start(self, dummyResults='DIREKT'):
     """start the animation, returning its deferred"""
     assert self.state() != QAbstractAnimation.Running
     for animation in self.animations:
         uiTile = animation.targetObject()
         self.debug |= uiTile.tile in Debug.animation
         uiTile.setActiveAnimation(animation)
         self.addAnimation(animation)
         propName = animation.pName()
         animation.setStartValue(uiTile.getValue(propName))
         if propName == 'rotation':
             # change direction if that makes the difference smaller
             endValue = animation.unpackEndValue()
             currValue = uiTile.rotation
             if endValue - currValue > 180:
                 animation.setStartValue(currValue + 360)
             if currValue - endValue > 180:
                 animation.setStartValue(currValue - 360)
     for animation in self.animations:
         animation.targetObject().setDrawingOrder()
     self.finished.connect(self.allFinished)
     scene = Internal.scene
     scene.focusRect.hide()
     QParallelAnimationGroup.start(
         self,
         QAbstractAnimation.DeleteWhenStopped)
     if self.debug:
         logDebug(u'Animation group %d started (%s)' % (
             id(self), ','.join('A%d' % (id(x) % 10000) for x in self.animations)))
     return succeed(None)
Exemple #27
0
 def serverDisconnected(self, dummyReference):
     """perspective calls us back"""
     if self.connection and (Debug.traffic or Debug.connections):
         logDebug(
             u'perspective notifies disconnect: %s' %
             self.connection.url)
     self.remote_serverDisconnects()
Exemple #28
0
 def collectVoiceData(self, requests):
     """collect voices of other players"""
     if not self.running:
         return
     block = DeferredBlock(self)
     voiceDataRequests = []
     for request in requests:
         if request.answer == Message.ClientWantsVoiceData:
             # another human player requests sounds for voiceId
             voiceId = request.args[0]
             voiceFor = [
                 x for x in self.game.players
                 if isinstance(self.remotes[x], User)
                 and self.remotes[x].voiceId == voiceId
             ][0]
             voiceFor.voice = Voice(voiceId)
             if Debug.sound:
                 logDebug('client %s wants voice data %s for %s' %
                          (request.user.name, request.args[0], voiceFor))
             voiceDataRequests.append((request.user, voiceFor))
             if not voiceFor.voice.oggFiles():
                 # the server does not have it, ask the client with that
                 # voice
                 block.tell(voiceFor, voiceFor,
                            Message.ServerWantsVoiceData)
     block.callback(self.sendVoiceData, voiceDataRequests)
Exemple #29
0
    def processPlugin(self):
        """
            Create a graph for the specified component (or for all the project if is not defined)
            in which it shows the issues status (icebox, development, blocked and closed) in proportion

            :param project: Jira project
            :param componentId: Team to be analyzed. If empty, all project is counted
            :param fixVersion: If empty, all team issues are counted.
            :param actualSprint: If empty, all issues are counted. (Be careful, if all issues are counted it may a long time to run)
            :return: (str) Returns the filename of the generated image.
        """

        health_values = {}
        if self.component.__len__() == 0:
            component_jql = ''
        else:
            component_jql = jiraSetting.component_filters[str(self.component)]

        issue_type = jiraSetting.type_filters["Story_Spike"]

        for status, value in jiraSetting.status_filters.items():
            log.logDebug(
                "Executing request to get " + status + " issues for the team: " + component_jql + self.actualSprint)
            jql = 'project=' + str(self.project) + value + str(component_jql) + str(self.fixVersion) + str(
                self.actualSprint) + str(
                issue_type)
            res = tools.countIssue(jql, jira_connection)
            health_values[status] = res

        keys = list(health_values.keys())
        values = list(health_values.values())

        self.fileName = pl.generatePieChart("Sprint Health Board", self.project, self.component, self.fixVersion, keys,
                                            values)  # query ALL the project
        return self.fileName
Exemple #30
0
 def __initTableList(self, dummy):
     """first load of the list. Process options like --demo, --table, --join"""
     self.showTableList()
     if SingleshotOptions.table:
         Internal.autoPlay = False
         self.__requestNewTableFromServer(SingleshotOptions.table).addCallback(
             self.__showTables).addErrback(self.tableError)
         if Debug.table:
             logDebug(
                 u'%s: --table lets us open an new table %d' %
                 (self.name, SingleshotOptions.table))
         SingleshotOptions.table = False
     elif SingleshotOptions.join:
         Internal.autoPlay = False
         self.callServer('joinTable', SingleshotOptions.join).addCallback(
             self.__showTables).addErrback(self.tableError)
         if Debug.table:
             logDebug(
                 u'%s: --join lets us join table %s' %
                 (self.name, self._tableById(SingleshotOptions.join)))
         SingleshotOptions.join = False
     elif not self.game and (Internal.autoPlay or (not self.tables and self.hasLocalServer())):
         self.__requestNewTableFromServer().addCallback(
             self.__newLocalTable).addErrback(self.tableError)
     else:
         self.__showTables()
Exemple #31
0
 def __init__(self, paginaId, moduleConfig):
     self.project = ""
     self.component = ""
     self.fixVersion = ""
     self.actualSprint = ""
     log.logDebug('Processing Jira module for ' + str(paginaId) + ' con config ' + str(moduleConfig))
     self.doRequest(moduleConfig)
Exemple #32
0
 def createRule(self, name: str, definition: str = '', **kwargs):
     """shortcut for simpler definition of predefined rulesets"""
     defParts = definition.split('||')
     rule = None
     description = kwargs.get('description', '')
     for cls in [IntRule, BoolRule, StrRule]:
         if defParts[0].startswith(cls.prefix):
             rule = cls(name,
                        definition,
                        description=description,
                        parameter=kwargs['parameter'])
             break
     if not rule:
         if 'parameter' in kwargs:
             del kwargs['parameter']
         ruleType = type(ruleKey(name) + 'Rule', (Rule, ), {})
         rule = ruleType(name, definition, **kwargs)
         if defParts[0] == 'FCallingHand':
             parts1 = defParts[1].split('=')
             assert parts1[0] == 'Ohand', definition
             ruleClassName = parts1[1] + 'Rule'
             if ruleClassName not in RuleBase.ruleClasses:
                 logDebug('we want %s, definition:%s' %
                          (ruleClassName, definition))
                 logDebug('we have %s' % RuleBase.ruleClasses.keys())
             ruleType.limitHand = RuleBase.ruleClasses[ruleClassName]
     self.add(rule)
Exemple #33
0
    def debug(self, msg, btIndent=None, prevHandId=False):
        """
        Log a debug message.

        @param msg: The message.
        @type msg: A string.
        @param btIndent: If given, message is indented by
        depth(backtrace)-btIndent
        @type btIndent: C{int}
        @param prevHandId: If True, do not use current handId but previous
        @type prevHandId: C{bool}
        """
        if self.belongsToRobotPlayer():
            prefix = 'R'
        elif self.belongsToHumanPlayer():
            prefix = 'C'
        elif self.belongsToGameServer():
            prefix = 'S'
        else:
            logDebug(msg, btIndent=btIndent)
            return
        handId = self._prevHandId if prevHandId else self.handId
        handId = handId.prompt(withMoveCount=True)
        logDebug('%s%s: %s' % (prefix, handId, msg),
                 withGamePrefix=False,
                 btIndent=btIndent)
Exemple #34
0
 def nextHand(self, dummyResults):
     """next hand: maybe rotate"""
     if not self.running:
         return
     DeferredBlock.garbageCollection()
     for block in DeferredBlock.blocks:
         if block.table == self:
             logError('request left from previous hand: %s' %
                      block.outstandingStr())
     token = self.game.handId.prompt(
         withAI=False)  # we need to send the old token until the
     # clients started the new hand
     rotateWinds = self.game.maybeRotateWinds()
     if self.game.finished():
         self.server.removeTable(self, 'gameOver',
                                 i18nE('Game <numid>%1</numid> is over!'),
                                 self.game.seed)
         if Debug.process and os.name != 'nt':
             logDebug('MEM:%s' %
                      resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
         return
     self.game.sortPlayers()
     playerNames = list((x.wind, x.name) for x in self.game.players)
     self.tellAll(None,
                  Message.ReadyForHandStart,
                  self.startHand,
                  playerNames=playerNames,
                  rotateWinds=rotateWinds,
                  token=token)
Exemple #35
0
 def __init__(self, paginaId, moduleConfig):
     self.product = ""
     self.name = ""
     self.project = ""
     self.branch = ""
     log.logDebug('Processing Adict module for ' + str(paginaId) + ' con config ' + str(moduleConfig))
     self.doRequest(moduleConfig)
Exemple #36
0
 def clientAction(self, client, move):
     """violation: player may not say mah jongg"""
     move.player.popupMsg(self)
     move.player.mayWin = False
     if Debug.originalCall:
         logDebug(u'%s: cleared mayWin' % move.player)
     return client.ask(move, [Message.OK])
Exemple #37
0
def processFixVersions(connection, arrayVersions):
    allFixVersions = connection.project_versions(
        "MJF3DP")  # Jira request to get all allFixVersions for this project
    resultReleases = []
    auxDict = dict()
    resultDict = dict()

    listArrayVersions = arrayVersions.split(",")
    for version in allFixVersions:
        for item in listArrayVersions:
            if str(version) == str(item):
                resultReleases.append(version)
    for release in resultReleases:
        frameFixVersionArray = []
        try:
            arrayDate = release.releaseDate.split("-")
            frameFixVersionArray.append(str("ID: " +
                                            processIdArray(arrayDate)))
            log.logDebug('Transforming date: ' + str(arrayDate) + ' to ' +
                         processIdArray(arrayDate))

        except:
            frameFixVersionArray.append("ID: N/A")
            log.logDebug('Transforming date: [Null] to ID:N/A')
        processRelease(release, frameFixVersionArray)
        auxDict[str(release.name)] = frameFixVersionArray
        resultDict.update(auxDict)

    return resultDict
Exemple #38
0
 def _clientDiscarded4(self, dummyResults, msg, dangerousText,
                       mustPlayDangerous):
     """client told us he discarded a tile. Continue, check for dangerous game"""
     block = DeferredBlock(self)
     player = msg.player
     if dangerousText:
         if mustPlayDangerous and not player.lastSource.isDiscarded:
             if Debug.dangerousGame:
                 tile = Tile(msg.args[0])
                 logDebug(
                     '%s claims no choice. Discarded %s, keeping %s. %s' %
                     (player, tile, ''.join(
                         player.concealedTiles), ' / '.join(dangerousText)))
             player.claimedNoChoice = True
             block.tellAll(player,
                           Message.NoChoice,
                           tiles=TileList(player.concealedTiles))
         else:
             player.playedDangerous = True
             if Debug.dangerousGame:
                 tile = Tile(msg.args[0])
                 logDebug(
                     '%s played dangerous. Discarded %s, keeping %s. %s' %
                     (player, tile, ''.join(
                         player.concealedTiles), ' / '.join(dangerousText)))
             block.tellAll(player,
                           Message.DangerousGame,
                           tiles=TileList(player.concealedTiles))
     if msg.answer == Message.OriginalCall:
         player.isCalling = True
         block.callback(self.clientMadeOriginalCall, msg)
     else:
         block.callback(self._askForClaims, msg)
Exemple #39
0
 def perspective_setClientProperties(
         self, dbIdent, voiceId, maxGameId, clientVersion=None):
     """perspective_* methods are to be called remotely"""
     self.dbIdent = dbIdent
     self.voiceId = voiceId
     self.maxGameId = maxGameId
     clientVersion = nativeString(clientVersion)
     serverVersion = Internal.defaultPort
     if clientVersion != serverVersion:
         # we assume that versions x.y.* are compatible
         if clientVersion is None:
             # client passed no version info
             return fail(srvError(pb.Error,
                                  m18nE(
                                      'Your client has a version older than 4.9.0 but you need %1 for this server'),
                                  serverVersion))
         else:
             commonDigits = len([x for x in zip(
                 clientVersion.split(b'.'),
                 serverVersion.split(b'.'))
                                 if x[0] == x[1]])
             if commonDigits < 2:
                 return fail(srvError(pb.Error,
                                      m18nE(
                                          'Your client has version %1 but you need %2 for this server'),
                                      clientVersion or '<4.9.0',
                                      '.'.join(serverVersion.split('.')[:2]) + '.*'))
     if Debug.table:
         logDebug(u'client has dbIdent={} voiceId={} maxGameId={} clientVersion {}'.format(
             self.dbIdent, self.voiceId, self.maxGameId, clientVersion))
     self.server.sendTables(self)
Exemple #40
0
 def rollback(self, silent=None):
     """rollback and log it"""
     try:
         sqlite3.Connection.rollback(self)
         if not silent and Debug.sql:
             logDebug(u'%x rollbacked transaction' % id(self))
     except sqlite3.Error as exc:
         logWarning(u'%s cannot rollback: %s' % (self.name, exc.message))
Exemple #41
0
 def detached(self, dummyMind):
     """override pb.Avatar.detached"""
     if Debug.connections:
         logDebug(
             u'%s: connection detached from %s' %
             (self, self.source()))
     self.server.logout(self)
     self.mind = None
Exemple #42
0
 def addWatch(self, name, method):
     """If name changes, call method.
     method must accept 2 arguments: old value and new value."""
     if method not in self.__watching[name]:
         self.__watching[name].append(method)
         if Debug.preferences:
             logDebug('addWatch on {}, hook {}'.format(
                 name, method.__name__))
         self.callTrigger(name)  # initial change
Exemple #43
0
 def setEndValue(self, endValue):
     """wrapper with debugging code"""
     uiTile = self.targetObject()
     if uiTile.tile in Debug.animation:
         pName = self.pName()
         logDebug(
             u'%s: change endValue for %s: %s->%s  %s' % (self.ident(), pName, self.formatValue(self.endValue()),
                                                          self.formatValue(endValue), uiTile))
     QPropertyAnimation.setEndValue(self, endValue)
Exemple #44
0
 def board(self, value):
     """assign and show/hide as needed"""
     if value and not isAlive(value):
         logDebug(
             u'assigning focusRect to a non-alive board %s/%s' %
             (type(value), value))
         return
     if value:
         self._board = value
         self.refresh()
Exemple #45
0
 def remote_chat(self, data):
     """others chat to me"""
     chatLine = ChatMessage(data)
     if Debug.chat:
         logDebug(u'got chatLine: %s' % chatLine)
     table = self._tableById(chatLine.tableid)
     if not chatLine.isStatusMessage and not table.chatWindow:
         ChatWindow(table)
     if table.chatWindow:
         table.chatWindow.receiveLine(chatLine)
Exemple #46
0
 def serverAction(self, dummyTable, msg):
     """save voice sounds on the server"""
     voice = msg.player.voice
     voice.archiveContent = msg.args[0]
     if Debug.sound:
         if voice.oggFiles():
             logDebug(u'%s: server got wanted voice data %s' % (
                 msg.player, voice))
         else:
             logDebug(u'%s: server got empty voice data %s (arg0=%s)' % (
                 msg.player, voice, repr(msg.args[0][:100])))
Exemple #47
0
 def __generateDbIdent():
     """make sure the database has a unique ident and get it"""
     records = Query('select ident from general').records
     assert len(records) < 2
     if not records:
         dbIdent = str(random.randrange(100000000000))
         Query("INSERT INTO general(ident) values(?)", (dbIdent,))
         if Debug.sql:
             logDebug(
                 u'generated new dbIdent %s for %s' %
                 (dbIdent, Internal.db.path))
Exemple #48
0
 def cancelled(dummy):
     """the user does not want to start now. Back to table list"""
     if Debug.table:
         logDebug(u'%s: Readyforgamestart returns Message.NoGameStart for table %s' % (
             self.name, self._tableById(tableid)))
     self.table = None
     self.beginQuestion = None
     if self.tableList:
         self.__updateTableList()
         self.tableList.show()
     return Message.NoGameStart
Exemple #49
0
 def clientAction(self, client, move):
     """mirror the original call"""
     player = move.player
     if client.thatWasMe(player):
         player.originalCallingHand = player.hand
         if Debug.originalCall:
             logDebug(
                 u'%s gets originalCallingHand:%s' %
                 (player, player.originalCallingHand))
     player.originalCall = True
     client.game.addCsvTag('originalCall')
     return client.ask(move, [Message.OK])
Exemple #50
0
def cleanExit(*dummyArgs):
    """close sqlite3 files before quitting"""
    if isAlive(Internal.mainWindow):
        if Debug.quit:
            logDebug(u'cleanExit calling mainWindow.close')
        Internal.mainWindow.close()
    else:
        # this must be very early or very late
        if Debug.quit:
            logDebug(u'cleanExit calling sys.exit(0)')
        # sys.exit(0)
        MainWindow.aboutToQuit()
Exemple #51
0
 def garbageCollection():
     """delete completed blocks. Only to be called before
     inserting a new block. Assuming that block creation
     never overlaps."""
     for block in DeferredBlock.blocks[:]:
         if block.callbackMethod is None:
             block.logBug(u'DBlock %s has no callback' % str(block))
         if block.completed:
             DeferredBlock.blocks.remove(block)
     if len(DeferredBlock.blocks) > 100:
         logDebug(
             u'We have %d DeferredBlocks, they must be leaking' %
             len(DeferredBlock.blocks))
Exemple #52
0
def __afterCurrentAnimationDo(callback, *args, **kwargs):
    """a helper, delaying some action until all active
    animations have finished"""
    current = ParallelAnimationGroup.current
    if current:
        deferred = Deferred()
        deferred.addCallback(callback, *args, **kwargs)
        current.doAfter.append(deferred)
        if current.debug:
            logDebug(u'after current animation %d do %s %s' %
                     (id(current), callback, ','.join(args) if args else ''))
    else:
        callback(None, *args, **kwargs)
Exemple #53
0
 def callTrigger(self, name):
     """call registered callback for this attribute change"""
     newValue = getattr(self, name)
     if self.__oldValues[name] != newValue:
         if Debug.preferences:
             logDebug(u'{}: {} -> {} calling {}'.format(
                 name,
                 self.__oldValues[name],
                 newValue,
                 ','.join(x.__name__ for x in self.__watching[name])))
         for method in self.__watching[name]:
             method(self.__oldValues[name], newValue)
     self.__oldValues[name] = newValue
Exemple #54
0
 def sendLine(self, line=None, isStatusMessage=False):
     """send line to others. Either the edited line or parameter line."""
     if line is None:
         line = unicode(self.edit.text())
         self.edit.clear()
     if line:
         if Debug.chat:
             logDebug(u'sending line %s to others' % line)
         msg = ChatMessage(
             self.table.tableid,
             self.table.client.name,
             line,
             isStatusMessage)
         self.table.client.sendChat(msg).addErrback(self.chatError)
Exemple #55
0
 def hideTableList(result):
     """hide it only after player says I am ready"""
     # set scene.game first, otherwise tableList.hide()
     # sees no current game and logs out
     if result == Message.OK:
         if client.game and Internal.scene:
             Internal.scene.game = client.game
     if result == Message.OK and client.tableList and client.tableList.isVisible():
         if Debug.table:
             logDebug(
                 u'%s hiding table list because game started' %
                 client.name)
         client.tableList.hide()
     return result
Exemple #56
0
 def aboutToQuit():
     """now all connections to servers are cleanly closed"""
     mainWindow = Internal.mainWindow
     Internal.mainWindow = None
     if mainWindow:
         if Debug.quit:
             logDebug(u'aboutToQuit starting')
         if mainWindow.exitWaitTime > 1000.0 or Debug.quit:
             logDebug(
                 u'reactor stopped after %d ms' %
                 (mainWindow.exitWaitTime))
     else:
         if Debug.quit:
             logDebug(u'aboutToQuit: mainWindow is already None')
     StateSaver.saveAll()
     Internal.app.quit()
     try:
         # if we are killed while loading, Internal.db may not yet be
         # defined
         if Internal.db:
             Internal.db.close()
     except NameError:
         pass
     checkMemory()
     logging.shutdown()
     if Debug.quit:
         logDebug(u'aboutToQuit ending')
Exemple #57
0
 def tell(self, about, receivers, command, **kwargs):
     """send info about player 'about' to users 'receivers'"""
     def encodeKwargs():
         """those values are classes like Meld, Tile etc.
            Convert to str(python2) or bytes(python3"""
         for keyword in ('tile', 'tiles', 'meld', 'melds'):
             if keyword in kwargs:
                 kwargs[keyword] = str(kwargs[keyword]).encode()
     encodeKwargs()
     if about.__class__.__name__ == 'User':
         about = self.playerForUser(about)
     if not isinstance(receivers, list):
         receivers = list([receivers])
     assert receivers, 'DeferredBlock.tell(%s) has no receiver' % command
     self.__enrichMessage(self.table.game, about, command, kwargs)
     aboutName = about.name if about else None
     if self.table.running and len(receivers) in [1, 4]:
         # messages are either identical for all 4 players
         # or identical for 3 players and different for 1 player. And
         # we want to capture each message exactly once.
         self.table.game.appendMove(about, command, kwargs)
     localDeferreds = []
     for rec in self.__convertReceivers(receivers):
         isClient = rec.__class__.__name__.endswith('Client')
         if Debug.traffic and not isClient:
             message = u'-> {receiver:<15} about {about} {command}{kwargs}'.format(
                 receiver=rec.name[:15], about=about, command=command,
                 kwargs=Move.prettyKwargs(kwargs))
             logDebug(message)
         if isClient:
             defer = Deferred()
             defer.addCallback(rec.remote_move, command, **kwargs)
         else:
             defer = self.table.server.callRemote(
                 rec,
                 'move',
                 aboutName,
                 command.name,
                 **kwargs)
         if defer:
             defer.command = command.name
             defer.notifying = 'notifying' in kwargs
             self.__addRequest(defer, rec, about)
         else:
             msg = m18nE('The game server lost connection to player %1')
             self.table.abort(msg, rec.name)
         if isClient:
             localDeferreds.append(defer)
     for defer in localDeferreds:
         defer.callback(aboutName)  # callback needs an argument !
Exemple #58
0
 def __logCallServer(self, *args):
     """for Debug.traffic"""
     debugArgs = list(args[:])
     if Debug.neutral:
         if debugArgs[0] == 'ping':
             return
         if debugArgs[0] == 'setClientProperties':
             debugArgs[1] = 'DBID'
             debugArgs[3] = 'GAMEID'
             if debugArgs[4] >= 8300:
                 debugArgs[4] -= 300
     if self.game:
         self.game.debug('callServer(%s)' % repr(debugArgs))
     else:
         logDebug(u'callServer(%s)' % repr(debugArgs))
Exemple #59
0
 def focusTile(self, uiTile):
     """the uiTile of this board with focus. This is per Board!"""
     if uiTile is self._focusTile:
         return
     if uiTile:
         assert uiTile.tile.isKnown, uiTile
         if not isinstance(uiTile.board, DiscardBoard):
             assert uiTile.focusable, uiTile
         self.__prevPos = uiTile.sortKey()
     self._focusTile = uiTile
     if self._focusTile and self._focusTile.tile in Debug.focusable:
         logDebug(u'%s: new focus uiTile %s from %s' % (
             self.name, self._focusTile.tile if self._focusTile else 'None', stack('')[-1]))
     if self.hasFocus:
         self.scene().focusBoard = self
Exemple #60
0
 def confirmed(result):
     """quit if the active game has been aborted"""
     self.exitConfirmed = bool(result)
     if Debug.quit:
         if self.exitConfirmed:
             logDebug(u'mainWindow.queryClose confirmed')
         else:
             logDebug(u'mainWindow.queryClose not confirmed')
     # start closing again. This time no question will appear, the game
     # is already aborted
     if self.exitConfirmed:
         assert isAlive(self)
         self.close()
     else:
         self.exitConfirmed = None