# 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 collections import defaultdict
from os import access, R_OK, remove as remove_file, listdir
from os.path import join as join_path, normpath as norm_path
from threading import Lock
from time import time as get_time
from simplejson import JSONEncoder, JSONDecoder
from turbulenz_local.lib.exceptions import ApiException
from yaml import YAMLError
from pylons import config
from turbulenz_local.tools import get_absolute_path, create_dir
    @classmethod
    def load(cls, game):
        keys = GameNotificationKeys(game)
        cls.notification_key_dict[game.slug] = keys
        return keys


    @classmethod
    def get(cls, game):
        return cls.notification_key_dict.get(game.slug) or cls.load(game)


    @classmethod
    def reset(cls):
        cls.notification_key_dict = {}



def _get_task_path(slug, recipient, notification_type, filename=None):
    try:
        path = config['notifications_db']
    except KeyError:
        raise GameNotificationsUnsupportedException('notifications_db path config variable not set')

    path = join_path(path, slug, recipient, notification_type)

    if not create_dir(path):
        raise GameNotificationPathError('User GameNotification path \"%s\" could not be created.' % path)

    if filename:

# 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/gamenotifications.py
import logging
import yaml
from collections import defaultdict
from os import access, R_OK, remove as remove_file, listdir
from os.path import join as join_path, normpath as norm_path
from threading import Lock
from time import time as get_time
from simplejson import JSONEncoder, JSONDecoder
from turbulenz_local.lib.exceptions import ApiException
from yaml import YAMLError
from pylons import config
from turbulenz_local.tools import get_absolute_path, create_dir

    @classmethod
    def load(cls, game):
        keys = GameNotificationKeys(game)
        cls.notification_key_dict[game.slug] = keys
        return keys


    @classmethod
    def get(cls, game):
        return cls.notification_key_dict.get(game.slug) or cls.load(game)


    @classmethod
    def reset(cls):
        cls.notification_key_dict = {}



def _get_task_path(slug, recipient, notification_type, filename=None):
    try:
        path = config['notifications_db']
    except KeyError:
        raise GameNotificationsUnsupportedException('notifications_db path config variable not set')

    path = join_path(path, slug, recipient, notification_type)

    if not create_dir(path):
        raise GameNotificationPathError('User GameNotification path \"%s\" could not be created.' % path)

    if filename:

        return get_absolute_path(join_path(path, filename))