flake8 code cleanup, minor fixes
This commit is contained in:
parent
b9eb2d234e
commit
43f08547f0
4 changed files with 606 additions and 583 deletions
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import renderlib
|
import renderlib
|
||||||
|
@ -8,10 +9,7 @@ import shlex
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
from xml.sax.saxutils import escape as xmlescape
|
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
|
@ -69,17 +67,20 @@ parser.add_argument('--bgloop', action="store_true", default=False, help='''
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def headline(str):
|
def headline(str):
|
||||||
print("##################################################")
|
print("##################################################")
|
||||||
print(str)
|
print(str)
|
||||||
print("##################################################")
|
print("##################################################")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
def error(str):
|
def error(str):
|
||||||
headline(str)
|
headline(str)
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if not args.project:
|
if not args.project:
|
||||||
error("The Path to your project with After Effect Files is a required argument")
|
error("The Path to your project with After Effect Files is a required argument")
|
||||||
|
|
||||||
|
@ -118,14 +119,18 @@ elif args.bgloop:
|
||||||
else:
|
else:
|
||||||
events = list(renderlib.events(args.schedule))
|
events = list(renderlib.events(args.schedule))
|
||||||
|
|
||||||
|
|
||||||
def describe_event(event):
|
def describe_event(event):
|
||||||
return "#{}: {}".format(event['id'], event['title'])
|
return "#{}: {}".format(event['id'], event['title'])
|
||||||
|
|
||||||
|
|
||||||
def event_print(event, message):
|
def event_print(event, message):
|
||||||
print("{} – {}".format(describe_event(event), message))
|
print("{} – {}".format(describe_event(event), message))
|
||||||
|
|
||||||
|
|
||||||
tempdir = tempfile.TemporaryDirectory()
|
tempdir = tempfile.TemporaryDirectory()
|
||||||
print('working in '+tempdir.name)
|
print('working in ' + tempdir.name)
|
||||||
|
|
||||||
|
|
||||||
def fmt_command(command, **kwargs):
|
def fmt_command(command, **kwargs):
|
||||||
args = {}
|
args = {}
|
||||||
|
@ -135,6 +140,7 @@ def fmt_command(command, **kwargs):
|
||||||
command = command.format(**args)
|
command = command.format(**args)
|
||||||
return shlex.split(command)
|
return shlex.split(command)
|
||||||
|
|
||||||
|
|
||||||
def run_once(command, **kwargs):
|
def run_once(command, **kwargs):
|
||||||
DETACHED_PROCESS = 0x00000008
|
DETACHED_PROCESS = 0x00000008
|
||||||
return subprocess.Popen(
|
return subprocess.Popen(
|
||||||
|
@ -146,89 +152,92 @@ def run_once(command, **kwargs):
|
||||||
close_fds=True,
|
close_fds=True,
|
||||||
creationflags=DETACHED_PROCESS)
|
creationflags=DETACHED_PROCESS)
|
||||||
|
|
||||||
|
|
||||||
def run(command, **kwargs):
|
def run(command, **kwargs):
|
||||||
return subprocess.check_call(
|
return subprocess.check_call(
|
||||||
fmt_command(command, **kwargs),
|
fmt_command(command, **kwargs),
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
stdout=subprocess.DEVNULL)
|
stdout=subprocess.DEVNULL)
|
||||||
|
|
||||||
|
|
||||||
def enqueue_job(event):
|
def enqueue_job(event):
|
||||||
event_id = str(event['id'])
|
event_id = str(event['id'])
|
||||||
if os.path.exists(os.path.join(args.project, event_id+'.ts')) or os.path.exists(os.path.join(args.project, event_id+'.mov')) and not args.force:
|
if os.path.exists(os.path.join(args.project, event_id + '.ts')) or os.path.exists(os.path.join(args.project, event_id + '.mov')) and not args.force:
|
||||||
event_print(event, "file exist, skipping "+str(event['id']))
|
event_print(event, "file exist, skipping " + str(event['id']))
|
||||||
return
|
return
|
||||||
work_doc = os.path.join(tempdir.name, event_id+'.aep')
|
work_doc = os.path.join(tempdir.name, event_id + '.aep')
|
||||||
script_doc = os.path.join(tempdir.name, event_id+'.jsx')
|
script_doc = os.path.join(tempdir.name, event_id + '.jsx')
|
||||||
ascript_doc = os.path.join(tempdir.name, event_id+'.scpt')
|
ascript_doc = os.path.join(tempdir.name, event_id + '.scpt')
|
||||||
intermediate_clip = os.path.join(tempdir.name, event_id+'.mov')
|
intermediate_clip = os.path.join(tempdir.name, event_id + '.mov')
|
||||||
|
|
||||||
if event_id == 'pause' or event_id == 'outro' or event_id == 'bgloop':
|
if event_id == 'pause' or event_id == 'outro' or event_id == 'bgloop':
|
||||||
copyfile(args.project+event_id+'.aep',work_doc)
|
copyfile(args.project + event_id + '.aep', work_doc)
|
||||||
if platform.system() == 'Darwin':
|
if platform.system() == 'Darwin':
|
||||||
run('/Applications/Adobe\ After\ Effects\ CC\ 2018/aerender -project {jobpath} -comp {comp} -output {locationpath}',
|
run(r'/Applications/Adobe\ After\ Effects\ CC\ 2018/aerender -project {jobpath} -comp {comp} -output {locationpath}',
|
||||||
jobpath=work_doc,
|
jobpath=work_doc,
|
||||||
comp=event_id,
|
comp=event_id,
|
||||||
locationpath=intermediate_clip)
|
locationpath=intermediate_clip)
|
||||||
|
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
run('C:/Program\ Files/Adobe/Adobe\ After\ Effects\ CC\ 2018/Support\ Files/aerender.exe -project {jobpath} -comp {comp} -output {locationpath}',
|
run(r'C:/Program\ Files/Adobe/Adobe\ After\ Effects\ CC\ 2018/Support\ Files/aerender.exe -project {jobpath} -comp {comp} -output {locationpath}',
|
||||||
jobpath=work_doc,
|
jobpath=work_doc,
|
||||||
comp=event_id,
|
comp=event_id,
|
||||||
locationpath=intermediate_clip)
|
locationpath=intermediate_clip)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with open(args.project+'intro.jsx', 'r') as fp:
|
with open(args.project + 'intro.jsx', 'r') as fp:
|
||||||
scriptstr = fp.read()
|
scriptstr = fp.read()
|
||||||
|
|
||||||
for key, value in event.items():
|
for key, value in event.items():
|
||||||
value = str(value).replace('"', '\\"')
|
value = str(value).replace('"', '\\"')
|
||||||
scriptstr = scriptstr.replace("$"+str(key), value)
|
scriptstr = scriptstr.replace("$" + str(key), value)
|
||||||
|
|
||||||
with open(script_doc, 'w', encoding='utf-8') as fp:
|
with open(script_doc, 'w', encoding='utf-8') as fp:
|
||||||
fp.write(scriptstr)
|
fp.write(scriptstr)
|
||||||
|
|
||||||
copyfile(args.project+'intro.aep',work_doc)
|
copyfile(args.project + 'intro.aep', work_doc)
|
||||||
|
|
||||||
if platform.system() == 'Darwin':
|
if platform.system() == 'Darwin':
|
||||||
copyfile(args.project+'intro.scpt',ascript_doc)
|
copyfile(args.project + 'intro.scpt', ascript_doc)
|
||||||
run('osascript {ascript_path} {jobpath} {scriptpath}',
|
run('osascript {ascript_path} {jobpath} {scriptpath}',
|
||||||
jobpath=work_doc,
|
jobpath=work_doc,
|
||||||
scriptpath=script_doc,
|
scriptpath=script_doc,
|
||||||
ascript_path=ascript_doc)
|
ascript_path=ascript_doc)
|
||||||
|
|
||||||
run('/Applications/Adobe\ After\ Effects\ CC\ 2018/aerender -project {jobpath} -comp "intro" -output {locationpath}',
|
run(r'/Applications/Adobe\ After\ Effects\ CC\ 2018/aerender -project {jobpath} -comp "intro" -output {locationpath}',
|
||||||
jobpath=work_doc,
|
jobpath=work_doc,
|
||||||
locationpath=intermediate_clip)
|
locationpath=intermediate_clip)
|
||||||
|
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
run_once('C:/Program\ Files/Adobe/Adobe\ After\ Effects\ CC\ 2018/Support\ Files/AfterFX.exe -noui {jobpath}',
|
run_once(r'C:/Program\ Files/Adobe/Adobe\ After\ Effects\ CC\ 2018/Support\ Files/AfterFX.exe -noui {jobpath}',
|
||||||
jobpath=work_doc)
|
jobpath=work_doc)
|
||||||
time.sleep(15)
|
time.sleep(15)
|
||||||
|
|
||||||
run_once('C:/Program\ Files/Adobe/Adobe\ After\ Effects\ CC\ 2018/Support\ Files/AfterFX.exe -noui -r {scriptpath}',
|
run_once(r'C:/Program\ Files/Adobe/Adobe\ After\ Effects\ CC\ 2018/Support\ Files/AfterFX.exe -noui -r {scriptpath}',
|
||||||
scriptpath=script_doc)
|
scriptpath=script_doc)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
run('C:/Program\ Files/Adobe/Adobe\ After\ Effects\ CC\ 2018/Support\ Files/aerender.exe -project {jobpath} -comp "intro" -output {locationpath}',
|
run(r'C:/Program\ Files/Adobe/Adobe\ After\ Effects\ CC\ 2018/Support\ Files/aerender.exe -project {jobpath} -comp "intro" -output {locationpath}',
|
||||||
jobpath=work_doc,
|
jobpath=work_doc,
|
||||||
locationpath=intermediate_clip)
|
locationpath=intermediate_clip)
|
||||||
|
|
||||||
return event_id
|
return event_id
|
||||||
|
|
||||||
|
|
||||||
def finalize_job(job_id, event):
|
def finalize_job(job_id, event):
|
||||||
event_id = str(event['id'])
|
event_id = str(event['id'])
|
||||||
intermediate_clip = os.path.join(tempdir.name, event_id+'.mov')
|
intermediate_clip = os.path.join(tempdir.name, event_id + '.mov')
|
||||||
final_clip = os.path.join(os.path.dirname(args.project), event_id+'.ts')
|
final_clip = os.path.join(os.path.dirname(args.project), event_id + '.ts')
|
||||||
|
|
||||||
run('ffmpeg -y -hide_banner -loglevel error -i {input} -f lavfi -i anullsrc -ar 48000 -ac 2 -map 0:v -c:v mpeg2video -q:v 0 -aspect 16:9 -map 1:a -map 1:a -map 1:a -map 1:a -shortest -f mpegts {output}',
|
run('ffmpeg -y -hide_banner -loglevel error -i {input} -f lavfi -i anullsrc -ar 48000 -ac 2 -map 0:v -c:v mpeg2video -q:v 0 -aspect 16:9 -map 1:a -map 1:a -map 1:a -map 1:a -shortest -f mpegts {output}',
|
||||||
#run('ffmpeg -y -hide_banner -loglevel error -i "{input}" -ar 48000 -ac 1 -map 0:v -c:v mpeg2video -q:v 0 -aspect 16:9 -map 1:0 -c:a copy -map 2:0 -c:a copy -shortest -f mpegts "{output}"',
|
# run('ffmpeg -y -hide_banner -loglevel error -i "{input}" -ar 48000 -ac 1 -map 0:v -c:v mpeg2video -q:v 0 -aspect 16:9 -map 1:0 -c:a copy -map 2:0 -c:a copy -shortest -f mpegts "{output}"',
|
||||||
input=intermediate_clip,
|
input=intermediate_clip,
|
||||||
output=final_clip)
|
output=final_clip)
|
||||||
|
|
||||||
if event_id == 'pause' or event_id == 'outro' or event_id == 'bgloop':
|
if event_id == 'pause' or event_id == 'outro' or event_id == 'bgloop':
|
||||||
event_print(event, "finalized "+str(event_id)+" to "+final_clip)
|
event_print(event, "finalized " + str(event_id) + " to " + final_clip)
|
||||||
else:
|
else:
|
||||||
event_print(event, "finalized intro to "+final_clip)
|
event_print(event, "finalized intro to " + final_clip)
|
||||||
|
|
||||||
|
|
||||||
if args.ids:
|
if args.ids:
|
||||||
|
@ -250,7 +259,7 @@ for event in events:
|
||||||
print("skipping room %s (%s)" % (event['room'], event['title']))
|
print("skipping room %s (%s)" % (event['room'], event['title']))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
event_print(event, "enqueued as "+str(event['id']))
|
event_print(event, "enqueued as " + str(event['id']))
|
||||||
|
|
||||||
job_id = enqueue_job(event)
|
job_id = enqueue_job(event)
|
||||||
if not job_id:
|
if not job_id:
|
||||||
|
@ -264,13 +273,13 @@ for event in events:
|
||||||
event_id = str(event['id'])
|
event_id = str(event['id'])
|
||||||
event_print(event, "skipping finalizing job")
|
event_print(event, "skipping finalizing job")
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
intermediate_clip = os.path.join(tempdir.name, event_id+'.avi')
|
intermediate_clip = os.path.join(tempdir.name, event_id + '.avi')
|
||||||
final_clip = os.path.join(os.path.dirname(args.project), event_id+'.avi')
|
final_clip = os.path.join(os.path.dirname(args.project), event_id + '.avi')
|
||||||
else:
|
else:
|
||||||
intermediate_clip = os.path.join(tempdir.name, event_id+'.mov')
|
intermediate_clip = os.path.join(tempdir.name, event_id + '.mov')
|
||||||
final_clip = os.path.join(os.path.dirname(args.project), event_id+'.mov')
|
final_clip = os.path.join(os.path.dirname(args.project), event_id + '.mov')
|
||||||
copyfile(intermediate_clip, final_clip)
|
copyfile(intermediate_clip, final_clip)
|
||||||
event_print(event, "copied intermediate clip to "+final_clip)
|
event_print(event, "copied intermediate clip to " + final_clip)
|
||||||
|
|
||||||
print('all done, cleaning up '+tempdir.name)
|
print('all done, cleaning up ' + tempdir.name)
|
||||||
tempdir.cleanup()
|
tempdir.cleanup()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import renderlib
|
import renderlib
|
||||||
|
@ -47,17 +48,20 @@ parser.add_argument('--exclude-id', dest='exclude_ids', nargs='+', action="store
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def headline(str):
|
def headline(str):
|
||||||
print("##################################################")
|
print("##################################################")
|
||||||
print(str)
|
print(str)
|
||||||
print("##################################################")
|
print("##################################################")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
def error(str):
|
def error(str):
|
||||||
headline(str)
|
headline(str)
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if not args.motn:
|
if not args.motn:
|
||||||
error("The Motion-File is a rquired argument")
|
error("The Motion-File is a rquired argument")
|
||||||
|
|
||||||
|
@ -78,14 +82,17 @@ if args.debug:
|
||||||
else:
|
else:
|
||||||
events = list(renderlib.events(args.schedule))
|
events = list(renderlib.events(args.schedule))
|
||||||
|
|
||||||
|
|
||||||
def describe_event(event):
|
def describe_event(event):
|
||||||
return "#{}: {}".format(event['id'], event['title'])
|
return "#{}: {}".format(event['id'], event['title'])
|
||||||
|
|
||||||
|
|
||||||
def event_print(event, message):
|
def event_print(event, message):
|
||||||
print("{} – {}".format(describe_event(event), message))
|
print("{} – {}".format(describe_event(event), message))
|
||||||
|
|
||||||
|
|
||||||
tempdir = tempfile.TemporaryDirectory()
|
tempdir = tempfile.TemporaryDirectory()
|
||||||
print('working in '+tempdir.name)
|
print('working in ' + tempdir.name)
|
||||||
|
|
||||||
|
|
||||||
def fmt_command(command, **kwargs):
|
def fmt_command(command, **kwargs):
|
||||||
|
@ -96,10 +103,12 @@ def fmt_command(command, **kwargs):
|
||||||
command = command.format(**args)
|
command = command.format(**args)
|
||||||
return shlex.split(command)
|
return shlex.split(command)
|
||||||
|
|
||||||
|
|
||||||
def run(command, **kwargs):
|
def run(command, **kwargs):
|
||||||
return subprocess.check_call(
|
return subprocess.check_call(
|
||||||
fmt_command(command, **kwargs))
|
fmt_command(command, **kwargs))
|
||||||
|
|
||||||
|
|
||||||
def run_output(command, **kwargs):
|
def run_output(command, **kwargs):
|
||||||
return subprocess.check_output(
|
return subprocess.check_output(
|
||||||
fmt_command(command, **kwargs),
|
fmt_command(command, **kwargs),
|
||||||
|
@ -109,14 +118,14 @@ def run_output(command, **kwargs):
|
||||||
|
|
||||||
def enqueue_job(event):
|
def enqueue_job(event):
|
||||||
event_id = str(event['id'])
|
event_id = str(event['id'])
|
||||||
work_doc = os.path.join(tempdir.name, event_id+'.motn')
|
work_doc = os.path.join(tempdir.name, event_id + '.motn')
|
||||||
intermediate_clip = os.path.join(tempdir.name, event_id+'.mov')
|
intermediate_clip = os.path.join(tempdir.name, event_id + '.mov')
|
||||||
|
|
||||||
with open(args.motn, 'r') as fp:
|
with open(args.motn, 'r') as fp:
|
||||||
xmlstr = fp.read()
|
xmlstr = fp.read()
|
||||||
|
|
||||||
for key, value in event.items():
|
for key, value in event.items():
|
||||||
xmlstr = xmlstr.replace("$"+str(key), xmlescape(str(value)))
|
xmlstr = xmlstr.replace("$" + str(key), xmlescape(str(value)))
|
||||||
|
|
||||||
with open(work_doc, 'w') as fp:
|
with open(work_doc, 'w') as fp:
|
||||||
fp.write(xmlstr)
|
fp.write(xmlstr)
|
||||||
|
@ -127,16 +136,17 @@ def enqueue_job(event):
|
||||||
jobpath=work_doc,
|
jobpath=work_doc,
|
||||||
locationpath=intermediate_clip)
|
locationpath=intermediate_clip)
|
||||||
|
|
||||||
match = re.search("<jobID ([A-Z0-9\-]+) ?\/>", compressor_info)
|
match = re.search(r"<jobID ([A-Z0-9\-]+) ?\/>", compressor_info)
|
||||||
if not match:
|
if not match:
|
||||||
event_print(event, "unexpected output from compressor: \n"+compressor_info)
|
event_print(event, "unexpected output from compressor: \n" + compressor_info)
|
||||||
return
|
return
|
||||||
|
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
|
|
||||||
|
|
||||||
def fetch_job_status():
|
def fetch_job_status():
|
||||||
compressor_status = run_output('/Applications/Compressor.app/Contents/MacOS/Compressor -monitor')
|
compressor_status = run_output('/Applications/Compressor.app/Contents/MacOS/Compressor -monitor')
|
||||||
job_status_matches = re.finditer("<jobStatus (.*) \/jobStatus>", compressor_status)
|
job_status_matches = re.finditer(r"<jobStatus (.*) \/jobStatus>", compressor_status)
|
||||||
|
|
||||||
status_dict = {}
|
status_dict = {}
|
||||||
for match in job_status_matches:
|
for match in job_status_matches:
|
||||||
|
@ -150,8 +160,6 @@ def fetch_job_status():
|
||||||
return status_dict
|
return status_dict
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def filter_finished_jobs(active_jobs):
|
def filter_finished_jobs(active_jobs):
|
||||||
job_status = fetch_job_status()
|
job_status = fetch_job_status()
|
||||||
|
|
||||||
|
@ -169,25 +177,24 @@ def filter_finished_jobs(active_jobs):
|
||||||
elif status == 'Successful':
|
elif status == 'Successful':
|
||||||
finished_jobs.append((job_id, event))
|
finished_jobs.append((job_id, event))
|
||||||
else:
|
else:
|
||||||
event_print(event, "failed with staus="+status+" – removing from postprocessing queue")
|
event_print(event, "failed with staus=" + status + " – removing from postprocessing queue")
|
||||||
|
|
||||||
return new_active_jobs, finished_jobs
|
return new_active_jobs, finished_jobs
|
||||||
|
|
||||||
|
|
||||||
def finalize_job(job_id, event):
|
def finalize_job(job_id, event):
|
||||||
event_id = str(event['id'])
|
event_id = str(event['id'])
|
||||||
intermediate_clip = os.path.join(tempdir.name, event_id+'.mov')
|
intermediate_clip = os.path.join(tempdir.name, event_id + '.mov')
|
||||||
final_clip = os.path.join(os.path.dirname(args.motn), event_id+'.ts')
|
final_clip = os.path.join(os.path.dirname(args.motn), event_id + '.ts')
|
||||||
copy_clip = os.path.join(os.path.dirname(args.motn), event_id+'.mov')
|
copy_clip = os.path.join(os.path.dirname(args.motn), event_id + '.mov')
|
||||||
|
|
||||||
shutil.copy(intermediate_clip, copy_clip)
|
shutil.copy(intermediate_clip, copy_clip)
|
||||||
|
|
||||||
run('ffmpeg -y -hide_banner -loglevel error -i "{input}" -map 0:v -c:v mpeg2video -q:v 0 -aspect 16:9 -map 0:a -map 0:a -map 0:a -map 0:a -shortest -f mpegts "{output}"',
|
run('ffmpeg -y -hide_banner -loglevel error -i {input} -f lavfi -i anullsrc -ar 48000 -ac 2 -map 0:v -c:v mpeg2video -q:v 0 -aspect 16:9 -map 1:a -map 1:a -map 1:a -map 1:a -shortest -f mpegts {output}',
|
||||||
input=intermediate_clip,
|
input=intermediate_clip,
|
||||||
output=final_clip)
|
output=final_clip)
|
||||||
|
|
||||||
event_print(event, "finalized intro to "+final_clip)
|
event_print(event, "finalized intro to " + final_clip)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
active_jobs = []
|
active_jobs = []
|
||||||
|
@ -204,7 +211,7 @@ for event in filtered_events:
|
||||||
event_print(event, "job was not enqueued successfully, skipping postprocessing")
|
event_print(event, "job was not enqueued successfully, skipping postprocessing")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
event_print(event, "enqueued as "+job_id)
|
event_print(event, "enqueued as " + job_id)
|
||||||
active_jobs.append((job_id, event))
|
active_jobs.append((job_id, event))
|
||||||
|
|
||||||
print("waiting for rendering to complete")
|
print("waiting for rendering to complete")
|
||||||
|
@ -219,5 +226,5 @@ while len(active_jobs) > 0:
|
||||||
finalize_job(job_id, event)
|
finalize_job(job_id, event)
|
||||||
|
|
||||||
|
|
||||||
print('all done, cleaning up '+tempdir.name)
|
print('all done, cleaning up ' + tempdir.name)
|
||||||
tempdir.cleanup()
|
tempdir.cleanup()
|
||||||
|
|
31
make.py
31
make.py
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
from lxml import etree
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
@ -55,14 +55,14 @@ if len(sys.argv) < 2:
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not (args.debug==False or args.id==None):
|
if not (args.debug is False or args.id is None):
|
||||||
print("##################################################")
|
print("##################################################")
|
||||||
print("Error! You must not use --debug and --id together!")
|
print("Error! You must not use --debug and --id together!")
|
||||||
print("##################################################")
|
print("##################################################")
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not (args.debug==False or args.skip==None):
|
if not (args.debug is False or args.skip is None):
|
||||||
print("####################################################")
|
print("####################################################")
|
||||||
print("Error! You must not use --debug and --skip together!")
|
print("Error! You must not use --debug and --skip together!")
|
||||||
print("####################################################")
|
print("####################################################")
|
||||||
|
@ -72,8 +72,8 @@ if not (args.debug==False or args.skip==None):
|
||||||
print(args)
|
print(args)
|
||||||
|
|
||||||
# Set values from argparse
|
# Set values from argparse
|
||||||
projectname=args.projectpath.strip('/')
|
projectname = args.projectpath.strip('/')
|
||||||
projectpath=args.projectpath
|
projectpath = args.projectpath
|
||||||
|
|
||||||
# Check if project exists
|
# Check if project exists
|
||||||
try:
|
try:
|
||||||
|
@ -86,12 +86,14 @@ except ImportError:
|
||||||
# just renders one type of video
|
# just renders one type of video
|
||||||
renderlib.debug = args.debug
|
renderlib.debug = args.debug
|
||||||
renderlib.args = args
|
renderlib.args = args
|
||||||
#sys.exit(1)
|
# sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def render(infile, outfile, sequence, parameters={}, workdir=os.path.join(projectname, 'artwork')):
|
def render(infile, outfile, sequence, parameters={}, workdir=os.path.join(projectname, 'artwork')):
|
||||||
task = renderlib.Rendertask(infile=infile, outfile=outfile, sequence=sequence, parameters=parameters, workdir=workdir)
|
task = renderlib.Rendertask(infile=infile, outfile=outfile, sequence=sequence, parameters=parameters, workdir=workdir)
|
||||||
return renderlib.rendertask(task)
|
return renderlib.rendertask(task)
|
||||||
|
|
||||||
|
|
||||||
# debug-mode selected by --debug switch
|
# debug-mode selected by --debug switch
|
||||||
if renderlib.debug:
|
if renderlib.debug:
|
||||||
print("!!! DEBUG MODE !!!")
|
print("!!! DEBUG MODE !!!")
|
||||||
|
@ -105,16 +107,14 @@ if renderlib.debug:
|
||||||
# exit early
|
# exit early
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# threaded task queue
|
# threaded task queue
|
||||||
tasks = Queue()
|
tasks = Queue()
|
||||||
|
|
||||||
#initialize args.id and args.skip, if they are not given by the user
|
# initialize args.id and args.skip, if they are not given by the user
|
||||||
if (args.id==None):
|
if (args.id is None):
|
||||||
args.id = []
|
args.id = []
|
||||||
|
|
||||||
if (args.skip==None):
|
if (args.skip is None):
|
||||||
args.skip = []
|
args.skip = []
|
||||||
|
|
||||||
# call into project which generates the tasks
|
# call into project which generates the tasks
|
||||||
|
@ -131,12 +131,14 @@ for _ in range(num_worker_threads):
|
||||||
# this lock ensures, that only one thread at a time is writing to stdout
|
# this lock ensures, that only one thread at a time is writing to stdout
|
||||||
# and avoids output from multiple threads intermixing
|
# and avoids output from multiple threads intermixing
|
||||||
printLock = Lock()
|
printLock = Lock()
|
||||||
|
|
||||||
|
|
||||||
def tprint(str):
|
def tprint(str):
|
||||||
# aquire lock
|
# aquire lock
|
||||||
printLock.acquire()
|
printLock.acquire()
|
||||||
|
|
||||||
# print thread-name and message
|
# print thread-name and message
|
||||||
print(threading.current_thread().name+': '+str)
|
print(threading.current_thread().name + ': ' + str)
|
||||||
|
|
||||||
# release lock
|
# release lock
|
||||||
printLock.release()
|
printLock.release()
|
||||||
|
@ -163,7 +165,7 @@ def worker():
|
||||||
task = renderlib.Rendertask.ensure(tasks.get())
|
task = renderlib.Rendertask.ensure(tasks.get())
|
||||||
|
|
||||||
# if it is a stop-sentinal break out of the loop
|
# if it is a stop-sentinal break out of the loop
|
||||||
if task == None:
|
if task is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
# print that we're about to render a task
|
# print that we're about to render a task
|
||||||
|
@ -192,6 +194,7 @@ def worker():
|
||||||
# mark the sentinal as done
|
# mark the sentinal as done
|
||||||
tasks.task_done()
|
tasks.task_done()
|
||||||
|
|
||||||
|
|
||||||
# List of running threads
|
# List of running threads
|
||||||
threads = []
|
threads = []
|
||||||
|
|
||||||
|
@ -206,7 +209,7 @@ for i in range(num_worker_threads):
|
||||||
# we're doing it the manual way because tasks.join() would wait until all tasks are done,
|
# we're doing it the manual way because tasks.join() would wait until all tasks are done,
|
||||||
# even if the worker threads crash due to broken svgs, Ctrl-C termination or whatnot
|
# even if the worker threads crash due to broken svgs, Ctrl-C termination or whatnot
|
||||||
while True:
|
while True:
|
||||||
if tasks.empty() == True:
|
if tasks.empty() is True:
|
||||||
break
|
break
|
||||||
|
|
||||||
# sleep while the workers work
|
# sleep while the workers work
|
||||||
|
|
42
renderlib.py
42
renderlib.py
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import glob
|
import glob
|
||||||
import math
|
|
||||||
import shutil
|
import shutil
|
||||||
import errno
|
import errno
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
@ -22,24 +22,27 @@ args = None
|
||||||
cssutils.ser.prefs.lineSeparator = ' '
|
cssutils.ser.prefs.lineSeparator = ' '
|
||||||
cssutils.log.setLevel(logging.FATAL)
|
cssutils.log.setLevel(logging.FATAL)
|
||||||
|
|
||||||
|
|
||||||
def loadProject(projectname):
|
def loadProject(projectname):
|
||||||
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), projectname))
|
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), projectname))
|
||||||
return __import__(projectname)
|
return __import__(projectname)
|
||||||
|
|
||||||
|
|
||||||
def easeDelay(easer, delay, t, b, c, d, *args):
|
def easeDelay(easer, delay, t, b, c, d, *args):
|
||||||
if t < delay:
|
if t < delay:
|
||||||
return b
|
return b
|
||||||
|
|
||||||
if t - delay > d:
|
if t - delay > d:
|
||||||
return b+c
|
return b + c
|
||||||
|
|
||||||
return easer(t - delay, b, c, d, *args)
|
return easer(t - delay, b, c, d, *args)
|
||||||
|
|
||||||
|
|
||||||
class Rendertask:
|
class Rendertask:
|
||||||
def __init__(self, infile, sequence, parameters={}, outfile=None, workdir='.'):
|
def __init__(self, infile, sequence, parameters={}, outfile=None, workdir='.'):
|
||||||
if isinstance(infile, list):
|
if isinstance(infile, list):
|
||||||
self.infile = infile[0]
|
self.infile = infile[0]
|
||||||
#self.audiofile = infile[1]
|
# self.audiofile = infile[1]
|
||||||
else:
|
else:
|
||||||
self.infile = infile
|
self.infile = infile
|
||||||
self.audiofile = None
|
self.audiofile = None
|
||||||
|
@ -59,6 +62,7 @@ class Rendertask:
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# try to create all folders needed and skip, they already exist
|
# try to create all folders needed and skip, they already exist
|
||||||
def ensurePathExists(path):
|
def ensurePathExists(path):
|
||||||
try:
|
try:
|
||||||
|
@ -67,18 +71,20 @@ def ensurePathExists(path):
|
||||||
if exception.errno != errno.EEXIST:
|
if exception.errno != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
# remove the files matched by the pattern
|
# remove the files matched by the pattern
|
||||||
def ensureFilesRemoved(pattern):
|
def ensureFilesRemoved(pattern):
|
||||||
for f in glob.glob(pattern):
|
for f in glob.glob(pattern):
|
||||||
os.unlink(f)
|
os.unlink(f)
|
||||||
|
|
||||||
|
|
||||||
def rendertask(task):
|
def rendertask(task):
|
||||||
global args
|
global args
|
||||||
# in debug mode we have no thread-worker which prints its progress
|
# in debug mode we have no thread-worker which prints its progress
|
||||||
if debug:
|
if debug:
|
||||||
print("generating {0} from {1}".format(task.outfile, task.infile))
|
print("generating {0} from {1}".format(task.outfile, task.infile))
|
||||||
|
|
||||||
if not args.skip_frames and not 'only_rerender_frames_after' in task.parameters:
|
if args.skip_frames and 'only_rerender_frames_after' not in task.parameters:
|
||||||
if os.path.isdir(os.path.join(task.workdir, '.frames')):
|
if os.path.isdir(os.path.join(task.workdir, '.frames')):
|
||||||
shutil.rmtree(os.path.join(task.workdir, '.frames'))
|
shutil.rmtree(os.path.join(task.workdir, '.frames'))
|
||||||
|
|
||||||
|
@ -94,7 +100,7 @@ def rendertask(task):
|
||||||
parser = etree.XMLParser(huge_tree=True)
|
parser = etree.XMLParser(huge_tree=True)
|
||||||
svg = etree.fromstring(svgstr.encode('utf-8'), parser)
|
svg = etree.fromstring(svgstr.encode('utf-8'), parser)
|
||||||
|
|
||||||
#if '$subtitle' in task.parameters and task.parameters['$subtitle'] == '':
|
# if '$subtitle' in task.parameters and task.parameters['$subtitle'] == '':
|
||||||
# child = svg.findall(".//*[@id='subtitle']")[0]
|
# child = svg.findall(".//*[@id='subtitle']")[0]
|
||||||
# child.getparent().remove(child)
|
# child.getparent().remove(child)
|
||||||
|
|
||||||
|
@ -137,9 +143,9 @@ def rendertask(task):
|
||||||
for replaceinfo in frame:
|
for replaceinfo in frame:
|
||||||
(id, type, key, value) = replaceinfo
|
(id, type, key, value) = replaceinfo
|
||||||
|
|
||||||
for el in svg.findall(".//*[@id='"+id.replace("'", "\\'")+"']"):
|
for el in svg.findall(".//*[@id='" + id.replace("'", "\\'") + "']"):
|
||||||
if type == 'style':
|
if type == 'style':
|
||||||
style = cssutils.parseStyle( el.attrib['style'] if 'style' in el.attrib else '' )
|
style = cssutils.parseStyle(el.attrib['style'] if 'style' in el.attrib else '')
|
||||||
style[key] = str(value)
|
style[key] = str(value)
|
||||||
el.attrib['style'] = style.cssText
|
el.attrib['style'] = style.cssText
|
||||||
|
|
||||||
|
@ -153,7 +159,7 @@ def rendertask(task):
|
||||||
# open the output-file (named ".gen.svg" in the workdir)
|
# open the output-file (named ".gen.svg" in the workdir)
|
||||||
with open(os.path.join(task.workdir, '.gen.svg'), 'w') as fp:
|
with open(os.path.join(task.workdir, '.gen.svg'), 'w') as fp:
|
||||||
# write the generated svg-text into the output-file
|
# write the generated svg-text into the output-file
|
||||||
fp.write( etree.tostring(svg, encoding='unicode') )
|
fp.write(etree.tostring(svg, encoding='unicode'))
|
||||||
|
|
||||||
if task.outfile.endswith('.ts') or task.outfile.endswith('.mov'):
|
if task.outfile.endswith('.ts') or task.outfile.endswith('.mov'):
|
||||||
width = 1920
|
width = 1920
|
||||||
|
@ -166,18 +172,15 @@ def rendertask(task):
|
||||||
cmd = 'cd {0} && inkscape --export-background=white --export-background-opacity=0 --export-width={2} --export-height={3} --export-png=$(pwd)/.frames/{1:04d}.png $(pwd)/.gen.svg 2>&1 >/dev/null'.format(task.workdir, frameNr, width, height)
|
cmd = 'cd {0} && inkscape --export-background=white --export-background-opacity=0 --export-width={2} --export-height={3} --export-png=$(pwd)/.frames/{1:04d}.png $(pwd)/.gen.svg 2>&1 >/dev/null'.format(task.workdir, frameNr, width, height)
|
||||||
errorReturn = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT)
|
errorReturn = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT)
|
||||||
if errorReturn != '':
|
if errorReturn != '':
|
||||||
print("inkscape exitted with error\n"+errorReturn)
|
print("inkscape exitted with error\n" + errorReturn)
|
||||||
#sys.exit(42)
|
# sys.exit(42)
|
||||||
|
|
||||||
# increment frame-number
|
# increment frame-number
|
||||||
frameNr += 1
|
frameNr += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if args.only_frame:
|
if args.only_frame:
|
||||||
task.outfile = '{0}.frame{1:04d}.png'.format(task.outfile, args.only_frame)
|
task.outfile = '{0}.frame{1:04d}.png'.format(task.outfile, args.only_frame)
|
||||||
|
|
||||||
|
|
||||||
# remove the dv/ts we are about to (re-)generate
|
# remove the dv/ts we are about to (re-)generate
|
||||||
ensureFilesRemoved(os.path.join(task.workdir, task.outfile))
|
ensureFilesRemoved(os.path.join(task.workdir, task.outfile))
|
||||||
|
|
||||||
|
@ -220,12 +223,12 @@ def rendertask(task):
|
||||||
if not debug:
|
if not debug:
|
||||||
print("cleanup")
|
print("cleanup")
|
||||||
|
|
||||||
|
|
||||||
# remove the generated svg
|
# remove the generated svg
|
||||||
ensureFilesRemoved(os.path.join(task.workdir, '.gen.svg'))
|
ensureFilesRemoved(os.path.join(task.workdir, '.gen.svg'))
|
||||||
|
|
||||||
|
|
||||||
# Download the Events-Schedule and parse all Events out of it. Yield a tupel for each Event
|
# Download the Events-Schedule and parse all Events out of it. Yield a tupel for each Event
|
||||||
|
|
||||||
|
|
||||||
def events(scheduleUrl, titlemap={}):
|
def events(scheduleUrl, titlemap={}):
|
||||||
print("downloading schedule")
|
print("downloading schedule")
|
||||||
|
|
||||||
|
@ -249,7 +252,7 @@ def events(scheduleUrl, titlemap={}):
|
||||||
personnames = []
|
personnames = []
|
||||||
if event.find('persons') is not None:
|
if event.find('persons') is not None:
|
||||||
for person in event.find('persons').iter('person'):
|
for person in event.find('persons').iter('person'):
|
||||||
personname = re.sub( '\s+', ' ', person.text ).strip()
|
personname = re.sub(r'\s+', ' ', person.text).strip()
|
||||||
personnames.append(personname)
|
personnames.append(personname)
|
||||||
|
|
||||||
id = int(event.get('id'))
|
id = int(event.get('id'))
|
||||||
|
@ -257,12 +260,12 @@ def events(scheduleUrl, titlemap={}):
|
||||||
if id in titlemap:
|
if id in titlemap:
|
||||||
title = titlemap[id]
|
title = titlemap[id]
|
||||||
elif event.find('title') is not None and event.find('title').text is not None:
|
elif event.find('title') is not None and event.find('title').text is not None:
|
||||||
title = re.sub( '\s+', ' ', event.find('title').text ).strip()
|
title = re.sub(r'\s+', ' ', event.find('title').text).strip()
|
||||||
else:
|
else:
|
||||||
title = ''
|
title = ''
|
||||||
|
|
||||||
if event.find('subtitle') is not None and event.find('subtitle').text is not None:
|
if event.find('subtitle') is not None and event.find('subtitle').text is not None:
|
||||||
subtitle = re.sub( '\s+', ' ', event.find('subtitle').text ).strip()
|
subtitle = re.sub(r'\s+', ' ', event.find('subtitle').text).strip()
|
||||||
else:
|
else:
|
||||||
subtitle = ''
|
subtitle = ''
|
||||||
|
|
||||||
|
@ -274,9 +277,10 @@ def events(scheduleUrl, titlemap={}):
|
||||||
'persons': personnames,
|
'persons': personnames,
|
||||||
'personnames': ', '.join(personnames),
|
'personnames': ', '.join(personnames),
|
||||||
'room': room.attrib['name'],
|
'room': room.attrib['name'],
|
||||||
'track' : event.find('track').text
|
'track': event.find('track').text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
Loading…
Add table
Reference in a new issue