DaVinci MCP Professional v3.0.0
A modern, professional Model Context Protocol server for DaVinci Resolve integration
Loading...
Searching...
No Matches
platform.py
Go to the documentation of this file.
1"""
2Platform detection and environment setup utilities.
3"""
4
5import os
6import sys
7import platform
8from typing import Dict
9from pathlib import Path
10
11
12def get_platform() -> str:
13 """Get the current platform name."""
14 system = platform.system().lower()
15 if system == "darwin":
16 return "macos"
17 elif system == "windows":
18 return "windows"
19 elif system == "linux":
20 return "linux"
21 else:
22 return system
23
24
25def get_resolve_paths() -> Dict[str, Path]:
26 """Get platform-specific paths for DaVinci Resolve scripting API."""
27 current_platform = get_platform()
28
29 if current_platform == "macos":
30 api_path = Path(
31 "/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting"
32 )
33 lib_path = Path(
34 "/Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so"
35 )
36
37 elif current_platform == "windows":
38 program_data = Path(os.environ.get("PROGRAMDATA", "C:\\ProgramData"))
39 program_files = Path(os.environ.get("PROGRAMFILES", "C:\\Program Files"))
40
41 api_path = (
42 program_data
43 / "Blackmagic Design"
44 / "DaVinci Resolve"
45 / "Support"
46 / "Developer"
47 / "Scripting"
48 )
49 lib_path = (
50 program_files / "Blackmagic Design" / "DaVinci Resolve" / "fusionscript.dll"
51 )
52
53 elif current_platform == "linux":
54 # Default Linux paths - may need adjustment based on installation
55 api_path = Path("/opt/resolve/Developer/Scripting")
56 lib_path = Path("/opt/resolve/libs/fusionscript.so")
57
58 else:
59 raise RuntimeError(f"Unsupported platform: {current_platform}")
60
61 return {
62 "api_path": api_path,
63 "lib_path": lib_path,
64 "modules_path": api_path / "Modules",
65 }
66
67
69 """Set up environment variables for DaVinci Resolve scripting."""
70 try:
71 paths = get_resolve_paths()
72
73 # Set environment variables
74 os.environ["RESOLVE_SCRIPT_API"] = str(paths["api_path"])
75 os.environ["RESOLVE_SCRIPT_LIB"] = str(paths["lib_path"])
76
77 # Add modules path to Python path if not already there
78 modules_path_str = str(paths["modules_path"])
79 if modules_path_str not in sys.path:
80 sys.path.insert(0, modules_path_str)
81
82 return True
83 except Exception:
84 return False
85
86
87def check_resolve_installation() -> Dict[str, bool]:
88 """Check if DaVinci Resolve is properly installed."""
89 paths = get_resolve_paths()
90
91 return {
92 "api_path_exists": paths["api_path"].exists(),
93 "lib_path_exists": paths["lib_path"].exists(),
94 "modules_path_exists": paths["modules_path"].exists(),
95 }
96
97
99 """Check if DaVinci Resolve is currently running."""
100 current_platform = get_platform()
101
102 try:
103 if current_platform == "windows":
104 import subprocess
105
106 result = subprocess.run(
107 ["tasklist", "/FI", "IMAGENAME eq Resolve.exe"],
108 capture_output=True,
109 text=True,
110 check=False,
111 )
112 return "Resolve.exe" in result.stdout
113
114 elif current_platform in ["macos", "linux"]:
115 import subprocess
116
117 result = subprocess.run(
118 ["pgrep", "-f", "DaVinci Resolve"], capture_output=True, check=False
119 )
120 return result.returncode == 0
121
122 return False
123 except Exception:
124 return False
Dict[str, Path] get_resolve_paths()
Definition platform.py:25
Dict[str, bool] check_resolve_installation()
Definition platform.py:87