# 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/lib/tools.py
# def create_id():
#     #id needs to be of 12-bytes length
#     string_id = ''
#     for _ in range(12):
#         string_id += '%02x' % randint(0, 255)
#     return string_id
# 
# Path: turbulenz_local/lib/exceptions.py
# class BadRequest(ApiException):
#     def __init__(self, value, json_data=None):
#         ApiException.__init__(self, value, '400 Bad Request', json_data)
# 
# class NotFound(ApiException):
#     def __init__(self, value, json_data=None):
#         ApiException.__init__(self, value, '404 Not Found', json_data)
# 
# class Forbidden(ApiException):
#     def __init__(self, value, json_data=None):
#         ApiException.__init__(self, value, '403 Forbidden', json_data)


import logging
import yaml
from re import compile as regex_compile
from time import time as time
from os import listdir, remove as remove_file
from os.path import join as join_path, splitext, exists as path_exists
from threading import Lock
from pylons import config
from turbulenz_local.tools import get_absolute_path, create_dir
from turbulenz_local.lib.tools import create_id
from turbulenz_local.lib.exceptions import BadRequest, NotFound, Forbidden

            return self._set(key, value, owner, self.read_and_write)

    def get(self, user, key):
        with self.lock:
            self.datashare_access(user)
            if not isinstance(key, unicode):
                raise BadRequest('Key must be a string')

            if not self.validate_key.match(key):
                raise BadRequest('Key can only contain alphanumeric characters hyphens and dots')

            return self.store.get(key)

    def get_keys(self, user):
        with self.lock:
            self.datashare_access(user)
            return [self.key_summary_dict(key) for key in self.store.iterkeys()]

    def set_joinable(self, user, joinable):
        with self.lock:
            self.datashare_access(user)
            self.joinable = joinable
            self.write()

    def reload(self):
        with self.lock:
            try:
                self.load()
            except NotFound:

# 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/lib/tools.py
# def create_id():
#     #id needs to be of 12-bytes length
#     string_id = ''
#     for _ in range(12):
#         string_id += '%02x' % randint(0, 255)
#     return string_id
# 
# Path: turbulenz_local/lib/exceptions.py
# class BadRequest(ApiException):
#     def __init__(self, value, json_data=None):
#         ApiException.__init__(self, value, '400 Bad Request', json_data)
# 
# class NotFound(ApiException):
#     def __init__(self, value, json_data=None):
#         ApiException.__init__(self, value, '404 Not Found', json_data)
# 
# class Forbidden(ApiException):
#     def __init__(self, value, json_data=None):
#         ApiException.__init__(self, value, '403 Forbidden', json_data)


# Path: turbulenz_local/models/apiv1/datashare.py
import logging
import yaml
from re import compile as regex_compile
from time import time as time
from os import listdir, remove as remove_file
from os.path import join as join_path, splitext, exists as path_exists
from threading import Lock
from pylons import config
from turbulenz_local.tools import get_absolute_path, create_dir
from turbulenz_local.lib.tools import create_id
from turbulenz_local.lib.exceptions import BadRequest, NotFound, Forbidden


            return self._set(key, value, owner, self.read_and_write)

    def get(self, user, key):
        with self.lock:
            self.datashare_access(user)
            if not isinstance(key, unicode):
                raise BadRequest('Key must be a string')

            if not self.validate_key.match(key):
                raise BadRequest('Key can only contain alphanumeric characters hyphens and dots')

            return self.store.get(key)

    def get_keys(self, user):
        with self.lock:
            self.datashare_access(user)
            return [self.key_summary_dict(key) for key in self.store.iterkeys()]

    def set_joinable(self, user, joinable):
        with self.lock:
            self.datashare_access(user)
            self.joinable = joinable
            self.write()

    def reload(self):
        with self.lock:
            try:
                self.load()
            except NotFound:

                self._delete()