def _Crawl(self, base): """Crawls the directory given by |base| to find games. The return value is a dictionary from ID (field ia.id in the JSON config) to Game object. """ games = {} queue = [base] while queue: dir = queue.pop() for entry in os.scandir(dir): if not entry.is_dir(): continue try: config_path = os.path.join(entry.path, 'config.json') dummy = os.stat(config_path) with open(config_path, 'r') as file: data = file.read() config = json.loads(data) game = Game(entry.path, config) games[game.ID()] = game except json.decoder.JSONDecodeError as e: print('Malformed JSON in %s:' % (config_path, )) raise e except FileNotFoundError: queue.append(entry.path) return games
def startgame(): global thegame if thegame != None and thegame.ID != None: return (jsonify({'error': 'Game already started'}), 400) game_id = str(uuid.uuid4()) thegame = Game() thegame.ID = game_id return (jsonify({'game_id': thegame.ID}), 200)