X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fref%2Fmake.py;h=ac8ff15570bad3a7d48cd26eb0aac46b1d6dd2dd;hb=422c8a63d2368a2e63aee4c391207e3332d1d4c7;hp=013a7c248bb81b0696bc7fd27dc88b5e96087b24;hpb=0e7591e3bf95d4abe08d854850b6fc4e411586b0;p=libdcp.git diff --git a/test/ref/make.py b/test/ref/make.py index 013a7c24..ac8ff155 100755 --- a/test/ref/make.py +++ b/test/ref/make.py @@ -1,22 +1,52 @@ #!/usr/bin/python +# +# This slightly ridiculous script gets OpenDCP to generate +# a DCP using out test reference data (in j2c/ and wav/) +# and then adjusts its XML output to account for the fact +# that OpenDCP will generate its own random UUIDs (and use +# current timestamps). We set UUIDs and timestamps back +# to what our test suite will expect. +# +# The output of this script is checked into git, so +# there's normally no need to run it. +# +# If you do run it, the XML should be right but the +# MXFs that OpenDCP generates will not be quite what +# we expect, as they also contain random UUIDs. I don't +# think there's an easy way round that, so after running +# this script you will need to check that the libdcp +# test code generates correct MXFs (by verification on +# a projector, probably), and then copy those MXFs into the +# test/ref/DCP directory. +# + import os import sys import fileinput from lxml import etree -def replace(l, a, b): - return l.replace(a, b) - +# Namespaces for the various XML files assetmap_namespace = 'http://www.smpte-ra.org/schemas/429-9/2007/AM' cpl_namespace = 'http://www.smpte-ra.org/schemas/429-7/2006/CPL' +pkl_namespace = 'http://www.smpte-ra.org/schemas/429-8/2007/PKL' -wanted_cpl_id = 'df0e4141-13c3-4a7a-bef8-b5a04fcbc4bb' -wanted_pkl_id = '8e293965-f8ad-48c6-971d-261b01f65cdb' -wanted_assetmap_id = '18be072e-5a0f-44e1-b2eb-c8a52ae12789' +# The UUIDs of things that we want to put into the +# OpenDCP-generated XML +wanted_cpl_id = '9892e944-5046-4dbb-af7c-f50742f62fc2' +wanted_pkl_id = 'df0e4141-13c3-4a7a-bef8-b5a04fcbc4bb' +wanted_assetmap_id = 'b135d5cf-d180-43d8-b0b3-7373737b73bf' wanted_video_mxf_id = '81fb54df-e1bf-4647-8788-ea7ba154375b' -wanted_audio_mxf_id = 'c38bdd62-ce03-4988-8603-195f134207c7' +wanted_audio_mxf_id = '67b9341e-cadd-4dac-9d5c-f5a1d59f2d06' +wanted_reel_id = '379fa64c-ad71-46cf-bef7-b45624006610' + +# The hashes of the assets: first is the video MXF, second the audio MXF and third the CPL. +wanted_asset_hashes = ['VB9LCTmiD9OLlw4SvrEWUm5d67Q=', 'HapNpn7MjiJLa1OHRI61Rx8N/is=', 'PbXuvpUOKccTLMxg/lEbaXvNCT4='] +# The issue date that we want to use +wanted_issue_date = '2012-07-17T04:45:18+00:00' + +# Get OpenDCP to make the DCP os.system('rm -rf DCP') os.mkdir('DCP') os.system('opendcp_mxf -i j2c -o DCP/video.mxf -r 24') @@ -24,9 +54,13 @@ os.system('opendcp_mxf -i wav -o DCP/audio.mxf -r 24') os.system('opendcp_xml --reel DCP/video.mxf DCP/audio.mxf -k feature -t "A Test DCP" -a "A Test DCP"') os.system('mv *.xml DCP') +# Find what IDs it used cpl_id = None pkl_id = None assetmap_id = None +video_mxf_id = None +audio_mxf_id = None +reel_id = None for r, d, f in os.walk('DCP'): for n in f: @@ -35,6 +69,7 @@ for r, d, f in os.walk('DCP'): elif n.endswith('pkl.xml'): pkl_id = n[0:-8] +# (along the way, rename the CPL/PKL files) os.rename('DCP/%s_cpl.xml' % cpl_id, 'DCP/%s_cpl.xml' % wanted_cpl_id) os.rename('DCP/%s_pkl.xml' % pkl_id, 'DCP/%s_pkl.xml' % wanted_pkl_id) @@ -61,15 +96,38 @@ audio_mxf_id = xml.getroot().find(cpl_name('ReelList')). \ find(cpl_name('Id')).text audio_mxf_id = audio_mxf_id.replace('urn:uuid:', '') +reel_id = xml.getroot().find(cpl_name('ReelList')). \ + find(cpl_name('Reel')). \ + find(cpl_name('Id')).text +reel_id = reel_id.replace('urn:uuid:', '') + +def pkl_name(s): + return '{%s}%s' % (pkl_namespace, s) + +xml = etree.parse('DCP/%s_pkl.xml' % wanted_pkl_id) + +asset_list = xml.getroot().find(pkl_name('AssetList')) +asset_hashes = [] +for a in asset_list.iter(): + if a.tag == "{%s}Hash" % pkl_namespace: + asset_hashes.append(a.text) + +issue_date = xml.getroot().find(pkl_name('IssueDate')).text + +# Now run through the XML files doing the replacements for r, d, f in os.walk('DCP'): for n in f: if n.endswith('.xml'): for line in fileinput.input(os.path.join(r, n), inplace = 1): - line = replace(line, cpl_id, wanted_cpl_id) - line = replace(line, pkl_id, wanted_pkl_id) - line = replace(line, assetmap_id, wanted_assetmap_id) - line = replace(line, video_mxf_id, wanted_video_mxf_id) - line = replace(line, audio_mxf_id, wanted_audio_mxf_id) + line = line.replace(cpl_id, wanted_cpl_id) + line = line.replace(pkl_id, wanted_pkl_id) + line = line.replace(assetmap_id, wanted_assetmap_id) + line = line.replace(video_mxf_id, wanted_video_mxf_id) + line = line.replace(audio_mxf_id, wanted_audio_mxf_id) + line = line.replace(reel_id, wanted_reel_id) + line = line.replace(issue_date, wanted_issue_date) + for i in range(0, len(asset_hashes)): + line = line.replace(asset_hashes[i], wanted_asset_hashes[i]) print line,