Exemplo n.º 1
0
def get_database(verbose=True):
    global the_database

    def add_game_to_db(game, sm, model):
        info = GameInfoBypass(game, sm, model)
        the_database.game_mapping[game] = info

    if the_database is None:
        from ggplib.db.store import get_root
        the_database = GameDatabase(get_root())
        the_database.load(verbose=verbose)

        try:
            install_draughts(add_game_to_db)

        except Exception as err:
            log.error("Failed to install draughts: %s" % err)

        try:
            install_hex(add_game_to_db)

        except Exception as err:
            log.error("Failed to install hex: %s" % err)

    return the_database
Exemplo n.º 2
0
def get_database(verbose=True):
    global the_database
    if the_database is None:
        from ggplib.db.store import get_root
        the_database = GameDatabase(get_root())
        the_database.load(verbose=verbose)

    return the_database
Exemplo n.º 3
0
def test_import_store():
    root = store.get_root()
    rulesheets = root.get_directory("rulesheets")

    assert len(rulesheets.listdir("connectFour.kif")) == 1
    assert len(rulesheets.listdir("ticTacToe.kif")) == 1
    assert len(rulesheets.listdir("*.kif")) > 1
    print rulesheets.listdir("*.kif")
Exemplo n.º 4
0
def main(filenames, pre_load_database):
    root_store = get_root()
    rulesheets_store = root_store.get_directory("rulesheets")

    pattern = r'"([A-Za-z0-9_\./\\-]*)"'
    games = re.findall(pattern, text)

    mapping = {}
    for fn in filenames:
        a = fn
        # strip this off, comes from 'find ... | xargs ...'
        assert a.startswith("./")
        a = a[2:]

        # the directiory structure in ggp-repository is: game/version/x.kif.  If first version of the directory
        # structure is an implied v0.
        components = a.split('/')
        game = components[0]
        if len(components) == 2:
            version = 0
        else:
            assert len(components) == 3
            version = int(components[1].replace("v", ""))

        # skip games not interested in...
        if game not in games:
            continue

        # create our own mapping of most recent version of game
        if game in mapping:
            if version > mapping[game][0]:
                mapping[game] = (version, fn)
        else:
            mapping[game] = (version, fn)

    # all the games need to exist... or something is wrong
    print set(games) == set(mapping)

    # just copy to our destination_path the kif files
    known_to_fail = [
        'amazonsTorus_10x10', 'atariGoVariant_7x7', 'gt_two_thirds_4p',
        'gt_two_thirds_6p', 'linesOfAction', 'ticTacToeLargeSuicide',
        'ticTacToeLarge'
    ]

    for game in games:
        fn = mapping[game][1]

        if game in known_to_fail:
            continue

        cmd = "cp -f %s %s/%s.kif" % (fn, rulesheets_store.path, game)
        print cmd
        os.system(cmd)

    if pre_load_database:
        from ggplib.db.helper import lookup_all_games
        lookup_all_games()
Exemplo n.º 5
0
def get_gdl_for_game(game, replace_map=None):
    ''' return the gdl from the store '''
    root_store = get_root()
    rulesheets_store = root_store.get_directory("rulesheets")

    gdl = rulesheets_store.load_contents(game + ".kif")
    if replace_map:
        for k, v in replace_map.items():
            gdl.replace(k, v)
    return gdl
Exemplo n.º 6
0
def test_create():
    root = store.get_root()
    rulesheets = root.get_directory("rulesheets")
    games = root.get_directory("games")
    print rulesheets
    print games

    try:
        root.get_directory("i dont exist")
        assert False, "does not get here"
    except store.StoreException:
        pass

    # pretty unsafe test, but whatever
    abc = root.get_directory("abc", create=True)
    assert root.get_directory("abc", create=True) == abc
    os.rmdir(abc.path)