Add arch to dmg name, bundle applescript, parse pep440 version number

This commit is contained in:
Raoul Snyman 2023-09-14 11:39:44 -07:00
parent cdd1851f2d
commit 931faa3775
6 changed files with 58 additions and 20 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
__pycache__ __pycache__
*.pyc *.pyc
config.ini config.ini
*.spec

View File

@ -23,6 +23,7 @@
Base class for the Windows and macOS builders. Base class for the Windows and macOS builders.
""" """
import os import os
import re
import runpy import runpy
import sys import sys
from argparse import ArgumentParser from argparse import ArgumentParser
@ -39,6 +40,7 @@ BUILDER_DESCRIPTION = 'Build OpenLP for {platform}. Options are provided on both
'exported code for building. The two modes are invoked by the presence or absence of the --release ' \ 'exported code for building. The two modes are invoked by the presence or absence of the --release ' \
'option. If this option is omitted, a development build is built, while including the --release ' \ 'option. If this option is omitted, a development build is built, while including the --release ' \
'option with a version number will produce a build of that exact version.' 'option with a version number will produce a build of that exact version.'
PEP440 = re.compile(r'(?P<major>\d)\.(?P<minor>\d)(\.(?P<fix>\d))?((?P<pre>a|b|rc)(?P<rel>\d))?')
def _which(program): def _which(program):
@ -157,6 +159,16 @@ class Builder(object):
output, _ = self._run_command(['git', command] + args, err_msg) output, _ = self._run_command(['git', command] + args, err_msg)
return output return output
def parse_pep440_version(self, version: str) -> dict:
"""Parse a PEP440-compatible version number into a dictionary"""
if m := PEP440.match(version):
groups = m.groupdict()
if not groups.get('fix'):
groups['fix'] = '0'
return groups
else:
return None
def get_platform(self): def get_platform(self):
""" """
Return the platform we're building for Return the platform we're building for

View File

@ -92,6 +92,7 @@ like this:
import glob import glob
import os import os
import platform
from pathlib import Path from pathlib import Path
from shutil import copy, copytree, move, rmtree from shutil import copy, copytree, move, rmtree
@ -106,6 +107,13 @@ class MacOSXBuilder(Builder):
The :class:`MacosxBuilder` class encapsulates everything that is needed The :class:`MacosxBuilder` class encapsulates everything that is needed
to build a Mac OS X .dmg file. to build a Mac OS X .dmg file.
""" """
def _pep440_to_mac_version(self, version: str) -> str:
"""Convert a PEP440-compatible version to a Mac compatible version"""
if pep440 := self.parse_pep440_version(version):
return f'{pep440["major"]}.{pep440["minor"]}.{pep440["fix"]}'
else:
return '0.0.0'
def _get_directory_size(self, directory): def _get_directory_size(self, directory):
""" """
Return directory size - size of everything in the dir. Return directory size - size of everything in the dir.
@ -310,7 +318,7 @@ class MacOSXBuilder(Builder):
with open(os.path.join(self.dist_app_path, 'Contents', os.path.basename(self.bundle_info_path)), 'w') as fw, \ with open(os.path.join(self.dist_app_path, 'Contents', os.path.basename(self.bundle_info_path)), 'w') as fw, \
open(self.bundle_info_path, 'r') as fr: open(self.bundle_info_path, 'r') as fr:
text = fr.read() text = fr.read()
text = text % {'openlp_version': self.version} text = text % {'openlp_version': self._pep440_to_mac_version(self.version)}
fw.write(text) fw.write(text)
def _copy_macosx_files(self): def _copy_macosx_files(self):
@ -337,8 +345,9 @@ class MacOSXBuilder(Builder):
Create .dmg file. Create .dmg file.
""" """
self._print('Creating dmg file...') self._print('Creating dmg file...')
dmg_name = 'OpenLP-{version}.dmg'.format(version=self.version) arch = platform.machine()
dmg_title = 'OpenLP {version}'.format(version=self.version) dmg_name = f'OpenLP-{self.version}-{arch}.dmg'
dmg_title = f'OpenLP {self.version}'
self.dmg_file = os.path.join(self.work_path, 'dist', dmg_name) self.dmg_file = os.path.join(self.work_path, 'dist', dmg_name)
# Remove dmg if it exists. # Remove dmg if it exists.
@ -392,7 +401,7 @@ class MacOSXBuilder(Builder):
""" """
self._print('Copying extra files for macOS...') self._print('Copying extra files for macOS...')
# Exclude VLC for now, at least # Exclude VLC for now, at least
self._copy_vlc_files() # self._copy_vlc_files()
self._copy_bundle_files() self._copy_bundle_files()
self._copy_macosx_files() self._copy_macosx_files()
self._install_pyro5() self._install_pyro5()

View File

@ -97,7 +97,6 @@ Portable App Builds
import os import os
import glob import glob
import re
import sys import sys
from distutils import dir_util from distutils import dir_util
from hashlib import md5 from hashlib import md5
@ -110,9 +109,6 @@ from lxml.objectify import fromstring
from builder import Builder from builder import Builder
PEP440 = re.compile(r'(?P<major>\d)\.(?P<minor>\d)(\.(?P<fix>\d))?((?P<pre>a|b|rc)(?P<rel>\d))?')
class WindowsBuilder(Builder): class WindowsBuilder(Builder):
""" """
The :class:`WindowsBuilder` class encapsulates everything that is needed The :class:`WindowsBuilder` class encapsulates everything that is needed
@ -134,25 +130,22 @@ class WindowsBuilder(Builder):
def _pep440_to_windows_version(self, version: str) -> str: def _pep440_to_windows_version(self, version: str) -> str:
"""Convert a PEP440-compatible version string to a Windows version string""" """Convert a PEP440-compatible version string to a Windows version string"""
if m := PEP440.match(version): if pep440 := self.parse_pep440_version(version):
groups = m.groupdict()
if not groups.get('fix'):
groups['fix'] = '0'
build_number = 5000 build_number = 5000
if groups.get('pre'): if pep440.get('pre'):
if groups['pre'] == 'a': if pep440['pre'] == 'a':
build_number = 1000 build_number = 1000
elif groups['pre'] == 'b': elif pep440['pre'] == 'b':
build_number = 2000 build_number = 2000
elif groups['pre'] == 'rc': elif pep440['pre'] == 'rc':
build_number = 3000 build_number = 3000
if groups.get('rel'): if pep440.get('rel'):
try: try:
rel = int(groups['rel']) rel = int(pep440['rel'])
build_number += rel build_number += rel
except ValueError: except ValueError:
pass pass
return f'{groups["major"]}.{groups["minor"]}.{groups["fix"]}.{build_number}' return f'{pep440["major"]}.{pep440["minor"]}.{pep440["fix"]}.{build_number}'
else: else:
return '0.0.0.0' return '0.0.0.0'

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# 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; version 2 of the License. #
# #
# 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, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
hiddenimports = ['applescript']

View File

@ -20,4 +20,4 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
hiddenimports = ['Pyro4'] hiddenimports = ['Pyro5']