Various test hackery.
[libdcp.git] / test / ref / make.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import fileinput
6 from lxml import etree
7
8 assetmap_namespace = 'http://www.smpte-ra.org/schemas/429-9/2007/AM'
9 cpl_namespace = 'http://www.smpte-ra.org/schemas/429-7/2006/CPL'
10 pkl_namespace = 'http://www.smpte-ra.org/schemas/429-8/2007/PKL'
11
12 wanted_cpl_id = 'df0e4141-13c3-4a7a-bef8-b5a04fcbc4bb'
13 wanted_pkl_id = '8e293965-f8ad-48c6-971d-261b01f65cdb'
14 wanted_assetmap_id = '18be072e-5a0f-44e1-b2eb-c8a52ae12789'
15 wanted_video_mxf_id = '81fb54df-e1bf-4647-8788-ea7ba154375b'
16 wanted_audio_mxf_id = 'c38bdd62-ce03-4988-8603-195f134207c7'
17 wanted_reel_id = 'b135d5cf-d180-43d8-b0b3-7373737b73bf'
18 wanted_asset_hashes = ['E2vhyxdJQhEzSQZdp31w84ZZpfk=', '9OVODrw+zTkSbkGduoQ30k3Kk6Y=', '5E8Q9swcc2bBbFF3IEPNXfIP8gM=']
19 wanted_issue_date = '2012-07-17T04:45:18+00:00'
20
21 os.system('rm -rf DCP')
22 os.mkdir('DCP')
23 os.system('opendcp_mxf -i j2c -o DCP/video.mxf -r 24')
24 os.system('opendcp_mxf -i wav -o DCP/audio.mxf -r 24')
25 os.system('opendcp_xml --reel DCP/video.mxf DCP/audio.mxf -k feature -t "A Test DCP" -a "A Test DCP"')
26 os.system('mv *.xml DCP')
27
28 cpl_id = None
29 pkl_id = None
30 assetmap_id = None
31 video_mxf_id = None
32 audio_mxf_id = None
33 reel_id = None
34
35 for r, d, f in os.walk('DCP'):
36     for n in f:
37         if n.endswith('cpl.xml'):
38             cpl_id = n[0:-8]
39         elif n.endswith('pkl.xml'):
40             pkl_id = n[0:-8]
41
42 os.rename('DCP/%s_cpl.xml' % cpl_id, 'DCP/%s_cpl.xml' % wanted_cpl_id)
43 os.rename('DCP/%s_pkl.xml' % pkl_id, 'DCP/%s_pkl.xml' % wanted_pkl_id)
44
45 xml = etree.parse('DCP/ASSETMAP.xml')
46 assetmap_id = xml.getroot().find('{%s}Id' % assetmap_namespace).text
47 assetmap_id = assetmap_id.replace('urn:uuid:', '')
48
49 def cpl_name(s):
50     return '{%s}%s' % (cpl_namespace, s)
51
52 xml = etree.parse('DCP/%s_cpl.xml' % wanted_cpl_id)
53
54 video_mxf_id = xml.getroot().find(cpl_name('ReelList')).    \
55                              find(cpl_name('Reel')).        \
56                              find(cpl_name('AssetList')).   \
57                              find(cpl_name('MainPicture')). \
58                              find(cpl_name('Id')).text
59 video_mxf_id = video_mxf_id.replace('urn:uuid:', '')
60
61 audio_mxf_id = xml.getroot().find(cpl_name('ReelList')).    \
62                              find(cpl_name('Reel')).        \
63                              find(cpl_name('AssetList')).   \
64                              find(cpl_name('MainSound')). \
65                              find(cpl_name('Id')).text
66 audio_mxf_id = audio_mxf_id.replace('urn:uuid:', '')
67
68 reel_id =      xml.getroot().find(cpl_name('ReelList')).    \
69                              find(cpl_name('Reel')).        \
70                              find(cpl_name('Id')).text
71 reel_id = reel_id.replace('urn:uuid:', '')
72
73 def pkl_name(s):
74     return '{%s}%s' % (pkl_namespace, s)
75
76 xml = etree.parse('DCP/%s_pkl.xml' % wanted_pkl_id)
77
78 asset_list =   xml.getroot().find(pkl_name('AssetList'))
79 asset_hashes = []
80 print asset_list
81 for a in asset_list.iter():
82     if a.tag == "{%s}Hash" % pkl_namespace:
83         asset_hashes.append(a.text)
84
85 issue_date =    xml.getroot().find(pkl_name('IssueDate')).text
86
87 for r, d, f in os.walk('DCP'):
88     for n in f:
89         if n.endswith('.xml'):
90             for line in fileinput.input(os.path.join(r, n), inplace = 1):
91                 line = line.replace(cpl_id, wanted_cpl_id)
92                 line = line.replace(pkl_id, wanted_pkl_id)
93                 line = line.replace(assetmap_id, wanted_assetmap_id)
94                 line = line.replace(video_mxf_id, wanted_video_mxf_id)
95                 line = line.replace(audio_mxf_id, wanted_audio_mxf_id)
96                 line = line.replace(reel_id, wanted_reel_id)
97                 line = line.replace(issue_date, wanted_issue_date)
98                 for i in range(0, len(asset_hashes)):
99                     line = line.replace(asset_hashes[i], wanted_asset_hashes[i])
100                 print line,
101                 
102