# Path: turbulenz_local/lib/exceptions.py
# class ApiException(BaseException):
#     def __init__(self, value, status='500 Internal Server Error', json_data=None):
#         super(ApiException, self).__init__()
#         self.value = value
#         self.status = status
#         self.json_data = json_data
# 
#     def __str__(self):
#         return self.value
# 
# Path: turbulenz_local/tools.py
# def get_absolute_path(directory):
#     """
#     Return absolute path by working out path relative to games root
#     """
#     if isabs(directory):
#         return directory
# 
#     return realpath(normpath(join(config['games_root'], directory)))
# 
# def create_dir(directory):
#     """
#     Create the directory structure if necessary. return 'True' if it was created
#     successfully and can be written into, 'False' otherwise.
#     """
#     if directory.strip() == '':
#         return False
#     else:
#         absDir = get_absolute_path(directory)
#         try:
#             os.makedirs(absDir)
#         except OSError as e:
#             if e.errno != EEXIST:
#                 LOG.error('Failed creating meta dir: %s', str(e))
#                 return False
#         return os.access(absDir, os.W_OK)


import logging
import yaml
from os import access, R_OK
from os.path import join as join_path
from os.path import normpath as norm_path
from threading import Lock
from turbulenz_local.lib.exceptions import ApiException
from pylons import config
from turbulenz_local.tools import get_absolute_path, create_dir

LOG = logging.getLogger(__name__)




# pylint: disable=F0401
# pylint: enable=F0401


REQUIRED_BADGE_KEYS = ['key', 'title', 'description', 'points', 'shape']

class BadgesUnsupportedException(Exception):
    pass

class GameBadges(object):
    badges = []
    userbadges = {}
    userbadges_path = None

    def __init__(self, game):
        self.lock = Lock()

        self.game = game
        self.userbadges_path = None

        self.abs_game_path = get_absolute_path(game.path)

        try:
            self.lock.acquire()

# Path: turbulenz_local/lib/exceptions.py
# class ApiException(BaseException):
#     def __init__(self, value, status='500 Internal Server Error', json_data=None):
#         super(ApiException, self).__init__()
#         self.value = value
#         self.status = status
#         self.json_data = json_data
# 
#     def __str__(self):
#         return self.value
# 
# Path: turbulenz_local/tools.py
# def get_absolute_path(directory):
#     """
#     Return absolute path by working out path relative to games root
#     """
#     if isabs(directory):
#         return directory
# 
#     return realpath(normpath(join(config['games_root'], directory)))
# 
# def create_dir(directory):
#     """
#     Create the directory structure if necessary. return 'True' if it was created
#     successfully and can be written into, 'False' otherwise.
#     """
#     if directory.strip() == '':
#         return False
#     else:
#         absDir = get_absolute_path(directory)
#         try:
#             os.makedirs(absDir)
#         except OSError as e:
#             if e.errno != EEXIST:
#                 LOG.error('Failed creating meta dir: %s', str(e))
#                 return False
#         return os.access(absDir, os.W_OK)


# Path: turbulenz_local/models/apiv1/badges.py
import logging
import yaml
from os import access, R_OK
from os.path import join as join_path
from os.path import normpath as norm_path
from threading import Lock
from turbulenz_local.lib.exceptions import ApiException
from pylons import config
from turbulenz_local.tools import get_absolute_path, create_dir


LOG = logging.getLogger(__name__)




# pylint: disable=F0401
# pylint: enable=F0401


REQUIRED_BADGE_KEYS = ['key', 'title', 'description', 'points', 'shape']

class BadgesUnsupportedException(Exception):
    pass

class GameBadges(object):
    badges = []
    userbadges = {}
    userbadges_path = None

    def __init__(self, game):
        self.lock = Lock()

        self.game = game
        self.userbadges_path = None

        self.abs_game_path = get_absolute_path(game.path)

        try:
            self.lock.acquire()

            yaml_path = norm_path(get_absolute_path(join_path(game.path, 'badges.yaml')))