Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[![Downloads](https://static.pepy.tech/badge/maya-umbrella)](https://pepy.tech/project/maya-umbrella)
[![Downloads](https://static.pepy.tech/badge/maya-umbrella/month)](https://pepy.tech/project/maya-umbrella)
[![Downloads](https://static.pepy.tech/badge/maya-umbrella/week)](https://pepy.tech/project/maya-umbrella)
[![GitHub Release](https://img.shields.io/github/downloads/loonghao/maya_umbrella/total?label=GitHub%20Downloads)](https://github.com/loonghao/maya_umbrella/releases)
[![License](https://img.shields.io/pypi/l/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
[![PyPI Format](https://img.shields.io/pypi/format/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/loonghao/maya-umbrella/graphs/commit-activity)
Expand Down Expand Up @@ -177,6 +178,34 @@ nox -s maya -- 2018 --install-root /your/local/maya/root

```

## Hooks Control

Disable all hooks. When set to `true`, no hooks will be executed.
```shell
MAYA_UMBRELLA_DISABLE_ALL_HOOKS
```
If you want to disable all hooks:
```shell
SET MAYA_UMBRELLA_DISABLE_ALL_HOOKS=true
```

Disable specific hooks by name. Use a comma-separated list of hook names (without `.py` extension).

Available hooks:
- `delete_turtle` - Remove Turtle plugin and related nodes
- `delete_unknown_plugin_node` - Remove unknown plugin nodes
- `fix_model_panel` - Fix model panel issues
- `fix_no_scene_name` - Fix scenes without names
- `fix_on_model_change_3dc` - Fix 3D Coat model change callback

```shell
MAYA_UMBRELLA_DISABLE_HOOKS
```
For example, to disable the `delete_turtle` and `delete_unknown_plugin_node` hooks:
```shell
SET MAYA_UMBRELLA_DISABLE_HOOKS=delete_turtle,delete_unknown_plugin_node
```

# API

Get virus files that have not been repaired in the current scenario.
Expand Down
29 changes: 29 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[![Downloads](https://static.pepy.tech/badge/maya-umbrella)](https://pepy.tech/project/maya-umbrella)
[![Downloads](https://static.pepy.tech/badge/maya-umbrella/month)](https://pepy.tech/project/maya-umbrella)
[![Downloads](https://static.pepy.tech/badge/maya-umbrella/week)](https://pepy.tech/project/maya-umbrella)
[![GitHub Release](https://img.shields.io/github/downloads/loonghao/maya_umbrella/total?label=GitHub%20Downloads)](https://github.com/loonghao/maya_umbrella/releases)
[![License](https://img.shields.io/pypi/l/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
[![PyPI Format](https://img.shields.io/pypi/format/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/loonghao/maya-umbrella/graphs/commit-activity)
Expand Down Expand Up @@ -165,6 +166,34 @@ nox -s maya -- 2018 --install-root /your/local/maya/root

```

## Hooks 控制

禁用所有 hooks。设置为 `true` 时,不会执行任何 hooks。
```shell
MAYA_UMBRELLA_DISABLE_ALL_HOOKS
```
如果你想禁用所有 hooks:
```shell
SET MAYA_UMBRELLA_DISABLE_ALL_HOOKS=true
```

按名称禁用特定的 hooks。使用逗号分隔的 hook 名称列表(不需要 `.py` 扩展名)。

可用的 hooks:
- `delete_turtle` - 删除 Turtle 插件及相关节点
- `delete_unknown_plugin_node` - 删除未知插件节点
- `fix_model_panel` - 修复模型面板问题
- `fix_no_scene_name` - 修复没有名称的场景
- `fix_on_model_change_3dc` - 修复 3D Coat 模型变更回调

```shell
MAYA_UMBRELLA_DISABLE_HOOKS
```
例如,禁用 `delete_turtle` 和 `delete_unknown_plugin_node` hooks:
```shell
SET MAYA_UMBRELLA_DISABLE_HOOKS=delete_turtle,delete_unknown_plugin_node
```

# API

获取当前场景没有被修复的病毒文件
Expand Down
46 changes: 45 additions & 1 deletion maya_umbrella/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,58 @@ def load_hook(hook_file):
return module


def is_hooks_disabled():
"""Check if all hooks are disabled via environment variable.

Returns:
bool: True if hooks are disabled, False otherwise.
"""
return os.getenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "false").lower() == "true"


def get_disabled_hooks():
"""Get the list of disabled hook names from environment variable.

The environment variable MAYA_UMBRELLA_DISABLE_HOOKS should be a comma-separated
list of hook names (without .py extension).

Example:
SET MAYA_UMBRELLA_DISABLE_HOOKS=delete_turtle,delete_unknown_plugin_node

Returns:
list: A list of disabled hook names.
"""
disabled = os.getenv("MAYA_UMBRELLA_DISABLE_HOOKS", "")
if not disabled:
return []
return [name.strip() for name in disabled.split(",") if name.strip()]


def get_hooks():
"""Return a list of paths to all hook files in the 'hooks' directory.

This function respects the following environment variables:
- MAYA_UMBRELLA_DISABLE_ALL_HOOKS: Set to "true" to disable all hooks.
- MAYA_UMBRELLA_DISABLE_HOOKS: Comma-separated list of hook names to disable.

Returns:
list: A list of paths to all hook files in the 'hooks' directory.
"""
if is_hooks_disabled():
return []

pattern = os.path.join(this_root(), "hooks", "*.py")
return [hook for hook in glob.glob(pattern) if "__init__" not in hook]
disabled_hooks = get_disabled_hooks()

hooks = []
for hook in glob.glob(pattern):
if "__init__" in hook:
continue
hook_name = os.path.basename(hook).replace(".py", "")
if hook_name in disabled_hooks:
continue
hooks.append(hook)
return hooks


def get_vaccines():
Expand Down
88 changes: 88 additions & 0 deletions tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# Import local modules
from maya_umbrella.filesystem import check_virus_file_by_signature
from maya_umbrella.filesystem import get_backup_path
from maya_umbrella.filesystem import get_disabled_hooks
from maya_umbrella.filesystem import get_hooks
from maya_umbrella.filesystem import get_maya_install_root
from maya_umbrella.filesystem import is_hooks_disabled
from maya_umbrella.filesystem import remove_virus_file_by_signature
from maya_umbrella.signatures import FILE_VIRUS_SIGNATURES

Expand Down Expand Up @@ -70,3 +73,88 @@ def test_get_maya_install_root(monkeypatch, mocker):
monkeypatch.setenv("MAYA_LOCATION", "your/maya/install/root")
mocker.patch("os.path.exists", returnn_value=True)
assert get_maya_install_root("1234") == "your/maya/install/root"


def test_is_hooks_disabled_default():
"""Test is_hooks_disabled returns False by default."""
assert is_hooks_disabled() is False


def test_is_hooks_disabled_true(monkeypatch):
"""Test is_hooks_disabled returns True when env var is set."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "true")
assert is_hooks_disabled() is True


def test_is_hooks_disabled_case_insensitive(monkeypatch):
"""Test is_hooks_disabled is case insensitive."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "TRUE")
assert is_hooks_disabled() is True
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "True")
assert is_hooks_disabled() is True


def test_is_hooks_disabled_false(monkeypatch):
"""Test is_hooks_disabled returns False when env var is 'false'."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "false")
assert is_hooks_disabled() is False


def test_get_disabled_hooks_default():
"""Test get_disabled_hooks returns empty list by default."""
assert get_disabled_hooks() == []


def test_get_disabled_hooks_single(monkeypatch):
"""Test get_disabled_hooks with single hook."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle")
assert get_disabled_hooks() == ["delete_turtle"]


def test_get_disabled_hooks_multiple(monkeypatch):
"""Test get_disabled_hooks with multiple hooks."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle,delete_unknown_plugin_node")
assert get_disabled_hooks() == ["delete_turtle", "delete_unknown_plugin_node"]


def test_get_disabled_hooks_with_spaces(monkeypatch):
"""Test get_disabled_hooks handles spaces correctly."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle , delete_unknown_plugin_node")
assert get_disabled_hooks() == ["delete_turtle", "delete_unknown_plugin_node"]


def test_get_disabled_hooks_empty_values(monkeypatch):
"""Test get_disabled_hooks ignores empty values."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle,,delete_unknown_plugin_node,")
assert get_disabled_hooks() == ["delete_turtle", "delete_unknown_plugin_node"]


def test_get_hooks_returns_list():
"""Test get_hooks returns a list of hook files."""
hooks = get_hooks()
assert isinstance(hooks, list)
assert len(hooks) > 0


def test_get_hooks_disabled_all(monkeypatch):
"""Test get_hooks returns empty list when all hooks disabled."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "true")
assert get_hooks() == []


def test_get_hooks_disabled_specific(monkeypatch):
"""Test get_hooks excludes specific disabled hooks."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle")
hooks = get_hooks()
hook_names = [hook.split("\\")[-1].split("/")[-1].replace(".py", "") for hook in hooks]
assert "delete_turtle" not in hook_names
assert len(hooks) > 0


def test_get_hooks_disabled_multiple(monkeypatch):
"""Test get_hooks excludes multiple disabled hooks."""
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle,delete_unknown_plugin_node")
hooks = get_hooks()
hook_names = [hook.split("\\")[-1].split("/")[-1].replace(".py", "") for hook in hooks]
assert "delete_turtle" not in hook_names
assert "delete_unknown_plugin_node" not in hook_names