[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kajongg/sid] src: save current commit id or version in csv
From:       Wolfgang Rohdewald <wolfgang () rohdewald ! de>
Date:       2013-10-31 21:21:02
Message-ID: E1Vbzfq-0002lj-C3 () scm ! kde ! org
[Download RAW message or body]

Git commit f1a36a785d4fa96973e19e2e800883e3aeabe54d by Wolfgang Rohdewald.
Committed on 28/10/2013 at 21:57.
Pushed by wrohdewald into branch 'sid'.

save current commit id or version in csv

M  +3    -2    src/humanclient.py
M  +3    -1    src/kajongg.py
M  +18   -16   src/kajonggtest.py
M  +1    -1    src/scoringtest.py
M  +14   -0    src/util.py

http://commits.kde.org/kajongg/f1a36a785d4fa96973e19e2e800883e3aeabe54d

diff --git a/src/humanclient.py b/src/humanclient.py
index 5a5d32b..e1e87d8 100644
--- a/src/humanclient.py
+++ b/src/humanclient.py
@@ -32,7 +32,7 @@ from kde import Sorry, Information, QuestionYesNo, KIcon, \
     DialogIgnoringEscape
 
 from util import m18n, logWarning, logException, \
-    logInfo, logDebug
+    logInfo, logDebug, commit
 from message import Message, ChatMessage
 from chat import ChatWindow
 from common import Options, SingleshotOptions, Internal, Preferences, Debug, isAlive
