예제 #1
0
def cache(host, username):
    return Cache(Cache.key(host, username),
                 configdir='/tmp/tpclient-pyweb/cache/')
예제 #2
0
        # Try creating the user..
        print "User did not exist, trying to create user."
        if failed(connection.account(username, password, "", "daneel-ai bot")):
            print "Username / Password incorrect."
            return

        if failed(connection.login(username, password)):
            print "Created username, but still couldn't login :/"
            return

    games = connection.games()
    if failed(games):
        print "Getting the game object failed!"
        return

    cache = Cache(Cache.key(host, games[0], username))
    return connection, cache

def getDataDir():
    if hasattr(sys, "frozen"):
        return os.path.join(installpath, "share", "daneel-ai")
    if "site-packages" in daneel.__file__:
        datadir = os.path.join(os.path.dirname(daneel.__file__), "..", "..", "..", "..", "share", "daneel-ai")
    else:
        datadir = os.path.join(os.path.dirname(daneel.__file__), "..")
    return datadir
   


def createRuleSystem(rulesfile,verbosity,cache,connection):
    global mods
예제 #3
0
             state,
             message="",
             todownload=None,
             total=None,
             amount=None):
    """Callback function used when downloading all game data"""
    pass


def connect(host, port, username, password):
    """Connect function, used by the backend"""
    try:
        connection = Connection(host=host, port=port, debug=False)
    except socket.error, e:
        raise ConnectionError('Unable to connect to the host.')

    if failed(connection.connect()):
        raise ConnectionError('Unable to connect to the host.')

    if failed(connection.login(username, password)):
        raise ConnectionError('Wrong user name or password.')

    cache = Cache(Cache.key(host, username),
                  configdir='/tmp/tpclient-pyweb/cache/')
    return connection, cache


def cache(host, username):
    return Cache(Cache.key(host, username),
                 configdir='/tmp/tpclient-pyweb/cache/')
예제 #4
0
def cache(host, username):
    return Cache(Cache.key(host, username), configdir='/tmp/tpclient-pyweb/cache/')
예제 #5
0
    """Exception used in connect"""
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return str(self.value)

def callback(mode, state, message="", todownload=None, total=None, amount=None):
    """Callback function used when downloading all game data"""
    pass

def connect(host, port, username, password):
    """Connect function, used by the backend"""
    try:
        connection = Connection(host=host, port=port, debug=False)
    except socket.error, e:
        raise ConnectionError('Unable to connect to the host.')

    if failed(connection.connect()):
        raise ConnectionError('Unable to connect to the host.')

    if failed(connection.login(username, password)):
        raise ConnectionError('Wrong user name or password.')

    cache = Cache(Cache.key(host, username), configdir='/tmp/tpclient-pyweb/cache/')
    return connection, cache

def cache(host, username):
    return Cache(Cache.key(host, username), configdir='/tmp/tpclient-pyweb/cache/')

예제 #6
0
	# print list_of_states
	
	# FIXME remove the hard codings here
	rulesfile='risk'
	turns = 0
	connection = None
	verbosity = 1
	for state in list_of_states:
		basename = state.partition('.')
		output = state_dir + basename[0]  + ".out"
		profile = state_dir + state  + ".profile"
		
#		tested_state = picklegamestate.GameState().unpickle(state_dir + state)
		
		print state_dir + state
		cache = Cache('test')
		cache.file = state_dir + state
		cache.load()

		cProfile.runctx('gameLoopBenchMark(rulesfile,turns,connection,cache,verbosity)', globals(), locals(), profile)	
		
		file = FakeStdOut(output, 'w')
		p = pstats.Stats(profile,stream=file)
		
		p.strip_dirs().sort_stats('time').print_stats(100)
		file.close()
			

		
	
예제 #7
0
def createCache(host, port, username, password, games):
    """Create the initial cache"""
    #print "Cache Key" + Cache.key(host, games, username)+":"+str(port)+"/"
    cache = Cache(Cache.key(host, games[0], username)+":"+str(port)+"/", configdir='/tmp/tpclient-pyweb/cache/')
    
    return cache