Rename some classes.
[dcpomatic.git] / cscript
1 # -*- mode: python -*-
2 #
3 #    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 #
5 #    This file is part of DCP-o-matic.
6 #
7 #    DCP-o-matic is free software; you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation; either version 2 of the License, or
10 #    (at your option) any later version.
11 #
12 #    DCP-o-matic is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 from __future__ import print_function
22 import glob
23 import shutil
24 import os
25 import copy
26
27 deb_build_depends = dict()
28
29 deb_build_depends_base = ['debhelper', 'python', 'g++', 'pkg-config', 'libsndfile1-dev', 'libgtk2.0-dev']
30
31 deb_build_depends['12.04'] = copy.deepcopy(deb_build_depends_base)
32 deb_build_depends['12.04'].extend(['libssh-dev'])
33 deb_build_depends['14.04'] = copy.deepcopy(deb_build_depends_base)
34 deb_build_depends['14.04'].extend(['libssh-dev'])
35 deb_build_depends['16.04'] = copy.deepcopy(deb_build_depends_base)
36 deb_build_depends['16.04'].extend(['libssh-dev'])
37 deb_build_depends['16.10'] = copy.deepcopy(deb_build_depends_base)
38 deb_build_depends['16.10'].extend(['libssh-dev'])
39 deb_build_depends['17.04'] = copy.deepcopy(deb_build_depends_base)
40 deb_build_depends['17.04'].extend(['libssh-dev'])
41 deb_build_depends['7'] = copy.deepcopy(deb_build_depends_base)
42 deb_build_depends['7'].extend(['libssh-dev'])
43 deb_build_depends['8'] = copy.deepcopy(deb_build_depends_base)
44 deb_build_depends['8'].extend(['libssh-dev'])
45 deb_build_depends['unstable'] = copy.deepcopy(deb_build_depends_base)
46
47 deb_depends = dict()
48
49 deb_depends_base = ['libc6', 'libsndfile1', 'libsamplerate0', 'libxmlsec1', 'libxmlsec1-openssl', 'libcurl3', 'libgtk2.0-0']
50
51 deb_depends['12.04'] = copy.deepcopy(deb_depends_base)
52 deb_depends['12.04'].extend(['libboost-filesystem1.48.0',
53                              'libboost-thread1.48.0',
54                              'libboost-regex1.48.0',
55                              'libmagick++4',
56                              'libxml++2.6-2',
57                              'libboost-date-time1.48.0',
58                              'libzip2',
59                              'libicu48',
60                              'libnettle4',
61                              'libssh-4'])
62
63 deb_depends['14.04'] = copy.deepcopy(deb_depends_base)
64 deb_depends['14.04'].extend(['libboost-filesystem1.54.0',
65                              'libboost-thread1.54.0',
66                              'libboost-regex1.54.0',
67                              'libmagick++5',
68                              'libxml++2.6-2',
69                              'libboost-date-time1.54.0',
70                              'libzip2',
71                              'libcairomm-1.0-1',
72                              'libpangomm-1.4-1,'
73                              'libicu52',
74                              'libnettle4',
75                              'libssh-4'])
76
77 deb_depends['16.04'] = copy.deepcopy(deb_depends_base)
78 deb_depends['16.04'].extend(['libboost-filesystem1.58.0',
79                              'libboost-thread1.58.0',
80                              'libboost-regex1.58.0',
81                              'libmagick++-6.q16-5v5',
82                              'libxml++2.6-2v5',
83                              'libboost-date-time1.58.0',
84                              'libzip4',
85                              'libcairomm-1.0-1v5',
86                              'libpangomm-1.4-1v5',
87                              'libwxgtk3.0-0v5',
88                              'libicu55',
89                              'libnettle6',
90                              'libssh-4'])
91
92 deb_depends['16.10'] = copy.deepcopy(deb_depends_base)
93 deb_depends['16.10'].extend(['libboost-filesystem1.61.0',
94                              'libboost-thread1.61.0',
95                              'libboost-regex1.61.0',
96                              'libmagick++-6.q16-5v5',
97                              'libxml++2.6-2v5',
98                              'libboost-date-time1.61.0',
99                              'libzip4',
100                              'libwxgtk3.0-0v5',
101                              'libicu57',
102                              'libnettle6',
103                              'libssh-4'])
104
105 deb_depends['17.04'] = copy.deepcopy(deb_depends_base)
106 deb_depends['17.04'].extend(['libboost-filesystem1.62.0',
107                              'libboost-thread1.62.0',
108                              'libboost-regex1.62.0',
109                              'libmagick++-6.q16-7',
110                              'libxml++2.6-2v5',
111                              'libboost-date-time1.62.0',
112                              'libzip4',
113                              'libwxgtk3.0-0v5',
114                              'libicu57',
115                              'libnettle6',
116                              'libssh-4'])
117
118 deb_depends['7'] = copy.deepcopy(deb_depends_base)
119 deb_depends['7'].extend(['libboost-filesystem1.49.0',
120                              'libboost-thread1.49.0',
121                              'libboost-regex1.49.0',
122                              'libmagick++5',
123                              'libxml++2.6-2',
124                              'libboost-date-time1.49.0',
125                              'libzip2',
126                              'libcairomm-1.0-1',
127                              'libpangomm-1.4-1',
128                              'libicu48',
129                              'libnettle4',
130                              'libnotify4'])
131
132 deb_depends['8'] = copy.deepcopy(deb_depends_base)
133 deb_depends['8'].extend(['libboost-filesystem1.55.0',
134                          'libboost-thread1.55.0',
135                          'libboost-date-time1.55.0',
136                          'libboost-regex1.55.0',
137                          'libmagick++-6.q16-5',
138                          'libxml++2.6-2',
139                          'libzip2',
140                          'libcairomm-1.0-1',
141                          'libpangomm-1.4-1',
142                          'libwxgtk3.0-0',
143                          'libxcb-xfixes0',
144                          'libxcb-shape0',
145                          'libicu52',
146                          'libnettle4',
147                          'libssh-4'])
148
149 deb_depends['unstable'] = copy.deepcopy(deb_depends_base)
150 deb_depends['unstable'].extend(['libboost-filesystem1.58.0',
151                                 'libboost-thread1.58.0',
152                                 'libboost-regex1.58.0',
153                                 'libmagick++-6.q16-5v5',
154                                 'libxml++2.6-2v5',
155                                 'libgtk2.0-0',
156                                 'libboost-date-time1.58.0',
157                                 'libzip2',
158                                 'libicu52',
159                                 'libnettle6'])
160
161 def packages(name, packages, f):
162     s = '%s: ' % name
163     for p in packages:
164         s += str(p) + ', '
165     print(s[:-2], file=f)
166
167 def make_control(debian_version, bits, filename, debug):
168     f = open(filename, 'w')
169     print('Source: dcpomatic', file=f)
170     print('Section: video', file=f)
171     print('Priority: extra', file=f)
172     print('Maintainer: Carl Hetherington <carl@dcpomatic.com>', file=f)
173     packages('Build-Depends', deb_build_depends[debian_version], f)
174     print('Standards-Version: 3.9.3', file=f)
175     print('Homepage: http://dcpomatic.com/', file=f)
176     print('', file=f)
177     print('Package: dcpomatic', file=f)
178     if bits == 32:
179         print('Architecture: i386', file=f)
180     else:
181         print('Architecture: amd64', file=f)
182
183     packages('Depends', deb_depends[debian_version], f)
184
185     print('Description: Generator of Digital Cinema Packages (DCPs)', file=f)
186     print('  DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio', file=f)
187     print('  files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant', file=f)
188     print('  digital projectors.', file=f)
189
190     if debug:
191         print('', file=f)
192         print('Package: dcpomatic-dbg', file=f)
193         if bits == 32:
194             print('Architecture: i386', file=f)
195         else:
196             print('Architecture: amd64', file=f)
197         print('Section: debug', file=f)
198         print('Priority: extra', file=f)
199         packages('Depends', deb_depends[debian_version], f)
200         print('Description: debugging symbols for dcpomatic', file=f)
201         print('  This package contains the debugging symbols for dcpomatic.', file=f)
202         print('', file=f)
203
204 def make_spec(filename, version, target):
205     """Make a .spec file for a RPM build"""
206     f = open(filename, 'w')
207     print('Summary:A program that generates Digital Cinema Packages (DCPs) from video and audio files', file=f)
208     print('Name:dcpomatic2', file=f)
209     print('Version:%s' % version, file=f)
210     print('Release:1%{?dist}', file=f)
211     print('License:GPL', file=f)
212     print('Group:Applications/Multimedia', file=f)
213     print('URL:http://dcpomatic.com/', file=f)
214     print('Requires: ImageMagick-c++, glibmm24, libzip', file=f)
215     print('', file=f)
216     print('%description', file=f)
217     print('DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio ', file=f)
218     print('files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant ', file=f)
219     print('digital projectors.', file=f)
220     print('', file=f)
221     print('%files', file=f)
222     print('%{_bindir}/dcpomatic2', file=f)
223     print('%{_bindir}/dcpomatic2_batch', file=f)
224     print('%{_bindir}/dcpomatic2_cli', file=f)
225     print('%{_bindir}/dcpomatic2_create', file=f)
226     print('%{_bindir}/dcpomatic2_kdm', file=f)
227     print('%{_bindir}/dcpomatic2_server', file=f)
228     print('%{_bindir}/dcpomatic2_server_cli', file=f)
229     print('%{_bindir}/dcpomatic2_kdm_cli', file=f)
230     print('%{_datadir}/applications/dcpomatic2.desktop', file=f)
231     print('%{_datadir}/applications/dcpomatic2_batch.desktop', file=f)
232     print('%{_datadir}/applications/dcpomatic2_server.desktop', file=f)
233     print('%{_datadir}/applications/dcpomatic2_kdm.desktop', file=f)
234     print('%{_datadir}/dcpomatic2/dcpomatic2_server_small.png', file=f)
235     print('%{_datadir}/dcpomatic2/LiberationSans-Regular.ttf', file=f)
236     print('%{_datadir}/dcpomatic2/LiberationSans-Italic.ttf', file=f)
237     print('%{_datadir}/dcpomatic2/LiberationSans-Bold.ttf', file=f)
238     print('%{_datadir}/dcpomatic2/splash.png', file=f)
239     for r in ['128x128', '16x16', '22x22', '256x256', '32x32', '48x48', '512x512', '64x64']:
240         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2.png' % r, file=f)
241         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_batch.png' % r, file=f)
242         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_kdm.png' % r, file=f)
243         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_server.png' % r, file=f)
244     for l in ['de_DE', 'es_ES', 'fr_FR', 'it_IT', 'sv_SE', 'nl_NL', 'ru_RU', 'pl_PL', 'da_DK', 'pt_PT', 'pt_BR', 'sk_SK', 'cs_CZ', 'uk_UA', 'zh_CN']:
245         print('%%{_datadir}/locale/%s/LC_MESSAGES/dcpomatic2.mo' % l, file=f)
246         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2-wx.mo' % l, file=f)
247         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2.mo' % l, file=f)
248     print('', file=f)
249     print('%prep', file=f)
250     print('rm -rf $RPM_BUILD_DIR/dcpomatic-%s' % version, file=f)
251     print('tar xjf $RPM_SOURCE_DIR/dcpomatic-%s.tar.bz2' % version, file=f)
252     print('%build', file=f)
253     print('cd dcpomatic-%s' % version, file=f)
254     print('export PKG_CONFIG_PATH=%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig' % (target.directory, target.directory), file=f)
255
256     if target.distro == 'centos' and target.version == '5':
257         prefix = 'BUILDROOT/usr'
258     else:
259         prefix = '%{buildroot}/usr'
260
261     print('CXXFLAGS="-I%s/include" LDFLAGS="-L%s/lib" ./waf configure --prefix=%s --install-prefix=/usr %s' %
262           (target.directory, target.directory, prefix, configure_options(target)), file=f)
263     print('./waf', file=f)
264     print('%install', file=f)
265     print('cd dcpomatic-%s' % version, file=f)
266     print('./waf install', file=f)
267     print('', file=f)
268     print('%post', file=f)
269     print('/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
270     print('', file=f)
271     print('%postun', file=f)
272     print('if [ $1 -eq 0 ] ; then', file=f)
273     print('    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null', file=f)
274     print('    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
275     print('fi', file=f)
276     print('', file=f)
277     print('%posttrans', file=f)
278     print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
279
280 def dependencies(target):
281
282     if target.platform == 'linux':
283         ffmpeg_options = { 'shared': False }
284     else:
285         ffmpeg_options = {}
286
287     return (('ffmpeg-cdist', 'c7df8d5', ffmpeg_options),
288             ('libdcp', 'a3032f3'),
289             ('libsub', 'a04f1d5'),
290             ('rtaudio-cdist', None))
291
292 def configure_options(target):
293     opt = ''
294     if target.debug:
295         opt += ' --enable-debug'
296     if target.platform == 'windows':
297         opt += ' --target-windows'
298     elif target.platform == 'linux':
299         opt += ' --static-dcpomatic --static-wxwidgets --static-ffmpeg --static-dcp --static-sub --static-cxml'
300         if target.distro == 'centos':
301             opt += ' --static-xmlsec --static-ssh --disable-tests'
302             if target.version == '6.5':
303                 opt += ' --static-boost --static-xmlpp'
304             elif target.version == '7':
305                 opt += ' --workaround-gssapi --static-xmlpp'
306
307     # Build Windows debug versions with static linking as I think gdb works better then
308     if target.debug and target.platform == 'windows':
309         opt += ' --static-dcpomatic'
310
311     return opt
312
313 def build(target, options):
314     target.command('./waf configure --prefix=%s %s' % (target.directory, configure_options(target)))
315     target.command('./waf')
316
317     if target.platform == 'linux' or target.platform == 'osx':
318         target.command('./waf install')
319
320 def package_windows(target):
321     identifier = ''
322     if target.version is not None:
323         identifier = '%s.' % target.version
324     identifier += '%d' % target.bits
325     shutil.copyfile('build/platform/windows/installer.%s.nsi' % identifier, 'build/platform/windows/installer2.%s.nsi' % identifier)
326     target.command('sed -i "s~%%resources%%~%s/platform/windows~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
327     target.command('sed -i "s~%%graphics%%~%s/graphics~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
328     target.command('sed -i "s~%%static_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.windows_prefix, identifier))
329     target.command('sed -i "s~%%cdist_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.directory, identifier))
330     target.command('sed -i "s~%%mingw%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.mingw_path, identifier))
331     target.command('sed -i "s~%%binaries%%~%s/build~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
332     target.command('sed -i "s~%%bits%%~32~g" build/platform/windows/installer2.%s.nsi' % identifier)
333     target.command('makensis build/platform/windows/installer2.%s.nsi' % identifier)
334     return os.path.abspath(glob.glob('build/platform/windows/*%s*.exe' % target.bits)[0])
335
336 def package_debian(target, cpu, version):
337     make_control(target.version, target.bits, 'debian/control', target.debug)
338     target.command('./waf dist')
339     f = open('debian/files', 'w')
340     print('dcpomatic_%s-1_%s.deb video extra' % (version, cpu), file=f)
341     shutil.rmtree('build/deb', ignore_errors=True)
342
343     os.makedirs('build/deb')
344     os.chdir('build/deb')
345     shutil.move('../../dcpomatic-%s.tar.bz2' % version, 'dcpomatic_%s.orig.tar.bz2' % version)
346     target.command('tar xjf dcpomatic_%s.orig.tar.bz2' % version)
347     os.chdir('dcpomatic-%s' % version)
348     target.command('dch -b -v %s-1 "New upstream release."' % version)
349     target.set('CDIST_LINKFLAGS', target.get('LINKFLAGS'))
350     target.set('CDIST_CXXFLAGS', target.get('CXXFLAGS'))
351     target.set('CDIST_PKG_CONFIG_PATH', target.get('PKG_CONFIG_PATH'))
352
353     target.set('CDIST_CONFIGURE', '"' + configure_options(target) + '"')
354     if target.debug:
355         target.set('CDIST_DEBUG_PACKAGE', '--dbg-package=dcpomatic-dbg')
356     if target.version in ['15.04', '15.10', '16.04', '16.10', '17.04', '8', 'unstable']:
357         target.set('CDIST_LOCALE_PREFIX', '/usr/share/locale')
358     else:
359         target.set('CDIST_LOCALE_PREFIX', '/usr/local/share/locale')
360
361     target.command('dpkg-buildpackage -uc -us')
362
363     debs = []
364     for p in glob.glob('../*.deb'):
365         debs.append(os.path.abspath(p))
366
367     return debs
368
369 def package_rpm(target, cpu, version):
370     topdir = os.path.realpath('build/rpmbuild')
371     os.makedirs('%s/BUILD' % topdir)
372     os.makedirs('%s/RPMS' % topdir)
373     os.makedirs('%s/SOURCES' % topdir)
374     os.makedirs('%s/SPECS' % topdir)
375     os.makedirs('%s/SRPMS' % topdir)
376
377     target.command('./waf dist')
378     shutil.copyfile(
379         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
380         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
381         )
382
383     make_spec('build/platform/linux/dcpomatic2.spec', version, target)
384     cmd = 'rpmbuild --define \'_topdir %s\' -bb build/platform/linux/dcpomatic2.spec' % topdir
385     if target.distro == 'centos' and target.version == '5':
386         cmd += ' --buildroot %s/BUILD/dcpomatic-%s/BUILDROOT' % (topdir, version)
387     target.command(cmd)
388     rpms = []
389
390     if cpu == "amd64":
391         cpu = "x86_64"
392     else:
393         if target.distro == 'centos' and target.version == '5':
394             cpu = "i386"
395         else:
396             cpu = "i686"
397
398     print('Looking in %s/RPMS/%s/*.rpm' % (topdir, cpu))
399     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
400         print('found %s' % p)
401         rpms.append(os.path.abspath(p))
402
403     return rpms
404
405 def package(target, version):
406     if target.platform == 'windows':
407         return package_windows(target)
408     elif target.platform == 'linux':
409         if target.bits == 32:
410             cpu = 'i386'
411         else:
412             cpu = 'amd64'
413
414         if target.distro == 'debian' or target.distro == 'ubuntu':
415             return package_debian(target, cpu, version)
416         elif target.distro == 'centos' or target.distro == 'fedora':
417             return package_rpm(target, cpu, version)
418     elif target.platform == 'osx':
419         target.command('bash platform/osx/make_dmg.sh %s' % target.directory)
420         return [os.path.abspath(x) for x in glob.glob('build/platform/osx/DCP-o-matic*.dmg')]
421     elif target.platform == 'docker':
422         shutil.copyfile(target.deb, 'build/platform/docker')
423         f = open('build/platform/docker/Dockerfile', 'w')
424         print('FROM debian:jessie', file=f)
425         print('MAINTAINER carl@dcpomatic.com', file=f)
426         print('ADD build/platform/docker/dcpomatic_%s-1_amd64.deb /tmp' % (version, version), file=f)
427         print('RUN apt-get -o Acquire:http::Timeout="5" update; exit 0', file=f)
428         print('RUN dpkg -i /tmp/dcpomatic_*.deb; exit 0', file=f)
429         print('RUN apt-get -y -f install', file=f)
430         print('RUN apt-get clean', file=f)
431         print('EXPOSE 6192', file=f)
432         print('CMD ["/usr/bin/dcpomatic2_server_cli", "--verbose"]', file=f)
433         f.close()
434         target.command('docker build build/platform/docker -t dcpomatic-server:%s' % version)
435         target.command('docker save dcpomatic-server:%s -o dcpomatic-server-%s-docker.tar' % (version, version))
436
437 def make_pot(target):
438     target.command('./waf pot')
439     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
440             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
441             os.path.abspath('build/src/tools/dcpomatic.pot')]
442
443 def make_manual(target):
444     os.chdir('doc/manual')
445     target.command('make')
446     target.command('pdflatex colour.tex')
447     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
448
449 def test(target, test):
450     if target.platform != 'windows':
451         target.set('LC_ALL', 'C')
452         cmd = 'run/tests '
453         if target.debug:
454             cmd += '--backtrace '
455         if test is not None:
456             cmd += '--run_test=%s' % test
457         target.command(cmd)