diff --git a/README.md b/README.md index a1b2f56..7d25fe1 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ and it is recommended to use Python 3.8 or higher versions. 通过虚拟环境去设置开发环境, 推荐python-3.8以上的版本 +通过pip安装相关开发依赖 + ```shell pip install -r requirements-dev.txt ``` @@ -109,7 +111,9 @@ nox -s lint-fx # 生成安装包 执行下面的命令可以在/.zip下面创建zip,参数 `--version` 当前工具的版本号 - **注意:`make-zip` 与 `--version`之间有 俩个`-`** + +**注意:`make-zip` 与 `--version`之间有 俩个`-`** + ```shell nox -s make-zip -- --version 0.5.0 ``` @@ -188,13 +192,16 @@ print(api.scan_files_from_pattern("your/path/*.m[ab]")) ``` # 案例 -如果你想要快速通过maya standalone去批量清理maya文件,可以`下载`或者`git clone`当前`main`分支的工程, -根据上面指引设置好开发环境 -通过`nox`命令去启动maya `standalone`环境,maya版本根据你当前本地安装的maya为准,比如你本地安装了`2018`, +如果你想要快速通过maya standalone去批量清理maya文件, +可以`下载`或者`git clone`当前`main`分支的工程, +根据上面指引设置好开发环境, +通过`nox`命令去启动maya `standalone`环境,maya版本根据你当前本地安装的maya为准, +比如你本地安装了`2018`, 那么就是 `nox -s maya -- 2018 --standalone` 下面的语法是启动一个maya-2020的环境去动态从`c:/test`文件夹下去查杀病毒 + ```shell -nox -s maya-2020-s -- c:/test/*.m[ab] +nox -s maya -- 2018 --standalone --pattern c:/test/*.m[ab] ``` ## Contributors ✨ diff --git a/maya_umbrella/__init__.py b/maya_umbrella/__init__.py index e21b312..9b1385c 100644 --- a/maya_umbrella/__init__.py +++ b/maya_umbrella/__init__.py @@ -6,6 +6,7 @@ from maya_umbrella.defender import get_defender_instance from maya_umbrella.scanner import MayaVirusScanner + # All public APIs. __all__ = [ "MayaVirusDefender", diff --git a/maya_umbrella/defender.py b/maya_umbrella/defender.py index 56ae1ca..e46f539 100644 --- a/maya_umbrella/defender.py +++ b/maya_umbrella/defender.py @@ -164,7 +164,11 @@ def context_defender(): def get_defender_instance(): - """Get the MayaVirusDefender instance.""" + """Get the MayaVirusDefender instance. + + Returns: + MayaVirusDefender: The MayaVirusDefender instance. + """ global MAYA_UMBRELLA_DEFENDER if MAYA_UMBRELLA_DEFENDER is None: MAYA_UMBRELLA_DEFENDER = MayaVirusDefender() diff --git a/maya_umbrella/filesystem.py b/maya_umbrella/filesystem.py index 8d0b858..1bb0ff8 100644 --- a/maya_umbrella/filesystem.py +++ b/maya_umbrella/filesystem.py @@ -4,6 +4,7 @@ import glob import importlib import json +import logging import os import random import re @@ -43,10 +44,20 @@ def safe_rmtree(path): def _codes_open(path, encoding="utf-8"): - # Import built-in modules - with codecs.open(path, "r", encoding) as file_: - return file_.read() + """Open and read the content of a file using the specified encoding. + Args: + path (str): Path to the file. + encoding (str, optional): The encoding to use when reading the file. Defaults to "utf-8". + + Returns: + str: The content of the file, or an empty string if the file could not be read. + """ + try: + with codecs.open(path, "r", encoding) as file_: + return file_.read() + except (OSError, IOError): # noqa: UP024 + return "" def read_file(path): """Read the content of the file at the given path.""" @@ -78,12 +89,6 @@ def write_file(path, content): file_.write(content) -def _codes_write(path, content, encoding="utf-8"): - # Import built-in modules - with codecs.open(path, "w", encoding) as file_: - file_.write(content) - - @contextmanager def atomic_writes(src, mode, **options): """Context manager for atomic writes to a file. @@ -102,7 +107,7 @@ def atomic_writes(src, mode, **options): AttributeError: If the os module does not have the 'replace' function (Python 2 compatibility). """ temp_path = os.path.join(os.path.dirname(src), "._{}".format(id_generator())) - open_func = open if PY3 else _codes_open + open_func = open if PY3 else codecs.open with open_func(temp_path, mode, **options) as f: yield f try: @@ -295,6 +300,7 @@ def get_backup_path(path, root_path=None): def get_maya_install_root(maya_version): """Get the Maya install root path.""" + logger = logging.getLogger(__name__) maya_location = os.getenv("MAYA_LOCATION") try: # Import built-in modules @@ -308,14 +314,14 @@ def get_maya_install_root(maya_version): ) root, _ = winreg.QueryValueEx(key, "MAYA_INSTALL_LOCATION") if not os.path.isdir(root): - print("Failed to locate the appropriate Maya path in the registration list.") + logger.info("Failed to locate the appropriate Maya path in the registration list.") except OSError: return maya_location maya_location = maya_location or root if not maya_location: - print("maya not found.") + logger.info("maya not found.") return maya_exe = os.path.join(maya_location, "bin", "maya.exe") if not os.path.exists(maya_exe): - print("maya.exe not found in {maya_location}.".format(maya_location=maya_location)) + logger.info("maya.exe not found in {maya_location}.".format(maya_location=maya_location)) return maya_location diff --git a/maya_umbrella/vaccines/vaccine3.py b/maya_umbrella/vaccines/vaccine3.py index ea9b770..559b9c3 100644 --- a/maya_umbrella/vaccines/vaccine3.py +++ b/maya_umbrella/vaccines/vaccine3.py @@ -20,6 +20,14 @@ class Vaccine(AbstractVaccine): @staticmethod def is_infected(script_node): + """Check if a script node is infected with a virus. + + Args: + script_node (str): The name of the script node to check. + + Returns: + bool: True if the script node is infected, False otherwise. + """ if "_gene" in script_node: return True if "uifiguration" in script_node: diff --git a/nox_actions/utils.py b/nox_actions/utils.py index 3bdb912..264711e 100644 --- a/nox_actions/utils.py +++ b/nox_actions/utils.py @@ -8,4 +8,12 @@ def _assemble_env_paths(*paths): + """Assemble environment paths separated by a semicolon. + + Args: + *paths: Paths to be assembled. + + Returns: + str: Assembled paths separated by a semicolon. + """ return ";".join(paths)