@@ -710,7 +710,8 @@ class HumanClient(Client):
                     writer = csv.writer(open(Options.csv,'a'), delimiter=';')
                     if Debug.process:
                         self.game.csvTags.append('MEM:%s' % \
                resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
-                    row = [self.game.ruleset.name, Options.AI, str(self.game.seed), \
','.join(self.game.csvTags)] +                    row = [self.game.ruleset.name, \
Options.AI, commit(), str(self.game.seed), +                        \
                ','.join(self.game.csvTags)]
                     for player in sorted(self.game.players, key=lambda x: x.name):
                         row.append(player.name.encode('utf-8'))
                         row.append(player.balance)
diff --git a/src/kajongg.py b/src/kajongg.py
index 7ec3b43..f296946 100755
--- a/src/kajongg.py
+++ b/src/kajongg.py
@@ -139,7 +139,7 @@ class EvHandler(QObject):
         return QObject.eventFilter(self, receiver, event)
 
 if __name__ == "__main__":
-    from util import initLog
+    from util import initLog, commit
     initLog('kajongg')
 
     ABOUT = About()
@@ -162,6 +162,8 @@ if __name__ == "__main__":
     reactor.runReturn(installSignalHandlers=False)
     Internal.reactor = reactor
 
+    if Options.csv:
+        commit() # abort if we cannot get a legal commit for the csv file?
     if Options.gui:
         from playfield import PlayField
         PlayField().show()
diff --git a/src/kajonggtest.py b/src/kajonggtest.py
index bb622d3..77bd5de 100755
--- a/src/kajonggtest.py
+++ b/src/kajonggtest.py
@@ -24,14 +24,15 @@ import os, sys, csv, subprocess, random
 from optparse import OptionParser
 
 from common import Debug
-from util import removeIfExists
+from util import removeIfExists, initLog, commit
 
 # fields in row:
 RULESET = 0
 AI = 1
-GAME = 2
-TAGS = 3
-PLAYERS = 4
+COMMIT = 2
+GAME = 3
+TAGS = 4
+PLAYERS = 5
 
 def neutralize(rows):
     """remove things we do not want to compare"""
@@ -58,8 +59,8 @@ def readGames(csvFile):
     allRows = set(tuple(x) for x in allRows)
     games = dict()
     # build set of rows for every ai
-    for variant in set(tuple(x[:GAME]) for x in allRows):
-        games[variant] = frozenset(x for x in allRows if tuple(x[:GAME]) == variant)
+    for variant in set(tuple(x[:COMMIT]) for x in allRows):
+        games[variant] = frozenset(x for x in allRows if tuple(x[:COMMIT]) == \
variant)  return games
 
 def printDifferingResults(rowLists):
@@ -74,7 +75,7 @@ def printDifferingResults(rowLists):
             allGameIds[rowId].append(row)
     differing = []
     for key, value in allGameIds.items():
-        if len(set(tuple(list(x)[GAME:]) for x in value)) != 1:
+        if len(set(tuple(list(x)[GAME:]) for x in value)) > \
len(set(tuple(list(x)[:COMMIT]) for x in value)):  differing.append(key)
     if not differing:
         print 'no games differ'
@@ -86,20 +87,17 @@ def evaluate(games):
     """evaluate games"""
     if not games:
         return
-    commonGames = None
+    commonGames = set()
     for variant, rows in games.items():
         gameIds = set(x[GAME] for x in rows)
-        if len(gameIds) != len(rows):
+        if len(gameIds) != len(set(tuple(list(x)[GAME:]) for x in rows)) != 1:
             print 'ruleset "%s" AI "%s" has different rows for games' % (variant[0], \
variant[1]),  for game in gameIds:
                 if len([x for x in rows if x[GAME] == game]) > 1:
                     print game,
             print
-            return
-        if not commonGames:
-            commonGames = gameIds
-        else:
-            commonGames &= gameIds
+            break
+        commonGames &= gameIds
     printDifferingResults(games.values())
     print
     print 'the 3 robot players always use the Default AI'
@@ -112,7 +110,7 @@ def evaluate(games):
         print '{ruleset:<25} {ai:<20} {games:>5}  '.format(ruleset = ruleset[:25], \
ai=aiVariant[:20],  games=len(commonGames)),
         for playerIdx in range(4):
-            print '{p:>8}'.format(p=sum(int(x[PLAYER+playerIdx*4]) for x in rows if \
x[GAME] in commonGames)), +            print \
'{p:>8}'.format(p=sum(int(x[PLAYERS+1+playerIdx*4]) for x in rows if x[GAME] in \
commonGames)),  print
     print
     print 'all games:'
@@ -122,7 +120,7 @@ def evaluate(games):
             print '{ruleset:<25} {ai:<20} {rows:>5}  '.format(ruleset=ruleset[:25], \
ai=aiVariant[:20],  rows=len(rows)),
             for playerIdx in range(4):
-                print '{p:>8}'.format(p=sum(int(x[PLAYER+1+playerIdx*4]) for x in \
rows)), +                print '{p:>8}'.format(p=sum(int(x[PLAYERS+1+playerIdx*4]) \
for x in rows)),  print
 
 def proposeGames(games, optionAIVariants, rulesets):
@@ -281,6 +279,10 @@ def improve_options(options):
 def main():
     """parse options, play, evaluate results"""
 
+    initLog('kajonggtest')
+
+    commit() # make sure we are at a point where comparisons make sense
+
     (options, args) = parse_options()
 
     options = improve_options(options)
diff --git a/src/scoringtest.py b/src/scoringtest.py
index 0f6fe48..491d536 100755
--- a/src/scoringtest.py
+++ b/src/scoringtest.py
@@ -454,7 +454,7 @@ class TstProgram(unittest.TestProgram):
         unittest.TestProgram.__init__(self, *args, **kwargs)
 
 if __name__ == '__main__':
-    initLog('kajonggtest')
+    initLog('scoringtest')
     Debug.profileRegex = True
    # Debug.handMatch = True
     TstProgram()
diff --git a/src/util.py b/src/util.py
index ecd8036..14f39f6 100644
--- a/src/util.py
+++ b/src/util.py
@@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA.  from __future__ import print_function
 import logging, socket, logging.handlers, traceback, os, datetime, shutil
 import time
+import subprocess
 
 from locale import getpreferredencoding
 from sys import stdout
@@ -394,3 +395,16 @@ def checkMemory():
                         type(obj), obj, id(referrer), type(referrer), referrer))
     logDebug('unreachable:%s' % gc.collect())
     gc.set_debug(0)
+
+def commit():
+    """the current git commit. Fail if there are uncommitted changes"""
+    if not os.path.exists(os.path.join('..', '.git')):
+        return Internal.version
+    subprocess.Popen(['git', 'update-index', '-q', '--refresh'])
+    _ = subprocess.Popen(['git', 'diff-index', '--name-only', 'HEAD', '--'], \
stdout=subprocess.PIPE).communicate()[0] +    uncommitted = list(x.strip() for x in \
_.split('\n') if len(x.strip())) +    if uncommitted:
+        raise UserWarning('you cannot write to CSV while having uncommitted changes \
in %s' % ', '.join(uncommitted)) +    result = subprocess.Popen(['git', 'log', '-1', \
'--format="%H"'], +            stdout=subprocess.PIPE).communicate()[0]
+    return result.split('\n')[0].replace('"', '')[:15]


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic