# 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 os
from pylons import config
from os.path import join as join_path
from turbulenz_local.tools import get_absolute_path, create_dir
                raise UserDataError

        # keys and values
        #for key_file in key_files:
        #    try:
        #        f = open(unicode(join_path(self.path, key_file)), 'r')
        #        (key, ext) = os.path.splitext(key_file)
        #        if (ext == '.txt'):
        #            try:
        #                list_array.append({
        #                    'key': key,
        #                    'value': f.read()
        #                    })
        #            finally:
        #                f.close()
        #    except IOError, e:
        #        LOG.error('Failed listing userdata: %s', str(e))
        #        raise UserDataError

        return list_array


    def exists(self, key):
        key_path = join_path(self.path, key + '.txt')
        return os.path.exists(key_path)


    def get(self, key):
        key_path = join_path(self.path, key + '.txt')
        try:

# 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/userdata.py
import logging
import os
from pylons import config
from os.path import join as join_path
from turbulenz_local.tools import get_absolute_path, create_dir

                raise UserDataError

        # keys and values
        #for key_file in key_files:
        #    try:
        #        f = open(unicode(join_path(self.path, key_file)), 'r')
        #        (key, ext) = os.path.splitext(key_file)
        #        if (ext == '.txt'):
        #            try:
        #                list_array.append({
        #                    'key': key,
        #                    'value': f.read()
        #                    })
        #            finally:
        #                f.close()
        #    except IOError, e:
        #        LOG.error('Failed listing userdata: %s', str(e))
        #        raise UserDataError

        return list_array


    def exists(self, key):
        key_path = join_path(self.path, key + '.txt')
        return os.path.exists(key_path)


    def get(self, key):
        key_path = join_path(self.path, key + '.txt')
        try:

            f = open(unicode(key_path), 'r')