Ejemplo n.º 1
0
    def save_settings(self, verbose=0):
        """Save current settings to disk.

        Args:
            verbose (int): print process data
        """
        _settings = self._read_settings()
        if verbose > 1:
            pprint.pprint(_settings)
        dprint('Saved settings', self.settings_file, verbose=verbose)
        write_yaml(file_=self.settings_file, data=_settings, force=True)
Ejemplo n.º 2
0
    def set_metadata(self, data):
        """Set metadata for this work area, writing yaml to disk.

        Args:
            data (dict): metadata to write
        """
        assert len(data['workfiles']) == len(self.get_metadata()['workfiles'])
        _tmp_yaml = '{}/metadata.yaml'.format(tempfile.gettempdir())
        write_yaml(data=data, file_=_tmp_yaml)
        if not os.path.getsize(self.yaml) - 20 < os.path.getsize(_tmp_yaml):
            print os.path.getsize(self.yaml), self.yaml
            print os.path.getsize(_tmp_yaml), _tmp_yaml
            diff(_tmp_yaml, self.yaml)
            raise ValueError("Losing data")
        shutil.copy(_tmp_yaml, self.yaml)
Ejemplo n.º 3
0
    def cache_write(self, tag, data, bkp=False, verbose=0):
        """Write data to the given cache.

        Args:
            tag (str): tag to store data to
            data (any): data to store
            bkp (bool): save timestamped backup file on save (if data changed)
            verbose (int): print process data

        Returns:
            (str): path to cache file
        """
        from psyhive.utils import File, write_yaml

        _file = File(self.cache_fmt.format(tag))
        lprint('WRITE CACHE FILE', _file.path, verbose=verbose)

        if bkp and _file.exists():
            _data = self.cache_read(tag)
            if _data == data:
                lprint(' - DATA UNCHANGED, NO BKP REQUIRED')
            else:
                lprint(' - STORE BKP', _data)

                _bkp = '{}/_bkp_{}_{}.{}'.format(
                    _file.dir, _file.basename, time.strftime('%y%m%d_%H%M%S'),
                    _file.extn)
                lprint(' - BKP', _bkp)
                shutil.copy(_file.path, _bkp)

        if _file.extn == 'yml':
            write_yaml(file_=_file, data=data)
        else:
            obj_write(file_=_file.path, obj=data)

        return _file.path
Ejemplo n.º 4
0
def build_shader_outputs(output, force=True, verbose=1):
    """Build shader outputs for the given shade asset.

    This consists of:

        - mb file containing just shaders for this asset
        - yml file containing list of shaders
        - standin file containing shaders attached to aiStandIn node

    Args:
        output (str): path to aiStandIn output
        force (bool): overrwrite existing files without confirmation
        verbose (int): print process data

    Returns:
        (str): path to output file
    """
    lprint('BUILD aiStandIn MA', output, verbose=verbose)

    # Get paths for standin + rest cache + shade
    _out = tk2.TTOutput(output)
    _shaders = _out.map_to(tk2.TTOutputFile, format='shaders', extension='mb')
    _yml = _out.map_to(tk2.TTOutputFile, format='shaders', extension='yml')
    _standin = _out.map_to(tk2.TTOutputFile,
                           format='aistandin',
                           extension='ma')
    _ver = tk2.TTOutputVersion(output)
    _rest_cache = get_single(_ver.find(extn='abc', filter_='restCache'),
                             catch=True)
    _shade = _ver.find_file(extn='mb', format_='maya')
    lprint(' - VER       ', _ver.path, verbose=verbose)
    lprint(' - SHADE     ', _shade.path, verbose=verbose)
    lprint(' - REST CACHE', _rest_cache, verbose=verbose)
    lprint(' - STANDIN   ', _standin.path, verbose=verbose)
    lprint(' - SHADERS   ', _shaders.path, verbose=verbose)
    assert not _shade == _out.path

    # Build aiStandIn node
    lprint(' - OPENING SHADE SCENE', verbose=verbose)
    host.open_scene(_shade.path, force=True)
    build_aistandin_from_shade(archive=_rest_cache,
                               shade=_ShadeScene(),
                               animated=False,
                               name='AIS',
                               deferred=False)

    # Remove + save aistandin
    cmds.delete('GEO')
    host.save_as(file_=_standin.path, force=force)

    # Remove standin + save shaders
    if cmds.objExists('AIS'):
        cmds.delete('AIS')
    _ses = [
        str(_se) for _se in cmds.ls(type='shadingEngine')
        if _se not in DEFAULT_NODES
    ]
    lprint(" - SHADING ENGINES", _ses, verbose=verbose)
    host.save_as(_shaders.path, force=force)
    write_yaml(file_=_yml.path, data=_ses, force=True)

    return _standin.path