-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.py
More file actions
63 lines (56 loc) · 1.62 KB
/
Copy pathexecutor.py
File metadata and controls
63 lines (56 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import builtins
import io
import sys
import time
import os
import os.path
import traceback
import urllib.request
import tempfile
import shutil
def execute_code(code, resolve):
"""
Execute LLM-generated Python code against the live Resolve instance.
Returns (stdout_output, error_or_none).
"""
pm = resolve.GetProjectManager()
project = pm.GetCurrentProject() if pm else None
media_pool = project.GetMediaPool() if project else None
timeline = project.GetCurrentTimeline() if project else None
# Auto-create a timeline if none exists
if timeline is None and media_pool is not None:
timeline = media_pool.CreateEmptyTimeline("Timeline 1")
if timeline is not None:
project.SetCurrentTimeline(timeline) # type: ignore[union-attr]
media_storage = resolve.GetMediaStorage()
fusion = resolve.Fusion()
exec_globals = {
"__builtins__": builtins,
# Resolve objects
"resolve": resolve,
"project_manager": pm,
"project": project,
"timeline": timeline,
"media_pool": media_pool,
"media_storage": media_storage,
"fusion": fusion,
# Useful modules
"time": time,
"os": os,
"urllib": urllib,
"tempfile": tempfile,
"shutil": shutil,
}
# Capture stdout
old_stdout = sys.stdout
captured = io.StringIO()
sys.stdout = captured
error = None
try:
exec(code, exec_globals)
except Exception:
error = traceback.format_exc()
finally:
sys.stdout = old_stdout
output = captured.getvalue()
return output, error