mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
ifcgit.git_diff - save diff to temp file on alt-click
This commit is contained in:
@@ -4,6 +4,7 @@ import bpy
|
||||
import bonsai.core.ifcgit as core
|
||||
import bonsai.tool as tool
|
||||
from bonsai.bim.module.ifcgit.data import IfcGitData, refresh
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
||||
class CreateRepo(bpy.types.Operator):
|
||||
@@ -410,12 +411,20 @@ class InstallGit(bpy.types.Operator):
|
||||
|
||||
|
||||
class RunGitDiff(bpy.types.Operator):
|
||||
"""Run `git diff` for the current version of IFC file and the last saved one."""
|
||||
|
||||
bl_label = "Git Diff"
|
||||
bl_idname = "ifcgit.git_diff"
|
||||
bl_description = (
|
||||
"Run `git diff` for the current version of IFC file and the last saved one.\n\n"
|
||||
"ALT+click to save output to temp directory."
|
||||
)
|
||||
bl_options = set()
|
||||
|
||||
save_to_temp: bpy.props.BoolProperty(options={"SKIP_SAVE"}) # pyright: ignore[reportRedeclaration]
|
||||
|
||||
if TYPE_CHECKING:
|
||||
save_to_temp: bool
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
if not tool.Ifc.get():
|
||||
@@ -426,6 +435,11 @@ class RunGitDiff(bpy.types.Operator):
|
||||
return False
|
||||
return True
|
||||
|
||||
def invoke(self, context, event):
|
||||
if event.alt:
|
||||
self.save_to_temp = True
|
||||
return self.execute(context)
|
||||
|
||||
def execute(self, context):
|
||||
core.run_git_diff(tool.IfcGit, self)
|
||||
core.run_git_diff(tool.IfcGit, self, self.save_to_temp)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -144,5 +144,5 @@ def install_git(ifcgit: type[tool.IfcGit], operator: bpy.types.Operator) -> None
|
||||
print("install_git() not implemented")
|
||||
|
||||
|
||||
def run_git_diff(ifcgit: type[tool.IfcGit], operator: bpy.types.Operator) -> None:
|
||||
ifcgit.run_git_diff(operator)
|
||||
def run_git_diff(ifcgit: type[tool.IfcGit], operator: bpy.types.Operator, save_to_temp: bool) -> None:
|
||||
ifcgit.run_git_diff(operator, save_to_temp)
|
||||
|
||||
@@ -22,9 +22,11 @@ import re
|
||||
import subprocess
|
||||
import bpy
|
||||
import logging
|
||||
import tempfile
|
||||
from bonsai.bim import import_ifc
|
||||
from bonsai.bim.ifc import IfcStore
|
||||
import bonsai.tool as tool
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Union, Literal, Any
|
||||
|
||||
# allows git import even if git executable isn't found
|
||||
@@ -582,21 +584,27 @@ class IfcGit:
|
||||
operator.report({"ERROR"}, "Winget is not available. Make sure Windows Package Manager is installed.")
|
||||
|
||||
@classmethod
|
||||
def run_git_diff(cls, operator: bpy.types.Operator) -> None:
|
||||
def run_git_diff(cls, operator: bpy.types.Operator, save_to_temp: bool) -> None:
|
||||
path = tool.Ifc.get_path()
|
||||
ifc_file = tool.Ifc.get()
|
||||
ifc_str = ifc_file.to_string()
|
||||
|
||||
color = "never" if save_to_temp else "always"
|
||||
# Avoid `text=True` as it's causing issues with colorful output.
|
||||
try:
|
||||
subprocess.check_output(
|
||||
("git", "diff", "--no-index", "--color=always", "--", path, "-"),
|
||||
("git", "diff", "--no-index", f"--color={color}", "--", path, "-"),
|
||||
input=ifc_str.encode(),
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
if e.returncode == 1:
|
||||
print(e.stdout.decode())
|
||||
operator.report({"INFO"}, "See system console for git diff output.")
|
||||
if save_to_temp:
|
||||
temp_path = Path(tempfile.gettempdir()) / "bonsai.diff"
|
||||
temp_path.write_bytes(e.stdout)
|
||||
operator.report({"INFO"}, f"Git diff output is saved to {temp_path}.")
|
||||
else:
|
||||
print(e.stdout.decode())
|
||||
operator.report({"INFO"}, "See system console for git diff output.")
|
||||
return
|
||||
print(e.output)
|
||||
raise Exception("Error running git diff, see system console.")
|
||||
|
||||
Reference in New Issue
Block a user