# Path: turbulenz_local/models/userlist.py
# def get_user(self, username):
#     username_lower = username.lower()
#     with self.lock:
#         try:
#             return self.users[username_lower]
#         except KeyError:
#             LOG.info('No user with username "%s" adding user with defaults', username)
#             try:
#                 user = self._add_user(username_lower)
#                 self._write_users()
#                 return user
#             except ValueError as e:
#                 raise BadRequest(str(e))
# 
# 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)


from logging import getLogger
from pylons import config
from os import remove, listdir, rmdir
from os.path import join as join_path, exists as path_exists
from threading import Lock
from turbulenz_local.models.userlist import get_user
from turbulenz_local.tools import get_absolute_path, create_dir
import yaml
            with open(default_yaml_path, 'r') as f:
                try:
                    file_defaults = yaml.load(f)
                    self.defaults = dict((v['user'], v['value']) for v in file_defaults['profiles'])
                except (yaml.YAMLError, KeyError, TypeError) as e:
                    LOG.error('Failed loading default game profiles: %s', str(e))


    def get(self, usernames):
        path = self.path
        game_profiles = {}
        with self.lock:
            for username in usernames:
                profile_path = join_path(path, username + '.txt')
                try:
                    with open(unicode(profile_path), 'r') as fin:
                        value = fin.read()
                except IOError:
                    if username in self.defaults:
                        value = self.defaults[username]
                    else:
                        continue
                game_profiles[username] = {'value': value}
        return {'profiles': game_profiles}


    def set(self, value):
        profile_path = join_path(self.path, self.user.username + '.txt')
        with self.lock:
            try:

# Path: turbulenz_local/models/userlist.py
# def get_user(self, username):
#     username_lower = username.lower()
#     with self.lock:
#         try:
#             return self.users[username_lower]
#         except KeyError:
#             LOG.info('No user with username "%s" adding user with defaults', username)
#             try:
#                 user = self._add_user(username_lower)
#                 self._write_users()
#                 return user
#             except ValueError as e:
#                 raise BadRequest(str(e))
# 
# 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/gameprofile.py
from logging import getLogger
from pylons import config
from os import remove, listdir, rmdir
from os.path import join as join_path, exists as path_exists
from threading import Lock
from turbulenz_local.models.userlist import get_user
from turbulenz_local.tools import get_absolute_path, create_dir
import yaml

            with open(default_yaml_path, 'r') as f:
                try:
                    file_defaults = yaml.load(f)
                    self.defaults = dict((v['user'], v['value']) for v in file_defaults['profiles'])
                except (yaml.YAMLError, KeyError, TypeError) as e:
                    LOG.error('Failed loading default game profiles: %s', str(e))


    def get(self, usernames):
        path = self.path
        game_profiles = {}
        with self.lock:
            for username in usernames:
                profile_path = join_path(path, username + '.txt')
                try:
                    with open(unicode(profile_path), 'r') as fin:
                        value = fin.read()
                except IOError:
                    if username in self.defaults:
                        value = self.defaults[username]
                    else:
                        continue
                game_profiles[username] = {'value': value}
        return {'profiles': game_profiles}


    def set(self, value):
        profile_path = join_path(self.path, self.user.username + '.txt')
        with self.lock:
            try:

                with open(unicode(profile_path), 'w') as fout: