Skip to content

Commit

Permalink
ci: Update python-publish.yml
Browse files Browse the repository at this point in the history
Signed-off-by: loonghao <[email protected]>
  • Loading branch information
loonghao committed May 8, 2024
1 parent 3e2d615 commit 77414a4
Show file tree
Hide file tree
Showing 16 changed files with 17,083 additions and 16,978 deletions.
45 changes: 38 additions & 7 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ jobs:
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
contents: write

steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
token: "${{ secrets.GITHUB_TOKEN }}"
fetch-depth: 0
ref: main
- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- uses: olegtarasov/[email protected]
id: get_tag_name
with:
tagRegex: "v(?<version>.*)"
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -35,7 +38,35 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
- name: Create release Version
run: gh release create ${{ steps.vars.outputs.tag }} --generate-notes
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: make Maya Mod
id: make_maya_mod
run: |
nox -s make-zip -- --version ${{ steps.get_tag_name.outputs.version }}
- name: Generate changelog
id: changelog
uses: jaywcjlove/changelog-generator@main
if: steps.get_tag_name.outputs.successful
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
filter-author: (|dependabot|renovate\\[bot\\]|dependabot\\[bot\\]|Renovate Bot)
filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}'
template: |
## Bugs
{{fix}}
## Feature
{{feat}}
## Improve
{{refactor,perf,clean}}
## Misc
{{chore,style,ci||🔶 Nothing change}}
## Unknown
{{__unknown__}}
- uses: ncipollo/release-action@v1
if: steps.make_maya_mod.outputs.successful
with:
artifacts: ".zip/maya_umbrella-*.zip"
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
body: |
Comparing Changes: ${{ steps.changelog.outputs.compareurl }}
${{ steps.changelog.outputs.changelog }}
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ maya_umbrella是以标准pipy包去发布的,所以我们可以通过pip insta
```shell
your/maya-root/mayapy -m pip install maya-umbrella
```
更新版本
```shell
your/maya-root/mayapy -m pip install maya-umbrella --upgrade
```
卸载
```shell
your/maya-root/mayapy -m pip uninstall maya-umbrella
```

# 开发环境设置

Expand Down Expand Up @@ -105,7 +113,7 @@ MAYA_UMBRELLA_LOG_NAME
```shell
MAYA_UMBRELLA_LOG_LEVEL
```
修改杀毒后文件的备份文件夹名称, 默认是`_maya_umbrella`
修改杀毒后文件的备份文件夹名称, 默认是`_virus`
比如:
你文件路径是 `c:/your/path/file.ma`
那么备份文件路径是 `c:/your/path/_maya_umbrella/file.ma`
Expand All @@ -117,7 +125,7 @@ MAYA_UMBRELLA_BACKUP_FOLDER_NAME
MAYA_UMBRELLA_LANG
```

忽略保存到备份文件夹,*请注意,如果你不清楚这个会导致的后果请不要轻易修改*默认批量杀毒后会自动保存到当前文件的备份文件夹.
忽略保存到备份文件夹,*请注意,如果你不清楚这个会导致的后果请不要轻易修改*默认批量杀毒后会把源文件自动备份到当前文件的备份文件夹.
```shell
MAYA_UMBRELLA_IGNORE_BACKUP
```
Expand Down
15 changes: 8 additions & 7 deletions maya_umbrella/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def __init__(self, collector, logger=None):

def callback_remove_rename_temp_files(self, *args, **kwargs):
"""Remove temporary files in the local script path."""
self.logger.info("Removing temporary files in %s", self.collector.local_script_path)
self.logger.debug("Removing temporary files in %s", self.collector.local_script_path)
for temp_file in glob.glob(os.path.join(self.collector.local_script_path, "._*")):
safe_remove_file(temp_file)

def fix_script_jobs(self):
"""Fix infected script jobs."""
for script_job in self.collector.infected_script_jobs:
script_num = int(re.findall(r"^(\d+):", script_job)[0])
self.logger.info("Kill script job %s", script_job)
self.logger.debug("Kill script job %s", script_job)
cmds.scriptJob(kill=script_num, force=True)
self.collector.remove_infected_script_job(script_job)

Expand All @@ -52,21 +52,21 @@ def fix_malicious_files(self):
for file_ in self.collector.malicious_files:
if os.path.exists(file_):
if os.path.isfile(file_):
self.logger.info("Removing %s", file_)
self.logger.debug(self.translator.translate("remove_file", name=file_))
safe_remove_file(file_)
self.collector.remove_malicious_file(file_)
else:
self.logger.info("Removing folder %s", file_)
self.logger.debug(self.translator.translate("remove_path", name=file_))
safe_rmtree(file_)
self.collector.remove_malicious_file(file_)

def fix_infected_nodes(self):
"""Fix infected nodes."""
for node in self.collector.infected_nodes:
self.logger.info(self.translator.translate("delete", name=node))
is_referenced = check_reference_node_exists(node)
if is_referenced:
try:
self.logger.debug(self.translator.translate("fix_infected_reference_nodes", name=node))
cmds.setAttr("{node}.before".format(node=node), "", type="string")
cmds.setAttr("{node}.after".format(node=node), "", type="string")
cmds.setAttr("{node}.scriptType".format(node=node), 0)
Expand All @@ -79,6 +79,7 @@ def fix_infected_nodes(self):
except ValueError:
pass
try:
self.logger.debug(self.translator.translate("fix_infected_nodes", name=node))
cmds.delete(node)
except ValueError:
pass
Expand All @@ -100,11 +101,11 @@ def fix(self):
"""Fix all issues related to the Maya virus."""
if self.collector.have_issues:
maya_file = cmds.file(query=True, sceneName=True, shortName=True) or "empty/scene"
self.logger.info("Starting Fixing all issues related to the Maya virus from %s.", maya_file)
self.logger.info(self.translator.translate("start_fix_issues", name=maya_file))
self.fix_malicious_files()
self.fix_infected_files()
self.fix_infected_nodes()
self.fix_script_jobs()
for func in self.collector.get_additionally_fix_funcs():
func()
self.logger.info("Finished Fixing all issues related to the Maya virus from %s.", maya_file)
self.logger.info(self.translator.translate("finish_fix_issues", name=maya_file))
1 change: 1 addition & 0 deletions maya_umbrella/defender.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# Global list to store IDs of Maya callbacks
MAYA_UMBRELLA_CALLBACK_IDS = []


def _add_callbacks_id(id_):
"""Add a callback ID to the global list if it's not already present.
Expand Down
15 changes: 11 additions & 4 deletions maya_umbrella/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def remove_virus_file_by_signature(file_path, signatures, output_file_path=None)
Args:
file_path (str): Path to the file to be cleaned.
signatures (list): List of signatures to match and remove.
output_file_path (str, optional): Path to the cleaned output file. Defaults to None, which overwrites the input file.
output_file_path (str, optional): Path to the cleaned output file.
Defaults to None, which overwrites the input file.
"""
data = read_file(file_path)
if check_virus_by_signature(data, signatures):
Expand Down Expand Up @@ -240,11 +241,14 @@ def check_virus_by_signature(content, signatures=None):
return False


def get_backup_path(path):
"""Get the backup path for a given file path based on environment variables.
def get_backup_path(path, root_path=None):
"""
Get the backup path for a given file path based on environment variables.
Args:
path (str): Path to the original file.
root_path (str, optional): Path to the root folder where backups should be saved.
Defaults to None, which saves backups in the original file's folder.
Returns:
str: The backup path.
Expand All @@ -253,8 +257,11 @@ def get_backup_path(path):
if ignore_backup:
return path
root, filename = os.path.split(path)
backup_folder_name = os.getenv("MAYA_UMBRELLA_BACKUP_FOLDER_NAME", "_umbrella_backup")
backup_folder_name = os.getenv("MAYA_UMBRELLA_BACKUP_FOLDER_NAME", "_virus")
backup_path = os.path.join(root, backup_folder_name)
if root_path:
_, base_path = os.path.splitdrive(root)
backup_path = os.path.join(root_path, base_path.strip(os.sep))
try:
os.makedirs(backup_path)
except (OSError, IOError): # noqa: UP024
Expand Down
7 changes: 6 additions & 1 deletion maya_umbrella/locales/en_US.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"start_fix_issues": "Start fixing all problems related to Maya virus $name",
"finish_fix_issues": "Done.",
"init_message": "Successfully loaded <hl>maya_umbrella</hl> under protection.",
"init_standalone_message": "-----------------------Loading maya_umbrella successfully----------------------",
"report_issue": "$name: Infected by Malware!",
Expand All @@ -8,7 +9,11 @@
"infected_script_jobs": "Infected script jobs: $name",
"infected_files": "Infected files: $name",
"infected_reference_files": "Infected reference files: $name",
"fix_infected_files": "Deleting infected files: $name",
"fix_infected_files": "Clean infected files: $name",
"fix_infected_nodes": "Delete infected nodes:$name",
"fix_infected_reference_nodes": "trying fix infected nodes from reference:$name",
"delete": "Deleting: $name",
"remove_file": "Deleting file:$name",
"remove_path": "Deleting path:$name",
"fix_script_job": "Kill script job: %s"
}
5 changes: 5 additions & 0 deletions maya_umbrella/locales/zh_CN.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"start_fix_issues": "开始修复与 Maya 病毒相关的所有问题 $name",
"finish_fix_issues": "修复结束.",
"init_message": "成功加载 <hl>maya_umbrella</hl> 保护中.",
"init_standalone_message": "-----------------------成功加载 maya_umbrella-----------------------",
"report_issue": "$name:被恶意感染!",
Expand All @@ -9,6 +10,10 @@
"infected_files": "被感染的脚本:$name",
"infected_reference_files": "被感染的参考文件:$name",
"fix_infected_files": "清理被感染的文件:$name",
"fix_infected_nodes": "删除被感染的节点:$name",
"fix_infected_reference_nodes": "尝试修复被感染的参考节点:$name",
"delete": "删除感染文件:$name",
"remove_file": "删除文件:$name",
"remove_path": "删除文件夹:$name",
"fix_script_job": "删除被感染的节点:$name"
}
27 changes: 23 additions & 4 deletions maya_umbrella/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import glob
import logging
import os
import shutil

# Import local modules
from maya_umbrella import maya_funs
from maya_umbrella.defender import context_defender
from maya_umbrella.filesystem import get_backup_path
from maya_umbrella.filesystem import read_file
from maya_umbrella.maya_funs import cmds


Expand All @@ -19,18 +21,22 @@ class MayaVirusScanner(object):
logger (Logger): Logger object for logging purposes.
defender (MayaVirusDefender): MayaVirusDefender object for fixing issues.
_env (dict): Custom environment variables.
output_path (str, optional): Path to save the fixed files. Defaults to None, which overwrites the original
files.
"""


def __init__(self, env=None):
def __init__(self, output_path=None, env=None):
"""Initialize the MayaVirusScanner.
Args:
output_path (str, optional): Path to save the fixed files. Defaults to None, which overwrites the original
files.
env (dict, optional): Custom environment variables. Defaults to None,
which sets the 'MAYA_COLOR_MANAGEMENT_SYNCOLOR' variable to '1'.
"""
self.logger = logging.getLogger(__name__)
self.defender = None
self.output_path = output_path
self._failed_files = []
self._fixed_files = []
# Custom env.
Expand All @@ -45,7 +51,7 @@ def scan_files_from_pattern(self, pattern):
pattern (str): The file pattern to match.
"""
os.environ.update(self._env)
self.scan_files_from_list(glob.iglob(pattern))
return self.scan_files_from_list(glob.iglob(pattern))

def scan_files_from_list(self, files):
"""Scan and fix Maya files from a given list.
Expand All @@ -57,6 +63,17 @@ def scan_files_from_list(self, files):
self.defender = defender
for maya_file in files:
self._fix(maya_file)
return self._fixed_files

def scan_files_from_file(self, text_file):
"""Scan and fix Maya files from a given text file containing a list of file paths.
Args:
text_file (str): Path to the text file containing the list of file paths.
"""
file_data = read_file(text_file)
files = file_data.splitlines()
return self.scan_files_from_list(files)

def _fix(self, maya_file):
"""Fix a single Maya file containing a virus.
Expand All @@ -74,7 +91,9 @@ def _fix(self, maya_file):
self._failed_files.append(maya_file)
if self.defender.have_issues:
self.defender.fix()
maya_funs.save_as_file(get_backup_path(maya_file))
backup_path = get_backup_path(maya_file, root_path=self.output_path)
shutil.copy2(maya_file, backup_path)
cmds.file(s=True, f=True)
self._fixed_files.append(maya_file)
cmds.file(new=True, force=True)
for ref in self.defender.collector.infected_reference_files:
Expand Down
6 changes: 4 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,11 @@ def make_install_zip(session: nox.Session):
shutil.copy2(os.path.join(ROOT, "maya", "userSetup.py"),
os.path.join(script_dir, "userSetup.py"))

with zipfile.ZipFile(os.path.join(temp_dir, f"{PACKAGE_NAME}-{version}.zip"), "w") as zip:
zip_file = os.path.join(temp_dir, f"{PACKAGE_NAME}-{version}.zip")
with zipfile.ZipFile(os.path.join(temp_dir, f"{PACKAGE_NAME}-{version}.zip"), "w") as zip_obj:
for root, _, files in os.walk(build_root):
for file in files:
zip.write(os.path.join(root, file),
zip_obj.write(os.path.join(root, file),
os.path.relpath(os.path.join(root, file),
os.path.join(build_root, '.')))
print("Saving to %s" % zip_file)
Loading

0 comments on commit 77414a4

Please sign in to comment.