2016-12-03 11:23:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-04-10 17:50:00 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2016-12-03 11:23:23 +00:00
|
|
|
|
2019-06-05 06:04:54 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2019 OpenLP Developers #
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# This program is free software: you can redistribute it and/or modify #
|
|
|
|
# it under the terms of the GNU General Public License as published by #
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, #
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
|
|
# GNU General Public License for more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License #
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2016-12-03 11:23:23 +00:00
|
|
|
"""
|
|
|
|
Windows Build Script
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
This script is used to build the Windows binary and the accompanying installer.
|
|
|
|
For this script to work out of the box, it depends on a number of things:
|
|
|
|
|
2019-02-15 20:19:31 +00:00
|
|
|
Python 3.7
|
2016-12-03 11:23:23 +00:00
|
|
|
|
|
|
|
PyQt5
|
|
|
|
You should already have this installed, OpenLP doesn't work without it. The
|
2017-09-26 21:58:42 +00:00
|
|
|
version the script expects is the packaged one available from pypi.
|
2016-12-03 11:23:23 +00:00
|
|
|
|
|
|
|
PyEnchant
|
|
|
|
This script expects the precompiled, installable version of PyEnchant to be
|
|
|
|
installed. You can find this on the PyEnchant site.
|
|
|
|
|
2019-04-10 17:50:00 +00:00
|
|
|
WiX Toolset
|
2019-04-10 18:36:12 +00:00
|
|
|
The toolset should be installed into "C:\\%PROGRAMFILES%\\WiX Toolset v3.11"
|
|
|
|
or similar.
|
2016-12-03 11:23:23 +00:00
|
|
|
|
|
|
|
Sphinx
|
|
|
|
This is used to build the documentation. The documentation trunk must be at
|
|
|
|
the same directory level as OpenLP trunk and named "documentation".
|
|
|
|
|
|
|
|
HTML Help Workshop
|
|
|
|
This is used to create the help file.
|
|
|
|
|
|
|
|
PyInstaller
|
2017-09-26 21:58:42 +00:00
|
|
|
PyInstaller can be installed from pypi.
|
2016-12-03 11:23:23 +00:00
|
|
|
|
2019-09-13 19:32:29 +00:00
|
|
|
Git
|
|
|
|
You need the command line "git" client installed.
|
2016-12-03 11:23:23 +00:00
|
|
|
|
|
|
|
OpenLP
|
|
|
|
A checkout of the latest code, in a branch directory, which is in a Bazaar
|
|
|
|
shared repository directory. This means your code should be in a directory
|
2016-12-05 18:23:50 +00:00
|
|
|
structure like this: "openlp\\branch-name".
|
2016-12-03 11:23:23 +00:00
|
|
|
|
|
|
|
windows-builder.py
|
|
|
|
This script, of course. It should be in the "windows-installer" directory
|
|
|
|
at the same level as OpenLP trunk.
|
|
|
|
|
|
|
|
Mako
|
|
|
|
Mako Templates for Python. This package is required for building the
|
|
|
|
remote plugin. It can be installed by going to your
|
2016-12-05 18:23:50 +00:00
|
|
|
python_directory\\scripts\\.. and running "easy_install Mako". If you do not
|
2016-12-03 11:23:23 +00:00
|
|
|
have easy_install, the Mako package can be obtained here:
|
|
|
|
|
|
|
|
http://www.makotemplates.org/download.html
|
|
|
|
|
|
|
|
MuPDF
|
|
|
|
Required for PDF support in OpenLP. Download the windows build from
|
|
|
|
mupdf.com, extract it, and set the mutoolbin option in the config file to
|
|
|
|
point to mutool.exe.
|
|
|
|
|
|
|
|
Portable App Builds
|
|
|
|
The following are required if you are planning to make a portable build of
|
|
|
|
OpenLP. The portable build conforms to the standards published by
|
|
|
|
PortableApps.com:
|
|
|
|
|
|
|
|
http://portableapps.com/development/portableapps.com_format
|
|
|
|
|
|
|
|
PortableApps.com Installer:
|
|
|
|
|
|
|
|
http://portableapps.com/apps/development/portableapps.com_installer
|
|
|
|
|
|
|
|
PortableApps.com Launcher:
|
|
|
|
|
|
|
|
http://portableapps.com/apps/development/portableapps.com_launcher
|
|
|
|
|
|
|
|
NSIS Portable (Unicode version):
|
|
|
|
|
|
|
|
http://portableapps.com/apps/development/nsis_portable
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2017-09-27 20:53:43 +00:00
|
|
|
import glob
|
2019-03-05 19:55:59 +00:00
|
|
|
import sys
|
2016-12-03 11:23:23 +00:00
|
|
|
from distutils import dir_util
|
2019-04-10 19:59:51 +00:00
|
|
|
from hashlib import md5
|
2019-07-04 06:23:21 +00:00
|
|
|
from shutil import copy, copytree, move, rmtree
|
2016-12-03 11:23:23 +00:00
|
|
|
|
2019-11-13 21:34:04 +00:00
|
|
|
from lxml.etree import ElementTree
|
2019-04-25 22:12:10 +00:00
|
|
|
from lxml.builder import E, ElementMaker
|
2019-11-13 21:34:04 +00:00
|
|
|
from lxml.objectify import fromstring
|
2019-04-09 04:14:43 +00:00
|
|
|
|
2016-12-03 11:23:23 +00:00
|
|
|
from builder import Builder
|
|
|
|
|
|
|
|
|
|
|
|
class WindowsBuilder(Builder):
|
|
|
|
"""
|
|
|
|
The :class:`WindowsBuilder` class encapsulates everything that is needed
|
|
|
|
to build a Windows installer.
|
|
|
|
"""
|
2023-09-08 06:15:32 +00:00
|
|
|
# Make mypy happy
|
|
|
|
program_files: str
|
|
|
|
candle_exe: str
|
|
|
|
light_exe: str
|
|
|
|
htmlhelp_exe: str
|
|
|
|
mutool_exe: str
|
|
|
|
dist_path: str
|
|
|
|
icon_path: str
|
|
|
|
license_path: str
|
|
|
|
portable_source_path: str
|
|
|
|
portable_dest_path: str
|
|
|
|
portablelauncher_exe: str
|
|
|
|
portableinstaller_exe: str
|
|
|
|
|
|
|
|
def _pep440_to_windows_version(self, version: str) -> str:
|
|
|
|
"""Convert a PEP440-compatible version string to a Windows version string"""
|
2023-09-14 18:39:44 +00:00
|
|
|
if pep440 := self.parse_pep440_version(version):
|
2023-09-08 06:15:32 +00:00
|
|
|
build_number = 5000
|
2023-09-14 18:39:44 +00:00
|
|
|
if pep440.get('pre'):
|
|
|
|
if pep440['pre'] == 'a':
|
2023-09-08 06:15:32 +00:00
|
|
|
build_number = 1000
|
2023-09-14 18:39:44 +00:00
|
|
|
elif pep440['pre'] == 'b':
|
2023-09-08 06:15:32 +00:00
|
|
|
build_number = 2000
|
2023-09-14 18:39:44 +00:00
|
|
|
elif pep440['pre'] == 'rc':
|
2023-09-08 06:15:32 +00:00
|
|
|
build_number = 3000
|
2023-09-14 18:39:44 +00:00
|
|
|
if pep440.get('rel'):
|
2023-09-08 06:15:32 +00:00
|
|
|
try:
|
2023-09-14 18:39:44 +00:00
|
|
|
rel = int(pep440['rel'])
|
2023-09-08 06:15:32 +00:00
|
|
|
build_number += rel
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2023-09-14 18:39:44 +00:00
|
|
|
return f'{pep440["major"]}.{pep440["minor"]}.{pep440["fix"]}.{build_number}'
|
2023-09-08 06:15:32 +00:00
|
|
|
else:
|
|
|
|
return '0.0.0.0'
|
2016-12-03 11:23:23 +00:00
|
|
|
|
2019-04-09 04:14:43 +00:00
|
|
|
def _walk_dirs(self, dir_dict, path):
|
2016-12-03 11:23:23 +00:00
|
|
|
"""
|
2019-04-09 04:14:43 +00:00
|
|
|
Walk a dictionary according to path
|
2016-12-03 11:23:23 +00:00
|
|
|
"""
|
2019-04-09 04:14:43 +00:00
|
|
|
parts = path.split(os.sep)
|
|
|
|
search_key = parts.pop(0)
|
|
|
|
if search_key in dir_dict.keys():
|
|
|
|
if not parts:
|
|
|
|
return dir_dict[search_key]
|
|
|
|
else:
|
2019-04-10 17:50:00 +00:00
|
|
|
return self._walk_dirs(dir_dict[search_key], os.sep.join(parts))
|
2019-04-09 04:14:43 +00:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2019-11-13 21:34:04 +00:00
|
|
|
def _get_dirs_and_files(self, install_dir, start_dir):
|
2019-04-09 04:14:43 +00:00
|
|
|
"""
|
|
|
|
Walk down a directory recursively and build up the XML for WiX
|
|
|
|
"""
|
2019-11-13 21:34:04 +00:00
|
|
|
self._openlp_id = None
|
2019-04-09 04:14:43 +00:00
|
|
|
start_base, start_path = os.path.split(start_dir)
|
2019-11-13 21:34:04 +00:00
|
|
|
element = install_dir
|
2019-04-09 04:14:43 +00:00
|
|
|
directories = {start_path: {'__dir__': element}}
|
|
|
|
components = []
|
2019-11-13 21:34:04 +00:00
|
|
|
component_ids = []
|
2019-04-25 22:12:10 +00:00
|
|
|
FxE = ElementMaker(namespace='http://schemas.microsoft.com/wix/FirewallExtension',
|
|
|
|
nsmap={'fw': 'http://schemas.microsoft.com/wix/FirewallExtension'})
|
2019-04-09 04:14:43 +00:00
|
|
|
|
|
|
|
for root, _, files in os.walk(start_dir):
|
|
|
|
parent = os.sep.join(root.replace(os.path.join(start_base, ''), '').split(os.sep)[:-1])
|
|
|
|
base = os.path.basename(root)
|
|
|
|
if root != start_dir:
|
2019-11-13 21:34:04 +00:00
|
|
|
dir_id = 'd_{}'.format(md5(os.path.join(parent, base).encode('utf8')).hexdigest())
|
|
|
|
new_element = E.Directory(Id=dir_id, Name=base)
|
|
|
|
element.append(new_element)
|
|
|
|
element = new_element
|
2019-04-09 04:14:43 +00:00
|
|
|
new_dir = {'__dir__': element}
|
2019-04-10 17:50:00 +00:00
|
|
|
parent_dir = self._walk_dirs(directories, parent)
|
2019-04-09 04:14:43 +00:00
|
|
|
parent_dir[base] = new_dir
|
|
|
|
parent_dir['__dir__'].append(element)
|
|
|
|
for fname in files:
|
2019-11-13 21:34:04 +00:00
|
|
|
source = os.path.join(root, fname)
|
|
|
|
source_id = 'f_{}'.format(md5(source.encode('utf8')).hexdigest())
|
|
|
|
component_ids.append(source_id)
|
2019-04-10 21:27:09 +00:00
|
|
|
if self.arch == 'x64':
|
2019-11-13 21:34:04 +00:00
|
|
|
file_ = E.File(Id=source_id, Name=fname, Source=source, ProcessorArchitecture='x64')
|
|
|
|
component = E.Component(file_, Id=source_id, Guid='*', DiskId='1', Win64='yes')
|
2019-04-10 21:27:09 +00:00
|
|
|
else:
|
2019-11-13 21:34:04 +00:00
|
|
|
file_ = E.File(Id=source_id, Name=fname, Source=source)
|
|
|
|
component = E.Component(file_, Id=source_id, Guid='*', DiskId='1')
|
2019-04-25 22:27:54 +00:00
|
|
|
if source.endswith('OpenLP.exe'):
|
2019-11-13 21:34:04 +00:00
|
|
|
self._openlp_id = source_id
|
|
|
|
file_.set('KeyPath', 'yes')
|
|
|
|
fw_program = '[#{}]'.format(source_id)
|
|
|
|
component.append(FxE.FirewallException(Id='OpenLP_TCP', Name='$(var.ProductName)',
|
|
|
|
IgnoreFailure='yes', Program=fw_program,
|
|
|
|
Protocol='tcp', Scope='any'))
|
|
|
|
component.append(FxE.FirewallException(Id='OpenLP_UDP', Name='$(var.ProductName)',
|
|
|
|
IgnoreFailure='yes', Program=fw_program,
|
|
|
|
Protocol='udp', Scope='any'))
|
|
|
|
component.append(E.Shortcut(Id='ApplicationStartMenuShortcut', Name='$(var.ProductName)',
|
|
|
|
Description='$(var.Description)', Directory='ProgramMenuDir',
|
|
|
|
Icon='OpenLP.ico', Advertise='yes', WorkingDirectory='INSTALLDIR'))
|
|
|
|
component.append(E.Shortcut(Id='DebugStartMenuShortcut', Name='$(var.ProductName) (Debug)',
|
|
|
|
Description='Run $(var.ProductName) with debug logging enabled',
|
|
|
|
Directory='ProgramMenuDir', Arguments='--log-level debug',
|
|
|
|
Icon='OpenLP.ico', Advertise='yes', WorkingDirectory='INSTALLDIR'))
|
|
|
|
component.append(E.ProgId(
|
|
|
|
E.Extension(
|
|
|
|
E.Verb(Id="Open", Command="Open", Argument=" "%1""),
|
|
|
|
E.MIME(Advertise="yes", ContentType="application/-x-openlp-service", Default="yes"),
|
|
|
|
Id="osz"
|
|
|
|
),
|
|
|
|
E.Extension(
|
|
|
|
E.Verb(Id="Open", Command="Open", Argument=" "%1""),
|
|
|
|
E.MIME(Advertise="yes", ContentType="application/-x-openlp-service-lite", Default="yes"),
|
|
|
|
Id="oszl"
|
|
|
|
),
|
|
|
|
Id="OpenLP.Service",
|
|
|
|
Description="OpenLP Service File",
|
|
|
|
Icon="service_file.ico",
|
|
|
|
Advertise="yes"
|
|
|
|
))
|
|
|
|
elif source.endswith('OpenLP.chm'):
|
|
|
|
component.append(E.Shortcut(Id='HelpStartMenuShortcut', Name='$(var.ProductName) Help',
|
|
|
|
Description='Help file for $(var.ProductName)',
|
|
|
|
Target='[#{}]'.format(source_id), WorkingDirectory='INSTALLDIR'))
|
2019-04-09 04:14:43 +00:00
|
|
|
element.append(component)
|
|
|
|
components.append(component)
|
2019-11-13 21:34:04 +00:00
|
|
|
return component_ids
|
2019-04-09 04:14:43 +00:00
|
|
|
|
|
|
|
def _create_wix_file(self):
|
|
|
|
"""
|
|
|
|
Create a WiX project file
|
|
|
|
"""
|
|
|
|
self._print('Creating WiX file...')
|
2016-12-06 20:51:27 +00:00
|
|
|
config_dir = os.path.dirname(self.config_path)
|
2019-04-09 04:14:43 +00:00
|
|
|
self._print_verbose('Reading base WiX file')
|
2019-04-10 17:50:00 +00:00
|
|
|
with open(os.path.join(config_dir, 'OpenLP-base.wxs'), 'rt') as base_file:
|
2019-04-09 04:14:43 +00:00
|
|
|
xml = base_file.read()
|
2019-09-24 18:47:13 +00:00
|
|
|
if '.dev' in self.version:
|
|
|
|
windows_version = self.version.replace('.dev', '.')
|
|
|
|
windows_version = windows_version.rsplit('+', 1)[0]
|
|
|
|
else:
|
2023-09-08 06:15:32 +00:00
|
|
|
windows_version = self._pep440_to_windows_version(self.version)
|
2019-11-13 21:34:04 +00:00
|
|
|
xml = xml % {
|
|
|
|
'dialog': os.path.join(config_dir, 'WizardMain.bmp'),
|
|
|
|
'banner': os.path.join(config_dir, 'WizardBanner.bmp'),
|
|
|
|
'license': os.path.join(config_dir, 'LICENSE.rtf'),
|
|
|
|
'platform': self.arch,
|
|
|
|
'progfilefolder': 'ProgramFiles64Folder' if self.arch == 'x64' else 'ProgramFilesFolder',
|
|
|
|
'systemfolder': 'System64Folder' if self.arch == 'x64' else 'SystemFolder',
|
|
|
|
'version': windows_version
|
|
|
|
}
|
|
|
|
root = fromstring(xml.encode('utf8'))
|
|
|
|
# Find the INSTALLDIR directory component and populate it with our files and folders
|
|
|
|
install_dir = root.xpath('//wix:Directory[@Id="INSTALLDIR"]',
|
|
|
|
namespaces={'wix': 'http://schemas.microsoft.com/wix/2006/wi'})[0]
|
2019-04-09 04:14:43 +00:00
|
|
|
self._print_verbose('Creating XML fragments from files and directories')
|
2019-11-13 21:34:04 +00:00
|
|
|
component_ids = self._get_dirs_and_files(install_dir, self.dist_path)
|
|
|
|
# Write the property for the "Run OpenLP" checkbox
|
|
|
|
product = root.xpath('//wix:Product',
|
|
|
|
namespaces={'wix': 'http://schemas.microsoft.com/wix/2006/wi'})[0]
|
|
|
|
product.append(E.Property(Id='WixShellExecTarget', Value='[#{}]'.format(self._openlp_id)))
|
|
|
|
# Set the component ids for the feature
|
|
|
|
feature = root.xpath('//wix:Feature',
|
|
|
|
namespaces={'wix': 'http://schemas.microsoft.com/wix/2006/wi'})[0]
|
|
|
|
for component_id in component_ids:
|
|
|
|
feature.append(E.ComponentRef(Id=component_id))
|
2019-04-09 04:14:43 +00:00
|
|
|
self._print_verbose('Writing new WiX file')
|
2019-11-13 21:34:04 +00:00
|
|
|
tree = ElementTree(root)
|
2019-04-10 19:06:38 +00:00
|
|
|
with open(os.path.join(config_dir, 'OpenLP.wxs'), 'wb') as f:
|
2019-11-13 21:34:04 +00:00
|
|
|
tree.write(f, encoding='utf-8', xml_declaration=True, pretty_print=True)
|
2019-04-09 04:14:43 +00:00
|
|
|
|
|
|
|
def _run_wix_tools(self):
|
|
|
|
"""
|
|
|
|
Run the WiX toolset to create an installer
|
|
|
|
"""
|
|
|
|
self._print('Running WiX tools...')
|
2019-04-11 16:54:19 +00:00
|
|
|
if self.arch == 'x64':
|
|
|
|
version = '{}-x64'.format(self.version)
|
|
|
|
else:
|
|
|
|
version = self.version
|
|
|
|
msi_file = os.path.abspath(os.path.join(self.dist_path, '..', 'OpenLP-{}.msi'.format(version)))
|
2019-04-10 19:17:39 +00:00
|
|
|
if os.path.exists(msi_file):
|
2019-04-09 04:14:43 +00:00
|
|
|
self._print_verbose('Removing old MSI file')
|
|
|
|
os.unlink(msi_file)
|
2016-12-06 20:51:27 +00:00
|
|
|
config_dir = os.path.dirname(self.config_path)
|
2019-04-11 04:56:12 +00:00
|
|
|
os.chdir(self.dist_path)
|
2019-04-25 21:54:48 +00:00
|
|
|
self._run_command([self.candle_exe, '-ext', 'WiXUtilExtension', '-ext', 'WixUIExtension',
|
|
|
|
'-ext', 'WixFirewallExtension', os.path.join(config_dir, 'OpenLP.wxs')],
|
2019-04-09 04:14:43 +00:00
|
|
|
'Error running WiX tool: candle')
|
2019-04-25 21:54:48 +00:00
|
|
|
self._run_command([self.light_exe, '-ext', 'WiXUtilExtension', '-ext', 'WixUIExtension',
|
|
|
|
'-ext', 'WixFirewallExtension', 'OpenLP.wixobj', '-o', msi_file],
|
2019-04-09 04:14:43 +00:00
|
|
|
'Error running WiX tool: light')
|
2016-12-03 11:23:23 +00:00
|
|
|
|
2016-12-07 13:18:50 +00:00
|
|
|
def _create_portableapp_structure(self):
|
2016-12-03 11:23:23 +00:00
|
|
|
"""
|
|
|
|
Checks the PortableApp directory structure amd creates
|
|
|
|
missing subdirs
|
|
|
|
"""
|
2016-12-09 09:52:33 +00:00
|
|
|
self._print('... Checking PortableApps directory structure...')
|
2016-12-06 21:02:14 +00:00
|
|
|
launcher_path = os.path.join(self.portable_dest_path, 'App', 'Appinfo', 'Launcher')
|
2016-12-03 11:23:23 +00:00
|
|
|
if not os.path.exists(launcher_path):
|
|
|
|
os.makedirs(launcher_path)
|
2016-12-06 21:02:14 +00:00
|
|
|
settings_path = os.path.join(self.portable_dest_path, 'Data', 'Settings')
|
2016-12-03 11:23:23 +00:00
|
|
|
if not os.path.exists(settings_path):
|
|
|
|
os.makedirs(settings_path)
|
|
|
|
|
2016-12-05 18:23:50 +00:00
|
|
|
def _create_portableapps_appinfo_file(self):
|
2016-12-03 11:23:23 +00:00
|
|
|
"""
|
|
|
|
Create a Portabbleapps appinfo.ini file.
|
|
|
|
"""
|
2016-12-09 09:52:33 +00:00
|
|
|
self._print_verbose('... Creating PortableApps appinfo file ...')
|
2016-12-06 20:51:27 +00:00
|
|
|
config_dir = os.path.dirname(self.config_path)
|
2019-09-24 18:47:13 +00:00
|
|
|
if '.dev' in self.version:
|
|
|
|
version, revision = self.version.split('.dev')
|
2016-12-12 19:02:33 +00:00
|
|
|
version = version + '.0' * (2 - version.count('.'))
|
2019-09-24 18:47:13 +00:00
|
|
|
self.portable_version = version + '.' + revision.split('+')[0]
|
2016-12-12 19:02:33 +00:00
|
|
|
else:
|
2023-09-10 04:22:00 +00:00
|
|
|
self.portable_version = self._pep440_to_windows_version(self.version)
|
2016-12-06 20:51:27 +00:00
|
|
|
with open(os.path.join(config_dir, 'appinfo.ini.default'), 'r') as input_file, \
|
2016-12-06 21:02:14 +00:00
|
|
|
open(os.path.join(self.portable_dest_path, 'App', 'Appinfo', 'appinfo.ini'), 'w') as output_file:
|
2016-12-03 11:23:23 +00:00
|
|
|
content = input_file.read()
|
2016-12-10 21:12:38 +00:00
|
|
|
content = content.replace('%(display_version)s', self.portable_version)
|
2016-12-07 13:18:50 +00:00
|
|
|
content = content.replace('%(package_version)s', self.portable_version)
|
2019-03-08 21:20:20 +00:00
|
|
|
content = content.replace('%(arch)s', self.arch)
|
2016-12-03 11:23:23 +00:00
|
|
|
output_file.write(content)
|
|
|
|
|
2016-12-05 18:23:50 +00:00
|
|
|
def _run_portableapp_builder(self):
|
2016-12-03 11:23:23 +00:00
|
|
|
"""
|
|
|
|
Creates a portable installer.
|
|
|
|
1 Copies the distribution to the portable apps directory
|
|
|
|
2 Builds the PortableApps Launcher
|
|
|
|
3 Builds the PortableApps Install
|
|
|
|
"""
|
|
|
|
self._print('Running PortableApps Builder...')
|
2016-12-09 09:52:33 +00:00
|
|
|
self._print_verbose('... Clearing old files')
|
2016-12-03 11:23:23 +00:00
|
|
|
# Remove previous contents of portableapp build directory.
|
2016-12-06 21:02:14 +00:00
|
|
|
if os.path.exists(self.portable_dest_path):
|
|
|
|
rmtree(self.portable_dest_path)
|
2016-12-09 09:52:33 +00:00
|
|
|
self._print_verbose('... Creating PortableApps build directory')
|
2016-12-03 11:23:23 +00:00
|
|
|
# Copy the contents of the OpenLPPortable directory to the portable
|
|
|
|
# build directory.
|
2016-12-06 21:02:14 +00:00
|
|
|
dir_util.copy_tree(self.portable_source_path, self.portable_dest_path)
|
2016-12-07 13:18:50 +00:00
|
|
|
self._create_portableapp_structure()
|
|
|
|
self._create_portableapps_appinfo_file()
|
2016-12-03 11:23:23 +00:00
|
|
|
# Copy distribution files to portableapp build directory.
|
2016-12-09 09:52:33 +00:00
|
|
|
self._print_verbose('... Copying distribution files')
|
2016-12-06 21:02:14 +00:00
|
|
|
portable_app_path = os.path.join(self.portable_dest_path, 'App', 'OpenLP')
|
2016-12-03 11:23:23 +00:00
|
|
|
dir_util.copy_tree(self.dist_path, portable_app_path)
|
|
|
|
# Copy help files to portableapp build directory.
|
|
|
|
if os.path.isfile(os.path.join(self.helpfile_path, 'OpenLP.chm')):
|
2016-12-09 09:52:33 +00:00
|
|
|
self._print_verbose('... Copying help files')
|
2016-12-03 11:23:23 +00:00
|
|
|
dir_util.copy_tree(self.helpfile_path, os.path.join(portable_app_path, 'help'))
|
|
|
|
else:
|
|
|
|
self._print('... WARNING: Windows help file not found')
|
|
|
|
# Build the launcher.
|
2016-12-09 09:52:33 +00:00
|
|
|
self._print_verbose('... Building PortableApps Launcher')
|
2016-12-08 23:38:22 +00:00
|
|
|
self._run_command([self.portablelauncher_exe, self.portable_dest_path],
|
2016-12-09 09:52:33 +00:00
|
|
|
'Error creating PortableApps Launcher')
|
2016-12-03 11:23:23 +00:00
|
|
|
# Build the portable installer.
|
2016-12-09 09:52:33 +00:00
|
|
|
self._print_verbose('... Building PortableApps Installer')
|
2016-12-06 21:02:14 +00:00
|
|
|
self._run_command([self.portableinstaller_exe, self.portable_dest_path],
|
|
|
|
'Error running PortableApps Installer')
|
2019-03-13 20:21:15 +00:00
|
|
|
portable_exe_name = 'OpenLPPortable_{ver}-{arch}.paf.exe'.format(ver=self.portable_version, arch=self.arch)
|
2016-12-12 10:00:31 +00:00
|
|
|
portable_exe_path = os.path.abspath(os.path.join(self.portable_dest_path, '..', portable_exe_name))
|
2016-12-11 12:20:35 +00:00
|
|
|
self._print_verbose('... Portable Build: {}'.format(portable_exe_path))
|
|
|
|
if os.path.exists(portable_exe_path):
|
2016-12-12 16:43:19 +00:00
|
|
|
move(portable_exe_path, os.path.join(self.dist_path, '..', portable_exe_name))
|
2016-12-09 09:52:33 +00:00
|
|
|
self._print('PortableApp build complete')
|
2016-12-03 11:23:23 +00:00
|
|
|
else:
|
|
|
|
raise Exception('PortableApp failed to build')
|
|
|
|
|
2016-12-05 18:23:50 +00:00
|
|
|
def get_platform(self):
|
2016-12-03 11:23:23 +00:00
|
|
|
"""
|
2016-12-05 18:23:50 +00:00
|
|
|
Return the platform we're building for
|
2016-12-03 11:23:23 +00:00
|
|
|
"""
|
2016-12-05 18:23:50 +00:00
|
|
|
return 'Windows'
|
|
|
|
|
|
|
|
def get_config_defaults(self):
|
|
|
|
"""
|
|
|
|
Build some default values for the config file
|
|
|
|
"""
|
|
|
|
config_defaults = super().get_config_defaults()
|
|
|
|
config_defaults.update({
|
|
|
|
'pyroot': self.python_root,
|
|
|
|
'progfiles': self.program_files,
|
2019-05-16 04:37:10 +00:00
|
|
|
'progfilesx86': self.program_files_x86,
|
2016-12-05 18:23:50 +00:00
|
|
|
'sitepackages': self.site_packages,
|
|
|
|
'projects': os.path.abspath(os.path.join(self.script_path, '..', '..'))
|
|
|
|
})
|
|
|
|
return config_defaults
|
|
|
|
|
|
|
|
def get_sphinx_build(self):
|
|
|
|
"""
|
|
|
|
Tell Sphinx we want to build HTML help
|
|
|
|
"""
|
|
|
|
return "htmlhelp"
|
|
|
|
|
2016-12-05 21:18:21 +00:00
|
|
|
def get_qt_translations_path(self):
|
|
|
|
"""
|
|
|
|
Return the path to Qt translation files on macOS
|
|
|
|
"""
|
2021-03-25 20:32:05 +00:00
|
|
|
return os.path.join(self.site_packages, 'PyQt5', 'Qt5', 'translations')
|
2016-12-05 21:18:21 +00:00
|
|
|
|
2016-12-05 18:23:50 +00:00
|
|
|
def add_extra_args(self, parser):
|
|
|
|
"""
|
|
|
|
Add extra arguments to the command line argument parser
|
|
|
|
"""
|
2016-12-07 21:49:54 +00:00
|
|
|
parser.add_argument('--portable', action='store_true', default=False,
|
2016-12-11 12:20:35 +00:00
|
|
|
help='Build a PortableApps.com build of OpenLP too')
|
2016-12-05 18:23:50 +00:00
|
|
|
|
|
|
|
def setup_system_paths(self):
|
|
|
|
"""
|
|
|
|
Set up some system paths.
|
|
|
|
"""
|
|
|
|
super().setup_system_paths()
|
|
|
|
self.python_root = os.path.dirname(self.python)
|
|
|
|
self.site_packages = os.path.join(self.python_root, 'Lib', 'site-packages')
|
2023-09-08 06:15:32 +00:00
|
|
|
self.program_files = os.environ['PROGRAMFILES']
|
2019-05-16 04:37:10 +00:00
|
|
|
self.program_files_x86 = os.getenv('PROGRAMFILES(x86)')
|
2019-02-16 21:01:03 +00:00
|
|
|
self._print_verbose(' {:.<20}: {}'.format('site packages: ', self.site_packages))
|
|
|
|
self._print_verbose(' {:.<20}: {}'.format('program files: ', self.program_files))
|
2019-05-16 04:37:10 +00:00
|
|
|
self._print_verbose(' {:.<20}: {}'.format('program files x86: ', self.program_files_x86))
|
2016-12-05 18:23:50 +00:00
|
|
|
|
|
|
|
def setup_paths(self):
|
|
|
|
"""
|
|
|
|
Set up a variety of paths that we use throughout the build process.
|
|
|
|
"""
|
|
|
|
super().setup_paths()
|
|
|
|
self.dist_path = os.path.join(self.work_path, 'dist', 'OpenLP')
|
|
|
|
self.helpfile_path = os.path.join(self.manual_build_path, 'htmlhelp')
|
|
|
|
self.winres_path = os.path.join(self.branch_path, 'resources', 'windows')
|
|
|
|
|
2019-03-08 21:20:20 +00:00
|
|
|
def setup_extra(self):
|
|
|
|
"""
|
|
|
|
Extra setup to run
|
|
|
|
"""
|
|
|
|
# Detect python instance bit size
|
|
|
|
self.arch = 'x86' if sys.maxsize == 0x7fffffff else 'x64'
|
2016-12-05 18:23:50 +00:00
|
|
|
|
|
|
|
def copy_extra_files(self):
|
|
|
|
"""
|
|
|
|
Copy all the Windows-specific files.
|
|
|
|
"""
|
|
|
|
self._print('Copying extra files for Windows...')
|
|
|
|
self._print_verbose('... OpenLP.ico')
|
2016-12-06 20:11:10 +00:00
|
|
|
copy(self.icon_path, os.path.join(self.dist_path, 'OpenLP.ico'))
|
2016-12-05 18:23:50 +00:00
|
|
|
self._print_verbose('... LICENSE.txt')
|
2016-12-06 21:02:14 +00:00
|
|
|
copy(self.license_path, os.path.join(self.dist_path, 'LICENSE.txt'))
|
2019-05-01 06:21:19 +00:00
|
|
|
self._print_verbose('... service_file.ico')
|
2019-05-02 20:40:11 +00:00
|
|
|
config_dir = os.path.dirname(self.config_path)
|
|
|
|
copy(os.path.join(config_dir, 'service_file.ico'), os.path.join(self.dist_path, 'service_file.ico'))
|
2016-12-05 18:23:50 +00:00
|
|
|
if os.path.isfile(os.path.join(self.helpfile_path, 'OpenLP.chm')):
|
|
|
|
self._print_verbose('... OpenLP.chm')
|
|
|
|
copy(os.path.join(self.helpfile_path, 'OpenLP.chm'), os.path.join(self.dist_path, 'OpenLP.chm'))
|
|
|
|
else:
|
|
|
|
self._print('... WARNING: Windows help file not found')
|
2019-05-15 22:39:12 +00:00
|
|
|
try:
|
|
|
|
# Check if PyMuPDF is installed
|
|
|
|
import fitz # noqa
|
|
|
|
HAS_PYMUPDF = True
|
|
|
|
except ImportError:
|
|
|
|
HAS_PYMUPDF = False
|
|
|
|
if not HAS_PYMUPDF:
|
|
|
|
self._print_verbose('... mutool.exe')
|
|
|
|
if self.mutool_exe and os.path.isfile(self.mutool_exe):
|
|
|
|
copy(os.path.join(self.mutool_exe), os.path.join(self.dist_path, 'mutool.exe'))
|
|
|
|
else:
|
|
|
|
self._print('... WARNING: mutool.exe not found')
|
|
|
|
vlc_path = os.path.join(self.program_files, 'VideoLAN', 'VLC')
|
2019-07-04 06:23:21 +00:00
|
|
|
vlc_dest = os.path.join(self.dist_path, 'vlc')
|
|
|
|
if not os.path.exists(vlc_dest):
|
|
|
|
os.makedirs(vlc_dest)
|
2019-04-11 22:25:20 +00:00
|
|
|
for fname in ['libvlc.dll', 'libvlccore.dll']:
|
|
|
|
self._print_verbose('... {}'.format(fname))
|
2019-07-04 06:23:21 +00:00
|
|
|
copy(os.path.join(vlc_path, fname), os.path.join(vlc_dest, fname))
|
|
|
|
if os.path.exists(os.path.join(vlc_dest, 'plugins')):
|
|
|
|
rmtree(os.path.join(vlc_dest, 'plugins'))
|
|
|
|
self._print_verbose('... copying VLC plugins')
|
2019-07-04 06:33:08 +00:00
|
|
|
copytree(os.path.join(vlc_path, 'plugins'), os.path.join(vlc_dest, 'plugins'))
|
2016-12-05 18:23:50 +00:00
|
|
|
|
|
|
|
def after_run_sphinx(self):
|
|
|
|
"""
|
|
|
|
Run HTML Help Workshop to convert the Sphinx output into a manual.
|
|
|
|
"""
|
|
|
|
self._print('Running HTML Help Workshop...')
|
|
|
|
os.chdir(os.path.join(self.manual_build_path, 'htmlhelp'))
|
2016-12-06 19:03:42 +00:00
|
|
|
self._run_command([self.htmlhelp_exe, 'OpenLP.chm'], 'Error running HTML Help Workshop', exit_code=1)
|
2016-12-05 18:23:50 +00:00
|
|
|
|
|
|
|
def build_package(self):
|
|
|
|
"""
|
|
|
|
Build the installer
|
|
|
|
"""
|
2019-04-09 04:14:43 +00:00
|
|
|
self._create_wix_file()
|
|
|
|
self._run_wix_tools()
|
2016-12-07 17:09:07 +00:00
|
|
|
if self.args.portable:
|
2016-12-05 18:23:50 +00:00
|
|
|
self._run_portableapp_builder()
|
2016-12-03 11:23:23 +00:00
|
|
|
|
2017-09-28 19:25:51 +00:00
|
|
|
def get_extra_parameters(self):
|
2017-09-26 21:58:42 +00:00
|
|
|
"""
|
2017-09-28 19:25:51 +00:00
|
|
|
Return a list of any extra parameters we wish to use
|
2017-09-26 21:58:42 +00:00
|
|
|
"""
|
2017-09-28 19:25:51 +00:00
|
|
|
parameters = []
|
2019-05-20 22:17:13 +00:00
|
|
|
dll_path = '{pf}\\Windows Kits\\10\\Redist\\ucrt\\DLLs\\{arch}\\*.dll'.format(pf=self.program_files_x86,
|
2019-03-08 21:20:20 +00:00
|
|
|
arch=self.arch)
|
2017-09-28 19:25:51 +00:00
|
|
|
# Finds the UCRT DDLs available from the Windows 10 SDK
|
2019-03-05 19:55:59 +00:00
|
|
|
for binary in glob.glob(dll_path):
|
2017-09-28 19:25:51 +00:00
|
|
|
parameters.append('--add-binary')
|
|
|
|
parameters.append(binary + ";.")
|
|
|
|
return parameters
|
2017-09-26 21:58:42 +00:00
|
|
|
|
2016-12-03 11:23:23 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
WindowsBuilder().main()
|