<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2012-2015, <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 shutil

import pymel.core as pm
import maya.cmds as mc
import time

from anima import logger
from anima.env import empty_reference_resolution
from anima.env.base import EnvironmentBase
from anima.env.mayaEnv import extension  # register extensions
from anima.exc import PublishError
from anima.repr import Representation
from anima.ui.progress_dialog import ProgressDialogManager

# empty publishers first
from anima.env.mayaEnv import publish as publish_scripts  # register publishers
reload(publish_scripts)

from anima.publish import (run_publishers, staging, PRE_PUBLISHER_TYPE,
                           POST_PUBLISHER_TYPE)


class Maya(EnvironmentBase):
    """The maya environment class

    .. versionadded:: 0.1.7
       Shallow Reference Updates

       With version 0.1.7 all the scene references are updated *shallowly*,
       that is no new versions are going to be created as opposed to
       **Deep Reference Updates**. With **Shallow Reference Update**, all the
       references in current scene is updated in place. So if a new version of
       a Version is present, Maya will update it to that version in the current
       scene without creating new intermediate versions. This makes things much
       simple and easy to manage.

    .. deprecated::
       Deep Reference Updates

       Deep reference updates are deprecated. Use shallow reference updates.

    """

    name = "Maya%s" % str(pm.versions.current())[0:4]
    representations = ['Base', 'GPU', 'ASS']

    time_to_fps = {
        u'sec': 1,
        u'2fps': 2,
        u'3fps': 3,
        u'4fps': 4,
        u'5fps': 5,
        u'6fps': 6,
        u'8fps': 8,
        u'10fps': 10,
        u'12fps': 12,
        u'game': 15,
        u'16fps': 16,
        u'20fps': 20,
        u'film': 24,
        u'pal': 25,
        u'ntsc': 30,
        u'40fps': 40,
        u'show': 48,
        u'palf': 50,
        u'ntscf': 60,
        u'75fps': 75,
        u'80fps': 80,
        u'100fps': 100,
        u'120fps': 120,
        u'125fps': 125,
        u'150fps': 150,
        u'200fps': 200,
        u'240fps': 240,
        u'250fps': 250,
        u'300fps': 300,
        u'375fps': 375,
        u'400fps': 400,
        u'500fps': 500,
        u'600fps': 600,
        u'750fps': 750,
        u'millisec': 1000,
        u'1200fps': 1200,
        u'1500fps': 1500,
        u'2000fps': 2000,
        u'3000fps': 3000,
        u'6000fps': 6000,
    }

    maya_workspace_file_content = """
workspace -fr "3dPaintTextures" ".mayaFiles/sourceimages/3dPaintTextures/";
workspace -fr "Adobe(R) Illustrator(R)" ".mayaFiles/data/";
workspace -fr "aliasWire" ".mayaFiles/data/";
workspace -fr "animImport" ".mayaFiles/data/";
workspace -fr "animExport" ".mayaFiles/data/";
workspace -fr "audio" ".mayaFiles/sound/";
workspace -fr "autoSave" ".mayaFiles/autosave/";
workspace -fr "clips" ".mayaFiles/clips/";
workspace -fr "DAE_FBX" ".mayaFiles/data/";
workspace -fr "DAE_FBX export" ".mayaFiles/data/";
workspace -fr "depth" ".mayaFiles/renderData/depth/";
workspace -fr "diskCache" ".mayaFiles/cache/";
workspace -fr "DXF" ".mayaFiles/data/";
workspace -fr "DXF export" ".mayaFiles/data/";
workspace -fr "DXF_FBX" ".mayaFiles/data/";
workspace -fr "DXF_FBX export" ".mayaFiles/data/";
workspace -fr "eps" ".mayaFiles/data/";
workspace -fr "EPS" ".mayaFiles/data/";
workspace -fr "FBX" ".mayaFiles/data/";
workspace -fr "FBX export" ".mayaFiles/data/";
workspace -fr "fluidCache" ".mayaFiles/cache/fluid/";
workspace -fr "furAttrMap" ".mayaFiles/renderData/fur/furAttrMap/";
workspace -fr "furEqualMap" ".mayaFiles/renderData/fur/furEqualMap/";
workspace -fr "furFiles" ".mayaFiles/renderData/fur/furFiles/";
workspace -fr "furImages" ".mayaFiles/renderData/fur/furImages/";
workspace -fr "furShadowMap" ".mayaFiles/renderData/fur/furShadowMap/";
workspace -fr "IGES" ".mayaFiles/data/";
workspace -fr "IGESexport" ".mayaFiles/data/";
workspace -fr "illustrator" ".mayaFiles/data/";
workspace -fr "image" ".mayaFiles/images/";
workspace -fr "images" ".mayaFiles/images/";
workspace -fr "iprImages" ".mayaFiles/renderData/iprImages/";
workspace -fr "lights" ".mayaFiles/renderData/shaders/";
workspace -fr "mayaAscii" ".mayaFiles/scenes/";
workspace -fr "mayaBinary" ".mayaFiles/scenes/";
workspace -fr "mel" ".mayaFiles/scripts/";
workspace -fr "mentalray" ".mayaFiles/renderData/mentalray/";
workspace -fr "mentalRay" ".mayaFiles/renderData/mentalray";
workspace -fr "move" ".mayaFiles/data/";
workspace -fr "movie" ".mayaFiles/movies/";
workspace -fr "OBJ" ".mayaFiles/data/";
workspace -fr "OBJexport" ".mayaFiles/data/";
workspace -fr "offlineEdit" ".mayaFiles/scenes/edits/";
workspace -fr "particles" ".mayaFiles/particles/";
workspace -fr "renderData" ".mayaFiles/renderData/";
workspace -fr "renderScenes" ".mayaFiles/scenes/";
workspace -fr "RIB" ".mayaFiles/data/";
workspace -fr "RIBexport" ".mayaFiles/data/";
workspace -fr "scene" ".mayaFiles/scenes/";
workspace -fr "scripts" ".mayaFiles/scripts/";
workspace -fr "shaders" ".mayaFiles/renderData/shaders/";
workspace -fr "sound" ".mayaFiles/sound/";
workspace -fr "sourceImages" ".mayaFiles/sourceimages/";
workspace -fr "templates" ".mayaFiles/assets/";
workspace -fr "textures" ".mayaFiles/images/";
workspace -fr "translatorData" ".mayaFiles/data/";
"""

    executable = {
        'windows': 'maya',
        'linux': 'maya',
        'osx': 'maya'
    }

    def __init__(self, extensions=None, version=None):
        #super(Maya, self).__init__(self.name, extensions, version)
        EnvironmentBase.__init__(self, self.name, extensions, version)

        self.use_progress_window = False
        if not pm.general.about(batch=1):
            self.use_progress_window = True

        self.set_arnold_texture_search_path()

    def set_arnold_texture_search_path(self):
        """sets environment defaults
        """
        start = time.time()
        from stalker import Repository

        # try to get a version from current scene
        v = self.get_current_version()

        if v:
            # just append the project repo
            all_repos = [v.task.project.repository]
        else:
            # no version append all repositories
            all_repos = Repository.query.all()

        try:
            # add all repo paths to Arnold Texture search path
            texture_search_path = []
            for repo in all_repos:
                texture_search_path.append(repo.windows_path)
                texture_search_path.append(repo.linux_path)

            texture_search_path = ';'.join(texture_search_path)

            dARO = pm.PyNode('defaultArnoldRenderOptions')
            dARO.setAttr('texture_searchpath', texture_search_path)
        except pm.MayaNodeError:
            pass

        end = time.time()
        logger.debug('set_arnold_texture_search_path() took '
                     '%f seconds' % (end - start))

    def save_as(self, version):
        """The save_as action for maya environment.

        It saves the given Version instance to the Version.absolute_full_path.
        """
        start = time.time()
        if version.is_published:
            # before doing anything run all publishers
            type_name = ''
            if version.task.type:<commit_msg>Update: Updated ``anima.env.mayaEnv.Maya.set_arnold_texture_search_path()`` method to add all the repositories to the search path.<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2012-2015, <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 shutil

