maya-umbrella 0.3.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. maya_umbrella-0.4.0/PKG-INFO +140 -0
  2. maya_umbrella-0.4.0/README.md +114 -0
  3. maya_umbrella-0.4.0/maya_umbrella/__init__.py +5 -0
  4. maya_umbrella-0.4.0/maya_umbrella/__version__.py +1 -0
  5. maya_umbrella-0.4.0/maya_umbrella/constants.py +5 -0
  6. maya_umbrella-0.4.0/maya_umbrella/core.py +117 -0
  7. {maya_umbrella-0.3.0 → maya_umbrella-0.4.0}/maya_umbrella/filesystem.py +38 -2
  8. {maya_umbrella-0.3.0 → maya_umbrella-0.4.0}/maya_umbrella/hooks/delete_turtle.py +7 -2
  9. {maya_umbrella-0.3.0 → maya_umbrella-0.4.0}/maya_umbrella/hooks/delete_unknown_plugin_node.py +8 -7
  10. {maya_umbrella-0.3.0 → maya_umbrella-0.4.0}/maya_umbrella/hooks/fix_model_panel.py +2 -3
  11. maya_umbrella-0.4.0/maya_umbrella/hooks/fix_on_model_change_3dc.py +19 -0
  12. maya_umbrella-0.4.0/maya_umbrella/log.py +37 -0
  13. maya_umbrella-0.4.0/maya_umbrella/vaccine.py +222 -0
  14. maya_umbrella-0.4.0/maya_umbrella/vaccines/vaccine1.py +17 -0
  15. maya_umbrella-0.4.0/maya_umbrella/vaccines/vaccine2.py +60 -0
  16. maya_umbrella-0.4.0/maya_umbrella/vaccines/vaccine3.py +78 -0
  17. {maya_umbrella-0.3.0 → maya_umbrella-0.4.0}/pyproject.toml +73 -4
  18. maya_umbrella-0.3.0/PKG-INFO +0 -85
  19. maya_umbrella-0.3.0/README.md +0 -59
  20. maya_umbrella-0.3.0/maya_umbrella/__init__.py +0 -5
  21. maya_umbrella-0.3.0/maya_umbrella/__version__.py +0 -1
  22. maya_umbrella-0.3.0/maya_umbrella/core.py +0 -76
  23. maya_umbrella-0.3.0/maya_umbrella/hooks/fix_on_model_change_3dc.py +0 -14
  24. maya_umbrella-0.3.0/maya_umbrella/vaccine.py +0 -80
  25. maya_umbrella-0.3.0/maya_umbrella/vaccines/vaccine1.py +0 -19
  26. maya_umbrella-0.3.0/maya_umbrella/vaccines/vaccine2.py +0 -65
  27. maya_umbrella-0.3.0/maya_umbrella/vaccines/vaccine3.py +0 -110
  28. {maya_umbrella-0.3.0 → maya_umbrella-0.4.0}/LICENSE +0 -0
  29. {maya_umbrella-0.3.0 → maya_umbrella-0.4.0}/maya_umbrella/hooks/__init__.py +0 -0
  30. {maya_umbrella-0.3.0 → maya_umbrella-0.4.0}/maya_umbrella/vaccines/__init__.py +0 -0
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.1
2
+ Name: maya_umbrella
3
+ Version: 0.4.0
4
+ Summary: Check and fix maya virus.
5
+ Home-page: https://github.com/loonghao/maya_umbrella
6
+ License: MIT
7
+ Keywords: notifiers,python,Maya,dcc
8
+ Author: longhao
9
+ Author-email: hal.long@outlook.com
10
+ Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 2
13
+ Classifier: Programming Language :: Python :: 2.7
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.6
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Project-URL: Documentation, https://github.com/loonghao/maya_umbrella
23
+ Project-URL: Repository, https://github.com/loonghao/maya_umbrella
24
+ Description-Content-Type: text/markdown
25
+
26
+ # maya-umbrella
27
+
28
+ [![Python Version](https://img.shields.io/pypi/pyversions/maya-umbrella)](https://img.shields.io/pypi/pyversions/maya-umbrella)
29
+ [![Nox](https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg)](https://github.com/wntrblm/nox)
30
+ [![PyPI Version](https://img.shields.io/pypi/v/maya-umbrella?color=green)](https://pypi.org/project/maya-umbrella/)
31
+ [![Downloads Status](https://img.shields.io/pypi/dw/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
32
+ [![Downloads](https://pepy.tech/badge/maya-umbrella)](https://pepy.tech/project/maya-umbrella)
33
+ [![License](https://img.shields.io/pypi/l/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
34
+ [![PyPI Format](https://img.shields.io/pypi/format/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
35
+ [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/loonghao/maya-umbrella/graphs/commit-activity)
36
+ [![maya-2024](https://img.shields.io/badge/maya-2024-green)](https://img.shields.io/badge/maya-2024-green)
37
+ [![maya-2023](https://img.shields.io/badge/maya-2023-green)](https://img.shields.io/badge/maya-2023-green)
38
+ [![maya-2022](https://img.shields.io/badge/maya-2022-green)](https://img.shields.io/badge/maya-2022-green)
39
+ [![maya-2021](https://img.shields.io/badge/maya-2021-green)](https://img.shields.io/badge/maya-2021-green)
40
+ [![maya-2020](https://img.shields.io/badge/maya-2020-green)](https://img.shields.io/badge/maya-2020-green)
41
+ [![maya-2019](https://img.shields.io/badge/maya-2019-green)](https://img.shields.io/badge/maya-2019-green)
42
+ [![maya-2018](https://img.shields.io/badge/maya-2018-green)](https://img.shields.io/badge/maya-2018-green)
43
+
44
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
45
+ [![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors-)
46
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
47
+
48
+ Check and fix maya virus.
49
+
50
+
51
+ # 发开环境设置
52
+
53
+ python 版本 3.9
54
+
55
+ ```shell
56
+ pip install nox poetry
57
+ ```
58
+
59
+ # 开发调试
60
+
61
+ ```shell
62
+ nox -s maya-2020
63
+ ```
64
+
65
+ ## 在maya中测试
66
+
67
+ 通过`nox -s maya-xxx`, 启动maya.
68
+ nox会动态根据你本地安装得maya去注册nox session, 比如你本地安装了`maya-2020`,那么通过`nox -s maya-2018`
69
+
70
+ 启动maya后在脚本编辑器中执行下面得代码,就会动态的从`<repo>/tests/virus/`里面去open ma文件去进行测试.
71
+
72
+ ```python
73
+ import manual_test_in_maya
74
+
75
+ manual_test_in_maya.start()
76
+ ```
77
+
78
+ ## 增加新的疫苗
79
+
80
+ 在`<repo>/maya_umbrella/vaccines/` 新建一个py, 因为有很多病毒没有具体的名字代号,我们统一以`vaccine<id>.py`
81
+ 继承`from maya_umbrella.vaccine import AbstractVaccine`并且class名字叫`Vaccine`即可, 然后去写具体的收集病毒逻辑
82
+
83
+ ## 代码检查
84
+
85
+ 我们可以利用封装好的`nox`命令去执行进行代码检查
86
+
87
+ ```shell
88
+ nox -s lint
89
+ nox -s black
90
+ nox -s isort
91
+ ```
92
+
93
+ # 环境变量
94
+
95
+ 我们可以通过下列环境变量去修改maya_umbrella的一些设置,方便有pipeline的公司可以更好的集成
96
+
97
+ 修改maya umbrella的日志保存目录,默认是windows temp目录
98
+
99
+ ```shell
100
+ MAYA_UMBRELLA_LOG_ROOT
101
+ ```
102
+
103
+ 修改maya umbrella的日志文件名称, 默认是`maya_umbrella`
104
+
105
+ ```shell
106
+ MAYA_UMBRELLA_LOG_NAME
107
+ ```
108
+
109
+ 设置日志级别,默认是info, 可以是debug可以看到更多的日志信息
110
+
111
+ ```shell
112
+ MAYA_UMBRELLA_LOG_LEVEL
113
+ ```
114
+
115
+ ## Contributors ✨
116
+
117
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
118
+
119
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
120
+ <!-- prettier-ignore-start -->
121
+ <!-- markdownlint-disable -->
122
+ <table>
123
+ <tbody>
124
+ <tr>
125
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/loonghao"><img src="https://avatars1.githubusercontent.com/u/13111745?v=4?s=100" width="100px;" alt="Hal"/><br /><sub><b>Hal</b></sub></a><br /><a href="https://github.com/loonghao/maya_umbrella/commits?author=loonghao" title="Code">💻</a> <a href="#infra-loonghao" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/loonghao/maya_umbrella/commits?author=loonghao" title="Tests">⚠️</a></td>
126
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/hotwinter0"><img src="https://avatars.githubusercontent.com/u/106237305?v=4?s=100" width="100px;" alt="hotwinter0"/><br /><sub><b>hotwinter0</b></sub></a><br /><a href="https://github.com/loonghao/maya_umbrella/commits?author=hotwinter0" title="Tests">⚠️</a> <a href="https://github.com/loonghao/maya_umbrella/commits?author=hotwinter0" title="Code">💻</a></td>
127
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/lingyunfx"><img src="https://avatars.githubusercontent.com/u/73666629?v=4?s=100" width="100px;" alt="lingyunfx"/><br /><sub><b>lingyunfx</b></sub></a><br /><a href="https://github.com/loonghao/maya_umbrella/commits?author=lingyunfx" title="Tests">⚠️</a></td>
128
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/yjjjj"><img src="https://avatars.githubusercontent.com/u/12741735?v=4?s=100" width="100px;" alt="yjjjj"/><br /><sub><b>yjjjj</b></sub></a><br /><a href="https://github.com/loonghao/maya_umbrella/commits?author=yjjjj" title="Tests">⚠️</a> <a href="https://github.com/loonghao/maya_umbrella/commits?author=yjjjj" title="Code">💻</a></td>
129
+ </tr>
130
+ </tbody>
131
+ </table>
132
+
133
+ <!-- markdownlint-restore -->
134
+ <!-- prettier-ignore-end -->
135
+
136
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
137
+
138
+ This project follows the [all-contributors](https://allcontributors.org) specification.
139
+ Contributions of any kind are welcome!
140
+
@@ -0,0 +1,114 @@
1
+ # maya-umbrella
2
+
3
+ [![Python Version](https://img.shields.io/pypi/pyversions/maya-umbrella)](https://img.shields.io/pypi/pyversions/maya-umbrella)
4
+ [![Nox](https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg)](https://github.com/wntrblm/nox)
5
+ [![PyPI Version](https://img.shields.io/pypi/v/maya-umbrella?color=green)](https://pypi.org/project/maya-umbrella/)
6
+ [![Downloads Status](https://img.shields.io/pypi/dw/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
7
+ [![Downloads](https://pepy.tech/badge/maya-umbrella)](https://pepy.tech/project/maya-umbrella)
8
+ [![License](https://img.shields.io/pypi/l/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
9
+ [![PyPI Format](https://img.shields.io/pypi/format/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
10
+ [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/loonghao/maya-umbrella/graphs/commit-activity)
11
+ [![maya-2024](https://img.shields.io/badge/maya-2024-green)](https://img.shields.io/badge/maya-2024-green)
12
+ [![maya-2023](https://img.shields.io/badge/maya-2023-green)](https://img.shields.io/badge/maya-2023-green)
13
+ [![maya-2022](https://img.shields.io/badge/maya-2022-green)](https://img.shields.io/badge/maya-2022-green)
14
+ [![maya-2021](https://img.shields.io/badge/maya-2021-green)](https://img.shields.io/badge/maya-2021-green)
15
+ [![maya-2020](https://img.shields.io/badge/maya-2020-green)](https://img.shields.io/badge/maya-2020-green)
16
+ [![maya-2019](https://img.shields.io/badge/maya-2019-green)](https://img.shields.io/badge/maya-2019-green)
17
+ [![maya-2018](https://img.shields.io/badge/maya-2018-green)](https://img.shields.io/badge/maya-2018-green)
18
+
19
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
20
+ [![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors-)
21
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
22
+
23
+ Check and fix maya virus.
24
+
25
+
26
+ # 发开环境设置
27
+
28
+ python 版本 3.9
29
+
30
+ ```shell
31
+ pip install nox poetry
32
+ ```
33
+
34
+ # 开发调试
35
+
36
+ ```shell
37
+ nox -s maya-2020
38
+ ```
39
+
40
+ ## 在maya中测试
41
+
42
+ 通过`nox -s maya-xxx`, 启动maya.
43
+ nox会动态根据你本地安装得maya去注册nox session, 比如你本地安装了`maya-2020`,那么通过`nox -s maya-2018`
44
+
45
+ 启动maya后在脚本编辑器中执行下面得代码,就会动态的从`<repo>/tests/virus/`里面去open ma文件去进行测试.
46
+
47
+ ```python
48
+ import manual_test_in_maya
49
+
50
+ manual_test_in_maya.start()
51
+ ```
52
+
53
+ ## 增加新的疫苗
54
+
55
+ 在`<repo>/maya_umbrella/vaccines/` 新建一个py, 因为有很多病毒没有具体的名字代号,我们统一以`vaccine<id>.py`
56
+ 继承`from maya_umbrella.vaccine import AbstractVaccine`并且class名字叫`Vaccine`即可, 然后去写具体的收集病毒逻辑
57
+
58
+ ## 代码检查
59
+
60
+ 我们可以利用封装好的`nox`命令去执行进行代码检查
61
+
62
+ ```shell
63
+ nox -s lint
64
+ nox -s black
65
+ nox -s isort
66
+ ```
67
+
68
+ # 环境变量
69
+
70
+ 我们可以通过下列环境变量去修改maya_umbrella的一些设置,方便有pipeline的公司可以更好的集成
71
+
72
+ 修改maya umbrella的日志保存目录,默认是windows temp目录
73
+
74
+ ```shell
75
+ MAYA_UMBRELLA_LOG_ROOT
76
+ ```
77
+
78
+ 修改maya umbrella的日志文件名称, 默认是`maya_umbrella`
79
+
80
+ ```shell
81
+ MAYA_UMBRELLA_LOG_NAME
82
+ ```
83
+
84
+ 设置日志级别,默认是info, 可以是debug可以看到更多的日志信息
85
+
86
+ ```shell
87
+ MAYA_UMBRELLA_LOG_LEVEL
88
+ ```
89
+
90
+ ## Contributors ✨
91
+
92
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
93
+
94
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
95
+ <!-- prettier-ignore-start -->
96
+ <!-- markdownlint-disable -->
97
+ <table>
98
+ <tbody>
99
+ <tr>
100
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/loonghao"><img src="https://avatars1.githubusercontent.com/u/13111745?v=4?s=100" width="100px;" alt="Hal"/><br /><sub><b>Hal</b></sub></a><br /><a href="https://github.com/loonghao/maya_umbrella/commits?author=loonghao" title="Code">💻</a> <a href="#infra-loonghao" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/loonghao/maya_umbrella/commits?author=loonghao" title="Tests">⚠️</a></td>
101
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/hotwinter0"><img src="https://avatars.githubusercontent.com/u/106237305?v=4?s=100" width="100px;" alt="hotwinter0"/><br /><sub><b>hotwinter0</b></sub></a><br /><a href="https://github.com/loonghao/maya_umbrella/commits?author=hotwinter0" title="Tests">⚠️</a> <a href="https://github.com/loonghao/maya_umbrella/commits?author=hotwinter0" title="Code">💻</a></td>
102
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/lingyunfx"><img src="https://avatars.githubusercontent.com/u/73666629?v=4?s=100" width="100px;" alt="lingyunfx"/><br /><sub><b>lingyunfx</b></sub></a><br /><a href="https://github.com/loonghao/maya_umbrella/commits?author=lingyunfx" title="Tests">⚠️</a></td>
103
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/yjjjj"><img src="https://avatars.githubusercontent.com/u/12741735?v=4?s=100" width="100px;" alt="yjjjj"/><br /><sub><b>yjjjj</b></sub></a><br /><a href="https://github.com/loonghao/maya_umbrella/commits?author=yjjjj" title="Tests">⚠️</a> <a href="https://github.com/loonghao/maya_umbrella/commits?author=yjjjj" title="Code">💻</a></td>
104
+ </tr>
105
+ </tbody>
106
+ </table>
107
+
108
+ <!-- markdownlint-restore -->
109
+ <!-- prettier-ignore-end -->
110
+
111
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
112
+
113
+ This project follows the [all-contributors](https://allcontributors.org) specification.
114
+ Contributions of any kind are welcome!
@@ -0,0 +1,5 @@
1
+ # Import local modules
2
+ from maya_umbrella.core import MayaVirusDefender
3
+
4
+
5
+ __all__ = ["MayaVirusDefender"]
@@ -0,0 +1 @@
1
+ __version__ = "0.4.0"
@@ -0,0 +1,5 @@
1
+ PACKAGE_NAME = "maya_umbrella"
2
+
3
+ LOG_FORMAT = "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
4
+
5
+ LOG_MAX_BYTES = 1024 * 1024 * 5
@@ -0,0 +1,117 @@
1
+ # Import built-in modules
2
+ import logging
3
+
4
+ # Import third-party modules
5
+ import maya.api.OpenMaya as om
6
+ import maya.cmds as cmds
7
+
8
+ # Import local modules
9
+ from maya_umbrella.filesystem import get_hooks
10
+ from maya_umbrella.filesystem import get_vaccines
11
+ from maya_umbrella.filesystem import load_hook
12
+ from maya_umbrella.log import setup_logger
13
+ from maya_umbrella.vaccine import MayaVirusCleaner
14
+
15
+
16
+ class MayaVirusDefender(object):
17
+ callback_ids = []
18
+ remove_callbacks = []
19
+ _bad_files = []
20
+ _vaccines = []
21
+ callback_maps = {
22
+ "after_open": om.MSceneMessage.kAfterOpen,
23
+ "maya_initialized": om.MSceneMessage.kMayaInitialized,
24
+ "after_import": om.MSceneMessage.kAfterImport,
25
+ "after_import_reference": om.MSceneMessage.kAfterImportReference,
26
+ "after_load_reference": om.MSceneMessage.kAfterLoadReference,
27
+ "before_save": om.MSceneMessage.kBeforeSave,
28
+ "before_import": om.MSceneMessage.kBeforeImport,
29
+ "before_load_reference": om.MSceneMessage.kBeforeLoadReference,
30
+ "before_import_reference": om.MSceneMessage.kBeforeImportReference,
31
+ "maya_exiting": om.MSceneMessage.kMayaExiting,
32
+ }
33
+
34
+ def __init__(self, auto_fix=True):
35
+ """Initialize the MayaVirusDefender.
36
+
37
+ Args:
38
+ auto_fix (bool): Whether to automatically fix issues.
39
+ """
40
+ logger = logging.getLogger(__name__)
41
+ self.auto_fix = auto_fix
42
+ self.logger = setup_logger(logger)
43
+ self.virus_cleaner = MayaVirusCleaner(self.logger)
44
+ self.load_vaccines()
45
+
46
+ def load_vaccines(self):
47
+ """Load all vaccines."""
48
+ for vaccine in get_vaccines():
49
+ vaccine_class = load_hook(vaccine).Vaccine
50
+ try:
51
+ self._vaccines.append(vaccine_class(api=self.virus_cleaner, logger=self.logger))
52
+ except Exception as e:
53
+ self.logger.error("Error loading vaccine: %s", e)
54
+
55
+ @property
56
+ def vaccines(self):
57
+ """Get all loaded vaccines.
58
+
59
+ Returns:
60
+ list: A list of loaded vaccines.
61
+ """
62
+ return self._vaccines
63
+
64
+ def run_hooks(self):
65
+ """Run all hooks, only works in non-batch mode."""
66
+ if not cmds.about(batch=True):
67
+ for hook_file in get_hooks():
68
+ self.logger.debug("run_hook: %s", hook_file)
69
+ try:
70
+ load_hook(hook_file).hook(self.virus_cleaner)
71
+ except Exception as e:
72
+ self.logger.error("Error running hook: %s", e)
73
+
74
+ def collect(self):
75
+ """Collect all issues related to the Maya virus."""
76
+ for vaccine in self.vaccines:
77
+ vaccine.collect_issues()
78
+
79
+ def fix(self):
80
+ """Fix all issues related to the Maya virus."""
81
+ self.virus_cleaner.fix_all_issues()
82
+
83
+ def report(self):
84
+ """Report all issues related to the Maya virus."""
85
+ self.virus_cleaner.reset_all_issues()
86
+ self.collect()
87
+ self.virus_cleaner.report_all_issues()
88
+
89
+ def setup(self):
90
+ """Set up the MayaVirusDefender."""
91
+ self.virus_cleaner.setup_default_callbacks()
92
+ for name, callbacks in self.virus_cleaner.registered_callbacks.items():
93
+ maya_callback = self.callback_maps[name]
94
+ self.logger.debug("%s setup.", name)
95
+ for func in callbacks:
96
+ self.callback_ids.append(om.MSceneMessage.addCallback(maya_callback, func))
97
+ for name, callbacks in self.callback_maps.items():
98
+ self.logger.debug("setup callback %s.", name)
99
+ self.callback_ids.append(om.MSceneMessage.addCallback(callbacks, self._callback))
100
+
101
+ def _callback(self, *args, **kwargs):
102
+ """Callback function for MayaVirusDefender.
103
+
104
+ Args:
105
+ *args: Variable length argument list.
106
+ **kwargs: Arbitrary keyword arguments.
107
+ """
108
+ if self.auto_fix:
109
+ self.collect()
110
+ self.fix()
111
+ self.run_hooks()
112
+ else:
113
+ self.report()
114
+
115
+ def start(self):
116
+ """Start the MayaVirusDefender."""
117
+ self._callback()
@@ -6,6 +6,10 @@ import os
6
6
  import random
7
7
  import shutil
8
8
  import string
9
+ import tempfile
10
+
11
+ # Import local modules
12
+ from maya_umbrella.constants import PACKAGE_NAME
9
13
 
10
14
 
11
15
  def this_root():
@@ -17,7 +21,7 @@ def safe_remove_file(file_path):
17
21
  """Remove the file at the given path without raising an error if the file does not exist."""
18
22
  try:
19
23
  os.remove(file_path)
20
- except (IOError, OSError):
24
+ except OSError:
21
25
  pass
22
26
 
23
27
 
@@ -25,7 +29,7 @@ def safe_rmtree(path):
25
29
  """Remove the directory at the given path without raising an error if the directory does not exist."""
26
30
  try:
27
31
  shutil.rmtree(path)
28
- except (IOError, OSError):
32
+ except OSError:
29
33
  pass
30
34
 
31
35
 
@@ -106,5 +110,37 @@ def get_hooks():
106
110
 
107
111
 
108
112
  def get_vaccines():
113
+ """
114
+ Get a list of all vaccine files.
115
+
116
+ Returns:
117
+ list: A list of vaccine files.
118
+ """
109
119
  pattern = os.path.join(this_root(), "vaccines", "*.py")
110
120
  return [vaccine for vaccine in glob.glob(pattern) if "__init__" not in vaccine]
121
+
122
+
123
+ def get_log_root():
124
+ """
125
+ Get the log root directory.
126
+
127
+ Returns:
128
+ str: The log root directory.
129
+ """
130
+ return os.getenv("MAYA_UMBRELLA_LOG_ROOT", tempfile.gettempdir())
131
+
132
+
133
+ def get_log_file():
134
+ """
135
+ Get the path of the log file.
136
+
137
+ Returns:
138
+ str: The path of the log file.
139
+ """
140
+ root = get_log_root()
141
+ try:
142
+ os.makedirs(root)
143
+ except OSError:
144
+ pass
145
+ name = os.getenv("MAYA_UMBRELLA_LOG_NAME", PACKAGE_NAME)
146
+ return os.path.join(root, "{name}.log".format(name=name))
@@ -3,11 +3,16 @@ import maya.cmds as cmds
3
3
  import maya.mel as mel
4
4
 
5
5
 
6
- def hook(logger):
6
+ def hook(virus_cleaner):
7
7
  for plugin in ["Turtle.mll", "mayatomr.mll"]:
8
8
  if cmds.pluginInfo(plugin, q=1, loaded=1):
9
9
  cmds.unloadPlugin(plugin, f=1)
10
- turtle_nodes = ["TurtleRenderOptions", "TurtleUIOptions", "TurtleBakeLayerManager", "TurtleDefaultBakeLayer"]
10
+ turtle_nodes = [
11
+ "TurtleRenderOptions",
12
+ "TurtleUIOptions",
13
+ "TurtleBakeLayerManager",
14
+ "TurtleDefaultBakeLayer",
15
+ ]
11
16
  for node in turtle_nodes:
12
17
  if cmds.objExists(node):
13
18
  cmds.lockNode(node, lock=1)
@@ -2,28 +2,29 @@
2
2
  import maya.cmds as cmds
3
3
 
4
4
 
5
- def hook(logger):
5
+ def hook(virus_cleaner):
6
6
  unknown_node = cmds.ls(type="unknown")
7
7
  unknown_plugin = cmds.unknownPlugin(query=True, l=True)
8
8
  if unknown_node:
9
9
  for nodeObj in unknown_node:
10
10
  if cmds.objExists(nodeObj):
11
11
  if cmds.referenceQuery(nodeObj, isNodeReferenced=True):
12
- logger.warning("Node from reference, skip. {}".format(nodeObj))
12
+ virus_cleaner.logger.warning("Node from reference, skip. {}".format(nodeObj))
13
13
  continue
14
14
  if cmds.lockNode(nodeObj, query=True)[0]:
15
15
  try:
16
16
  cmds.lockNode(nodeObj, lock=False)
17
- except Exception as e:
18
- logger.warning("The node is locked and cannot be unlocked. skip {}".format(nodeObj))
17
+ except Exception:
18
+ virus_cleaner.logger.warning(
19
+ "The node is locked and cannot be unlocked. skip {}".format(nodeObj))
19
20
  continue
20
21
  try:
21
22
  cmds.delete(nodeObj)
22
- logger.warning("Delete node : {}".format(nodeObj))
23
- except Exception as e:
23
+ virus_cleaner.logger.warning("Delete node: {}".format(nodeObj))
24
+ except Exception:
24
25
  pass
25
26
 
26
27
  if unknown_plugin:
27
28
  for plugObj in unknown_plugin:
28
29
  cmds.unknownPlugin(plugObj, remove=True)
29
- logger.warning("Delete plug-in : {}".format(plugObj))
30
+ virus_cleaner.logger.warning("Delete plug-in: {}".format(plugObj))
@@ -2,13 +2,12 @@
2
2
  import maya.cmds as cmds
3
3
 
4
4
 
5
- def hook(logger):
5
+ def hook(virus_cleaner):
6
6
  for model_panel in cmds.getPanel(typ="modelPanel"):
7
-
8
7
  # Get callback of the model editor
9
8
  callback = cmds.modelEditor(model_panel, query=True, editorChanged=True)
10
9
 
11
10
  # If the callback is the erroneous `CgAbBlastPanelOptChangeCallback`
12
11
  if callback == "CgAbBlastPanelOptChangeCallback":
13
- # Remove the callbacks from the editor
12
+ virus_cleaner.logger.info("Remove the callbacks from the editor")
14
13
  cmds.modelEditor(model_panel, edit=True, editorChanged="")
@@ -0,0 +1,19 @@
1
+ # Import third-party modules
2
+ import maya.cmds as cmds
3
+ import maya.mel as mel
4
+
5
+
6
+ def hook(virus_cleaner):
7
+ try:
8
+ mel.eval("global proc onModelChange3dc(string $a){}")
9
+ except Exception:
10
+ pass
11
+ try:
12
+ cmds.delete("fixCgAbBlastPanelOptChangeCallback")
13
+ except Exception:
14
+ pass
15
+ try:
16
+ script = "global proc CgAbBlastPanelOptChangeCallback(string $i){}"
17
+ mel.eval(script)
18
+ except Exception:
19
+ pass
@@ -0,0 +1,37 @@
1
+ # Import built-in modules
2
+ import logging.handlers
3
+ import os
4
+
5
+ # Import local modules
6
+ from maya_umbrella.constants import LOG_FORMAT
7
+ from maya_umbrella.constants import LOG_MAX_BYTES
8
+ from maya_umbrella.constants import PACKAGE_NAME
9
+ from maya_umbrella.filesystem import get_log_file
10
+
11
+
12
+ def setup_logger(logger=None, logfile=None, log_level=None):
13
+ """Set up the logger with the specified log file and log level.
14
+
15
+ Args:
16
+ logger (logging.Logger, optional): The logger to set up. Defaults to the logger for the package.
17
+ logfile (str, optional): The path to the log file. Defaults to the log file returned by `get_log_file()`.
18
+ log_level (int, optional): The log level. Defaults to `logging.INFO`.
19
+
20
+ Returns:
21
+ logging.Logger: The set up logger.
22
+ """
23
+ logger = logger or logging.getLogger(PACKAGE_NAME)
24
+ log_level = log_level or os.getenv("MAYA_UMBRELLA_LOG_LEVEL", "INFO")
25
+ logger.setLevel(log_level)
26
+ logfile = logfile or get_log_file()
27
+ if not len(logger.handlers):
28
+ filehandler = logging.handlers.RotatingFileHandler(
29
+ logfile,
30
+ mode="a",
31
+ backupCount=7,
32
+ delay=True,
33
+ maxBytes=LOG_MAX_BYTES,
34
+ )
35
+ filehandler.setFormatter(logging.Formatter(LOG_FORMAT))
36
+ logger.addHandler(filehandler)
37
+ return logger