# Path: mycroft/util/file_utils.py
# def get_temp_path(*args):
#     """Generate a valid path in the system temp directory.
# 
#     This method accepts one or more strings as arguments. The arguments are
#     joined and returned as a complete path inside the systems temp directory.
#     Importantly, this will not create any directories or files.
# 
#     Example usage: get_temp_path('mycroft', 'audio', 'example.wav')
#     Will return the equivalent of: '/tmp/mycroft/audio/example.wav'
# 
#     Args:
#         path_element (str): directories and/or filename
# 
#     Returns:
#         (str) a valid path in the systems temp directory
#     """
#     try:
#         path = os.path.join(tempfile.gettempdir(), *args)
#     except TypeError:
#         raise TypeError("Could not create a temp path, get_temp_path() only "
#                         "accepts Strings")
#     return path


import json
import os
import re
import xdg.BaseDirectory
from os.path import exists, isfile, join, dirname
from requests import RequestException
from mycroft.util.combo_lock import ComboLock
from mycroft.util.file_utils import get_temp_path
from mycroft.util import camel_case_split
from mycroft.util.json_helper import load_commented_json, merge_dict
from mycroft.util.log import LOG
from .locations import (
    DEFAULT_CONFIG,
    OLD_USER_CONFIG,
    SYSTEM_CONFIG,
    USER_CONFIG
)
        from mycroft.api import is_paired
            from mycroft.api import DeviceApi
                    where the config was loaded.
        force (bool): Set to True if writing should occur despite the original
                      was malformed.

        Returns:
            (bool) True if save was successful, else False.
        """
        result = False
        with self._lock:
            path = path or self.path
            config_dir = dirname(path)
            if not exists(config_dir):
                os.makedirs(config_dir)

            if self.is_valid or force:
                with open(path, 'w') as f:
                    json.dump(self, f, indent=2)
                result = True
            else:
                LOG.warning((f'"{path}" was not a valid config file when '
                             'loaded, will not save config. Please correct '
                             'the json or remove it to allow updates.'))
                result = False
        return result

    def merge(self, conf):
        merge_dict(self, conf)


class RemoteConf(LocalConf):

# Path: mycroft/util/file_utils.py
# def get_temp_path(*args):
#     """Generate a valid path in the system temp directory.
# 
#     This method accepts one or more strings as arguments. The arguments are
#     joined and returned as a complete path inside the systems temp directory.
#     Importantly, this will not create any directories or files.
# 
#     Example usage: get_temp_path('mycroft', 'audio', 'example.wav')
#     Will return the equivalent of: '/tmp/mycroft/audio/example.wav'
# 
#     Args:
#         path_element (str): directories and/or filename
# 
#     Returns:
#         (str) a valid path in the systems temp directory
#     """
#     try:
#         path = os.path.join(tempfile.gettempdir(), *args)
#     except TypeError:
#         raise TypeError("Could not create a temp path, get_temp_path() only "
#                         "accepts Strings")
#     return path


# Path: mycroft/configuration/config.py
import json
import os
import re
import xdg.BaseDirectory
from os.path import exists, isfile, join, dirname
from requests import RequestException
from mycroft.util.combo_lock import ComboLock
from mycroft.util.file_utils import get_temp_path
from mycroft.util import camel_case_split
from mycroft.util.json_helper import load_commented_json, merge_dict
from mycroft.util.log import LOG
from .locations import (
    DEFAULT_CONFIG,
    OLD_USER_CONFIG,
    SYSTEM_CONFIG,
    USER_CONFIG
)
        from mycroft.api import is_paired
            from mycroft.api import DeviceApi

                    where the config was loaded.
        force (bool): Set to True if writing should occur despite the original
                      was malformed.

        Returns:
            (bool) True if save was successful, else False.
        """
        result = False
        with self._lock:
            path = path or self.path
            config_dir = dirname(path)
            if not exists(config_dir):
                os.makedirs(config_dir)

            if self.is_valid or force:
                with open(path, 'w') as f:
                    json.dump(self, f, indent=2)
                result = True
            else:
                LOG.warning((f'"{path}" was not a valid config file when '
                             'loaded, will not save config. Please correct '
                             'the json or remove it to allow updates.'))
                result = False
        return result

    def merge(self, conf):
        merge_dict(self, conf)


class RemoteConf(LocalConf):

    _lock = ComboLock(get_temp_path('remote-conf.lock'))