import pymel.core as pm
import maya.cmds as mc
import time

from anima import logger
from anima.env import empty_reference_resolution
from anima.env.base import EnvironmentBase
from anima.env.mayaEnv import extension  # register extensions
from anima.exc import PublishError
from anima.repr import Representation
from anima.ui.progress_dialog import ProgressDialogManager

# empty publishers first
from anima.env.mayaEnv import publish as publish_scripts  # register publishers
reload(publish_scripts)

from anima.publish import (run_publishers, staging, PRE_PUBLISHER_TYPE,
                           POST_PUBLISHER_TYPE)


class Maya(EnvironmentBase):
    """The maya environment class

    .. versionadded:: 0.1.7
       Shallow Reference Updates

       With version 0.1.7 all the scene references are updated *shallowly*,
       that is no new versions are going to be created as opposed to
       **Deep Reference Updates**. With **Shallow Reference Update**, all the
       references in current scene is updated in place. So if a new version of
       a Version is present, Maya will update it to that version in the current
       scene without creating new intermediate versions. This makes things much
       simple and easy to manage.

    .. deprecated::
       Deep Reference Updates

       Deep reference updates are deprecated. Use shallow reference updates.

    """

    name = "Maya%s" % str(pm.versions.current())[0:4]
    representations = ['Base', 'GPU', 'ASS']

    time_to_fps = {
        u'sec': 1,
        u'2fps': 2,
        u'3fps': 3,
        u'4fps': 4,
        u'5fps': 5,
        u'6fps': 6,
        u'8fps': 8,
        u'10fps': 10,
        u'12fps': 12,
        u'game': 15,
        u'16fps': 16,
        u'20fps': 20,
        u'film': 24,
        u'pal': 25,
        u'ntsc': 30,
        u'40fps': 40,
        u'show': 48,
        u'palf': 50,
        u'ntscf': 60,
        u'75fps': 75,
        u'80fps': 80,
        u'100fps': 100,
        u'120fps': 120,
        u'125fps': 125,
        u'150fps': 150,
        u'200fps': 200,
        u'240fps': 240,
        u'250fps': 250,
        u'300fps': 300,
        u'375fps': 375,
        u'400fps': 400,
        u'500fps': 500,
        u'600fps': 600,
        u'750fps': 750,
        u'millisec': 1000,
        u'1200fps': 1200,
        u'1500fps': 1500,
        u'2000fps': 2000,
        u'3000fps': 3000,
        u'6000fps': 6000,
    }

    maya_workspace_file_content = """
workspace -fr "3dPaintTextures" ".mayaFiles/sourceimages/3dPaintTextures/";
workspace -fr "Adobe(R) Illustrator(R)" ".mayaFiles/data/";
workspace -fr "aliasWire" ".mayaFiles/data/";
workspace -fr "animImport" ".mayaFiles/data/";
workspace -fr "animExport" ".mayaFiles/data/";
workspace -fr "audio" ".mayaFiles/sound/";
workspace -fr "autoSave" ".mayaFiles/autosave/";
workspace -fr "clips" ".mayaFiles/clips/";
workspace -fr "DAE_FBX" ".mayaFiles/data/";
workspace -fr "DAE_FBX export" ".mayaFiles/data/";
workspace -fr "depth" ".mayaFiles/renderData/depth/";
workspace -fr "diskCache" ".mayaFiles/cache/";
workspace -fr "DXF" ".mayaFiles/data/";
workspace -fr "DXF export" ".mayaFiles/data/";
workspace -fr "DXF_FBX" ".mayaFiles/data/";
workspace -fr "DXF_FBX export" ".mayaFiles/data/";
workspace -fr "eps" ".mayaFiles/data/";
workspace -fr "EPS" ".mayaFiles/data/";
workspace -fr "FBX" ".mayaFiles/data/";
workspace -fr "FBX export" ".mayaFiles/data/";
workspace -fr "fluidCache" ".mayaFiles/cache/fluid/";
workspace -fr "furAttrMap" ".mayaFiles/renderData/fur/furAttrMap/";
workspace -fr "furEqualMap" ".mayaFiles/renderData/fur/furEqualMap/";
workspace -fr "furFiles" ".mayaFiles/renderData/fur/furFiles/";
workspace -fr "furImages" ".mayaFiles/renderData/fur/furImages/";
workspace -fr "furShadowMap" ".mayaFiles/renderData/fur/furShadowMap/";
workspace -fr "IGES" ".mayaFiles/data/";
workspace -fr "IGESexport" ".mayaFiles/data/";
workspace -fr "illustrator" ".mayaFiles/data/";
workspace -fr "image" ".mayaFiles/images/";
workspace -fr "images" ".mayaFiles/images/";
workspace -fr "iprImages" ".mayaFiles/renderData/iprImages/";
workspace -fr "lights" ".mayaFiles/renderData/shaders/";
workspace -fr "mayaAscii" ".mayaFiles/scenes/";
workspace -fr "mayaBinary" ".mayaFiles/scenes/";
workspace -fr "mel" ".mayaFiles/scripts/";
workspace -fr "mentalray" ".mayaFiles/renderData/mentalray/";
workspace -fr "mentalRay" ".mayaFiles/renderData/mentalray";
workspace -fr "move" ".mayaFiles/data/";
workspace -fr "movie" ".mayaFiles/movies/";
workspace -fr "OBJ" ".mayaFiles/data/";
workspace -fr "OBJexport" ".mayaFiles/data/";
workspace -fr "offlineEdit" ".mayaFiles/scenes/edits/";
workspace -fr "particles" ".mayaFiles/particles/";
workspace -fr "renderData" ".mayaFiles/renderData/";
workspace -fr "renderScenes" ".mayaFiles/scenes/";
workspace -fr "RIB" ".mayaFiles/data/";
workspace -fr "RIBexport" ".mayaFiles/data/";
workspace -fr "scene" ".mayaFiles/scenes/";
workspace -fr "scripts" ".mayaFiles/scripts/";
workspace -fr "shaders" ".mayaFiles/renderData/shaders/";
workspace -fr "sound" ".mayaFiles/sound/";
workspace -fr "sourceImages" ".mayaFiles/sourceimages/";
workspace -fr "templates" ".mayaFiles/assets/";
workspace -fr "textures" ".mayaFiles/images/";
workspace -fr "translatorData" ".mayaFiles/data/";
"""

    executable = {
        'windows': 'maya',
        'linux': 'maya',
        'osx': 'maya'
    }

    def __init__(self, extensions=None, version=None):
        #super(Maya, self).__init__(self.name, extensions, version)
        EnvironmentBase.__init__(self, self.name, extensions, version)

        self.use_progress_window = False
        if not pm.general.about(batch=1):
            self.use_progress_window = True

        self.set_arnold_texture_search_path()

    def set_arnold_texture_search_path(self):
        """sets environment defaults
        """
        start = time.time()
        from stalker import Repository

        # try to get a version from current scene
        # v = self.get_current_version()

        # if v:
        #     # just append the project repo
        #     all_repos = [v.task.project.repository]
        # else:
        #    # no version append all repositories
        all_repos = Repository.query.all()

        try:
            # add all repo paths to Arnold Texture search path
            texture_search_path = []
            for repo in all_repos:
                texture_search_path.append(repo.windows_path)
                texture_search_path.append(repo.linux_path)

            texture_search_path = ';'.join(texture_search_path)

            dARO = pm.PyNode('defaultArnoldRenderOptions')
            dARO.setAttr('texture_searchpath', texture_search_path)
        except pm.MayaNodeError:
            pass

        end = time.time()
        logger.debug('set_arnold_texture_search_path() took '
                     '%f seconds' % (end - start))

    def save_as(self, version):
        """The save_as action for maya environment.

        It saves the given Version instance to the Version.absolute_full_path.
        """
        start = time.time()
        if version.is_published:
            # before doing anything run all publishers
            type_name = ''
            if version.task.type:
{'fraction_non_alphanumeric': 0.13197296939181133, 'fraction_numerical': 0.026368093282098846, 'mean_word_length': 2.8754813863928113, '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': '4413513', 'n_tokens_mistral': 5385, 'n_tokens_neox': 4956, 'n_words': 1279}