<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2012-2013, <NAME>
#
# This module is part of anima-tools and is released under the BSD 2
# License: http://www.opensource.org/licenses/BSD-2-Clause

import os
import re

import hou
from stalker.db import DBSession

from anima.pipeline import utils
from stalker.models.env import EnvironmentBase

import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)


class Houdini(EnvironmentBase):
    """the houdini environment class
    """

    name = 'Houdini'

    def save_as(self, version):
        """the save action for houdini environment
        """
        if not version:
            return

        from stalker import Version
        assert isinstance(version, Version)

        # get the current version, and store it as the parent of the new version
        current_version = self.get_current_version()

        # initialize path variables by using update_paths()
        version.update_paths()

        # set the extension to hip
        version.extension = '.hip'

        # define that this version is created with Houdini
        version.created_with = self.name

        # create the folder if it doesn't exists
        try:
            os.makedirs(
                os.path.dirname(
                    version.absolute_full_path
                )
            )
        except OSError:
            # dirs exist
            pass

        # houdini uses / instead of \ under windows
        # lets fix it

        # *************************************************************
        # trying to set the render file name while the file has not been
        # saved before creates an error
        # so save the file two times if it is not saved before

        # check if the HIP environment variable has some data
        #if os.environ["HIP"] == os.environ["HOME"]:
        #    # save the file to create a meaningful HIP variable
        #    hou.hipFile.save(file_name=str(version.absolute_full_path))

        # set the environment variables
        self.set_environment_variables(version)

        # set the render file name
        self.set_render_filename(version)

        # houdini accepts only strings as file name, no unicode support as I
        # see
        hou.hipFile.save(file_name=str(version.absolute_full_path))

        # set the environment variables again
        self.set_environment_variables(version)

        # update the parent info
        if current_version:
            version.parent = current_version

            # update database with new version info
            DBSession.commit()

        return True

    def open_(self, version, force=False):
        """the open action for houdini environment
        """
        if not version:
            return

        if hou.hipFile.hasUnsavedChanges() and not force:
            raise RuntimeError

        hou.hipFile.load(
            file_name=str(version.absolute_full_path),
            suppress_save_prompt=True
        )

        # set the environment variables
        self.set_environment_variables(version)

        return True, []

    def post_open(self, version):
        """just skip it
        """
        return

    def import_(self, version):
        """the import action for houdini environment
        """
        hou.hipFile.merge(str(version.absolute_full_path))
        return True

    def get_current_version(self):
        """Returns the currently opened Version instance
        """
        version = None
        full_path = hou.hipFile.name()
        if full_path != 'untitled.hip':
            version = self.get_version_from_full_path(full_path)
        return version

    def get_version_from_recent_files(self):
        """returns the version from the recent files
        """
        version = None
        recent_files = self.get_recent_file_list()
        for i in range(len(recent_files) - 1, 0, -1):
            version = self.get_version_from_full_path(recent_files[i])
            if version:
                break
        return version<commit_msg>houdiniEnv is now able to store the environment variables without saving the file twice<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2012-2013, <NAME>
#
# This module is part of anima-tools and is released under the BSD 2
# License: http://www.opensource.org/licenses/BSD-2-Clause

import os
import re

import hou
from stalker.db import DBSession

from anima.pipeline import utils
from stalker.models.env import EnvironmentBase

import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)


class Houdini(EnvironmentBase):
    """the houdini environment class
    """

    name = 'Houdini'

    def save_as(self, version):
        """the save action for houdini environment
        """
        if not version:
            return

        from stalker import Version
        assert isinstance(version, Version)

        # get the current version, and store it as the parent of the new version
        current_version = self.get_current_version()

        # initialize path variables by using update_paths()
        version.update_paths()

        # set the extension to hip
        version.extension = '.hip'

        # define that this version is created with Houdini
        version.created_with = self.name

        # create the folder if it doesn't exists
        try:
            os.makedirs(
                os.path.dirname(
                    version.absolute_full_path
                )
            )
        except OSError:
            # dirs exist
            pass

        # houdini uses / instead of \ under windows
        # lets fix it

        # *************************************************************
        # trying to set the render file name while the file has not been
        # saved before creates an error
        # so save the file two times if it is not saved before

        # check if the HIP environment variable has some data
        #if os.environ["HIP"] == os.environ["HOME"]:
        #    # save the file to create a meaningful HIP variable
        #    hou.hipFile.save(file_name=str(version.absolute_full_path))

        # set the environment variables
        self.set_environment_variables(version)

        # set the render file name
        self.set_render_filename(version)

        # houdini accepts only strings as file name, no unicode support as I
        # see
        hou.hipFile.save(file_name=str(version.absolute_full_path))

        # set the environment variables again
        self.set_environment_variables(version)

        # update the parent info
        if current_version:
            version.parent = current_version

            # update database with new version info
            DBSession.commit()

        return True

    def open_(self, version, force=False):
        """the open action for houdini environment
        """
        if not version:
            return

        if hou.hipFile.hasUnsavedChanges() and not force:
            raise RuntimeError

        hou.hipFile.load(
            file_name=str(version.absolute_full_path),
            suppress_save_prompt=True
        )

        # set the environment variables
        self.set_environment_variables(version)

        return True, []

    def post_open(self, version):
        """just skip it
        """
        return

    def import_(self, version):
        """the import action for houdini environment
        """
        hou.hipFile.merge(str(version.absolute_full_path))
        return True

    def get_current_version(self):
        """Returns the currently opened Version instance
        """
        version = None
        full_path = hou.hipFile.name()
        if full_path != 'untitled.hip':
            version = self.get_version_from_full_path(full_path)
        return version

    def get_version_from_recent_files(self):
        """returns the version from the recent files
        """
        version = None
        recent_files = self.get_recent_file_list()
        for i in range(len(recent_files) - 1, 0, -1):
            version = self.get_version_from_full_path(
                os.path.expandvars(recent_files[i])
            )
            if version:
                break
        return version
{'fraction_non_alphanumeric': 0.08500847662872366, 'fraction_numerical': 0.0033906514894647614, 'mean_word_length': 2.1025544703230654, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2208377', 'n_tokens_mistral': 2200, 'n_tokens_neox': 2100, 'n_words': 681}