-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
172 lines (134 loc) · 4.12 KB
/
cli.py
File metadata and controls
172 lines (134 loc) · 4.12 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import os
import inquirer
import typer
from pydavinci import davinci
from rich import print
from rich.panel import Panel
from rich.prompt import Confirm
from patchwork.app import MasterFile, track_render
from patchwork.constants import STANDARD_RENDER_PRESETS
from patchwork.settings.manager import settings
from pyfiglet import Figlet
resolve = davinci.Resolve()
typer_app = typer.Typer()
figlet = Figlet(font="rectangles")
print(f"[cyan]{figlet.renderText('patchwork')}")
# CLI HANDLERS AND PROMPTS
def okay_to_write_sidecar(sidecar_output_path: str) -> bool:
if os.path.exists(sidecar_output_path):
if not Confirm.ask(
"Looks like a sidecar file already exists with that name.\n"
"It's linked render file is missing, "
"so it's likely an orphan.\n"
"Overwrite?"
):
return False
return True
def choose_render_preset():
# Remove generic presets?
rp = resolve.project.render_presets
if not settings.render.allow_generic_render_presets:
rp = [x for x in rp if x not in STANDARD_RENDER_PRESETS]
# Prompt for chosen preset
if choice := inquirer.prompt([
inquirer.List(
'render_preset',
message="Choose a render preset",
choices=rp,
)
]):
return choice
exit()
def choose_render_mode():
questions = [
inquirer.List(
'render_mode',
message="Ready to render?",
choices=["Local", "Network Render"],
)
]
answer = inquirer.prompt(questions)
if not answer:
exit()
if answer == "Network Render":
print(
"[cyan]"
"Cool! Select the network render machine, "
"then start the render in Resolve."
)
else:
print("[green]Starting render!")
return answer["render_mode"]
@typer_app.callback(invoke_without_command=True)
def callback(ctx: typer.Context):
if ctx.invoked_subcommand is None:
print()
print(Panel(
"\n"
"Patchwork patches render files with changes "
"marked in your timeline to save you time.\n"
"Run `patchwork new` to render a new master file "
"with the current timeline,\n"
"Or run `patchwork patch` to patch an existing "
"master file with segments marked "
"by ranged markers in the current timeline.",
title="Welcome to Patchwork!",
title_align="left",
expand=False,
))
@typer_app.command()
def new():
"""Render a new master file of the current timeline"""
print()
# Is resolve busy?
if resolve.project.is_rendering():
if Confirm.ask(
"\nLooks like Resolve is busy rendering!\n"
"You'll have to wait to queue a Patchwork job.\n"
"Check again?"
):
new()
exit()
# Are we happy?
if not Confirm.ask(
"\nAre you happy with the set render range?\n"
"Have you set necessary in and outs?",
):
exit()
# Remove generic presets?
rp = resolve.project.render_presets
if not settings.render.allow_generic_render_presets:
rp = [x for x in rp if x not in STANDARD_RENDER_PRESETS]
# Prompt for chosen preset
choice = inquirer.prompt([
inquirer.List(
'render_preset',
message="Choose a render preset",
choices=rp,
)
])
if not choice:
exit()
render_preset = choice["render_preset"]
# Init masterfile
masterfile = MasterFile(
render_preset=render_preset,
render_directory=settings.app.render_directory,
)
# Write sidecar?
if not okay_to_write_sidecar(masterfile.sidecar_output_path):
exit()
# Write sidecar.
masterfile.write_sidecar(overwrite=True)
# Render
render_mode = choose_render_mode()
job_id = masterfile.start_render(render_mode)
track_render(job_id)
@typer_app.command()
def patch():
"""Patch a master file with marked changes"""
...
def main():
typer_app()
if __name__ == "__main__":
main()