kerncraft/kernel.py
def _get_intermediate_file(self, name, machine_and_compiler_dependent=True, binary=False,
                               fp=True):
        """
        Create or open intermediate file (may be used for caching).

        Will replace files older than kernel file, machine file or kerncraft version.

        :param machine_and_compiler_dependent: set to False if file content does not depend on
                                               machine file or compiler settings
        :param fp: if False, will only return file name, not file object
        :paarm binary: if True, use binary mode for file access

        :return: (file object or file name, boolean if already existent and up-to-date)
        """
        if self._filename:
            base_name = os.path.join(os.path.dirname(self._filename),
                                     '.' + os.path.basename(self._filename) + '_kerncraft')
        else:
            base_name = tempfile.mkdtemp()

        if not self._keep_intermediates:
            # Remove directory and all content up on program exit
            atexit.register(shutil.rmtree, base_name)

        if machine_and_compiler_dependent:
            compiler, compiler_args = self._machine.get_compiler()
            compiler_args = '_'.join(compiler_args).replace('/', '')
            base_name += '/{}/{}/{}/'.format(
                self._machine.get_identifier(), compiler, compiler_args)

        # Create dirs recursively
        os.makedirs(base_name, exist_ok=True)

        # Build actual file path
        file_path = os.path.join(base_name, name)

        already_exists = False

        # Check if file exists and is still fresh
        if os.path.exists(file_path):
            file_modified = datetime.utcfromtimestamp(os.stat(file_path).st_mtime)
            if (file_modified < self._machine.get_last_modified_datetime() or
                file_modified < kerncraft.get_last_modified_datetime() or
                (self._filename and
                 file_modified < datetime.utcfromtimestamp(os.stat(self._filename).st_mtime))):
                os.remove(file_path)
            else:
                already_exists = True

        if fp:
            if already_exists:
                mode = 'r+'
            else:
                mode = 'w'
            if binary:
                mode += 'b'
            f = open(file_path, mode)
            return f, already_exists
        else:
            return reduce_path(file_path), already_exists
def _get_intermediate_file(self, name, machine_and_compiler_dependent=True, binary=False,
                               fp=True):
        """
        Create or open intermediate file (may be used for caching).

        Will replace files older than kernel file, machine file or kerncraft version.

        :param machine_and_compiler_dependent: set to False if file content does not depend on
                                               machine file or compiler settings
        :param fp: if False, will only return file name, not file object
        :paarm binary: if True, use binary mode for file access

        :return: (file object or file name, boolean if already existent and up-to-date)
        """
        if self._filename:
            base_name = os.path.join(os.path.dirname(self._filename),
                                     '.' + os.path.basename(self._filename) + '_kerncraft')
        else:
            base_name = tempfile.mkdtemp()

        if not self._keep_intermediates:
            # Remove directory and all content up on program exit
            atexit.register(shutil.rmtree, base_name)

        if machine_and_compiler_dependent:
            compiler, compiler_args = self._machine.get_compiler()
            compiler_args = '_'.join(compiler_args).replace('/', '')
            base_name += '/{}/{}/{}/'.format(
                self._machine.get_identifier(), compiler, compiler_args)

        # Create dirs recursively
        os.makedirs(base_name, exist_ok=True)

        # Build actual file path
        file_path = os.path.join(base_name, name)

        already_exists = False

        # Check if file exists and is still fresh
        if os.path.exists(file_path):
            file_modified = datetime.utcfromtimestamp(os.stat(file_path).st_mtime)
            if (file_modified < self._machine.get_last_modified_datetime() or
                file_modified < kerncraft.get_last_modified_datetime() or
                (self._filename and
                 file_modified < datetime.utcfromtimestamp(os.stat(self._filename).st_mtime))):
                os.remove(file_path)
            else:
                already_exists = True

        if fp:
            if already_exists:
                mode = 'r+'
            else:
                mode = 'w'
            if binary:
                mode += 'b'
            f = open(file_path, mode)
            return f, already_exists
        else:
            return reduce_path(file_path), already_exists
Create or open intermediate file (may be used for caching).

        Will replace files older than kernel file, machine file or kerncraft version.

        :param machine_and_compiler_dependent: set to False if file content does not depend on
                                               machine file or compiler settings
        :param fp: if False, will only return file name, not file object
        :paarm binary: if True, use binary mode for file access

        :return: (file object or file name, boolean if already existent and up-to-date)