From 931faa3775822934f2ef0baee4b644c7b6a47ae5 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 14 Sep 2023 11:39:44 -0700 Subject: [PATCH] Add arch to dmg name, bundle applescript, parse pep440 version number --- .gitignore | 1 + builders/builder.py | 12 ++++++++++ builders/macosx-builder.py | 17 ++++++++++---- builders/windows-builder.py | 23 +++++++------------ ...ins.presentations.lib.keynotecontroller.py | 23 +++++++++++++++++++ ...ugins.presentations.lib.maclocontroller.py | 2 +- 6 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 pyinstaller-hooks/hook-openlp.plugins.presentations.lib.keynotecontroller.py diff --git a/.gitignore b/.gitignore index a8319c3..9b25458 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ *.pyc config.ini +*.spec diff --git a/builders/builder.py b/builders/builder.py index f3b0b25..862d5bd 100644 --- a/builders/builder.py +++ b/builders/builder.py @@ -23,6 +23,7 @@ Base class for the Windows and macOS builders. """ import os +import re import runpy import sys 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 ' \ '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.' +PEP440 = re.compile(r'(?P\d)\.(?P\d)(\.(?P\d))?((?P
a|b|rc)(?P\d))?')
 
 
 def _which(program):
@@ -157,6 +159,16 @@ class Builder(object):
         output, _ = self._run_command(['git', command] + args, err_msg)
         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):
         """
         Return the platform we're building for
diff --git a/builders/macosx-builder.py b/builders/macosx-builder.py
index 6ad8812..a38b613 100644
--- a/builders/macosx-builder.py
+++ b/builders/macosx-builder.py
@@ -92,6 +92,7 @@ like this:
 
 import glob
 import os
+import platform
 from pathlib import Path
 from shutil import copy, copytree, move, rmtree
 
@@ -106,6 +107,13 @@ class MacOSXBuilder(Builder):
     The :class:`MacosxBuilder` class encapsulates everything that is needed
     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):
         """
         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, \
                 open(self.bundle_info_path, 'r') as fr:
             text = fr.read()
-            text = text % {'openlp_version': self.version}
+            text = text % {'openlp_version': self._pep440_to_mac_version(self.version)}
             fw.write(text)
 
     def _copy_macosx_files(self):
@@ -337,8 +345,9 @@ class MacOSXBuilder(Builder):
         Create .dmg file.
         """
         self._print('Creating dmg file...')
-        dmg_name = 'OpenLP-{version}.dmg'.format(version=self.version)
-        dmg_title = 'OpenLP {version}'.format(version=self.version)
+        arch = platform.machine()
+        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)
         # Remove dmg if it exists.
@@ -392,7 +401,7 @@ class MacOSXBuilder(Builder):
         """
         self._print('Copying extra files for macOS...')
         # Exclude VLC for now, at least
-        self._copy_vlc_files()
+        # self._copy_vlc_files()
         self._copy_bundle_files()
         self._copy_macosx_files()
         self._install_pyro5()
diff --git a/builders/windows-builder.py b/builders/windows-builder.py
index eb4a108..6e91668 100644
--- a/builders/windows-builder.py
+++ b/builders/windows-builder.py
@@ -97,7 +97,6 @@ Portable App Builds
 
 import os
 import glob
-import re
 import sys
 from distutils import dir_util
 from hashlib import md5
@@ -110,9 +109,6 @@ from lxml.objectify import fromstring
 from builder import Builder
 
 
-PEP440 = re.compile(r'(?P\d)\.(?P\d)(\.(?P\d))?((?P
a|b|rc)(?P\d))?')
-
-
 class WindowsBuilder(Builder):
     """
     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:
         """Convert a PEP440-compatible version string to a Windows version string"""
-        if m := PEP440.match(version):
-            groups = m.groupdict()
-            if not groups.get('fix'):
-                groups['fix'] = '0'
+        if pep440 := self.parse_pep440_version(version):
             build_number = 5000
-            if groups.get('pre'):
-                if groups['pre'] == 'a':
+            if pep440.get('pre'):
+                if pep440['pre'] == 'a':
                     build_number = 1000
-                elif groups['pre'] == 'b':
+                elif pep440['pre'] == 'b':
                     build_number = 2000
-                elif groups['pre'] == 'rc':
+                elif pep440['pre'] == 'rc':
                     build_number = 3000
-            if groups.get('rel'):
+            if pep440.get('rel'):
                 try:
-                    rel = int(groups['rel'])
+                    rel = int(pep440['rel'])
                     build_number += rel
                 except ValueError:
                     pass
-            return f'{groups["major"]}.{groups["minor"]}.{groups["fix"]}.{build_number}'
+            return f'{pep440["major"]}.{pep440["minor"]}.{pep440["fix"]}.{build_number}'
         else:
             return '0.0.0.0'
 
diff --git a/pyinstaller-hooks/hook-openlp.plugins.presentations.lib.keynotecontroller.py b/pyinstaller-hooks/hook-openlp.plugins.presentations.lib.keynotecontroller.py
new file mode 100644
index 0000000..27371f0
--- /dev/null
+++ b/pyinstaller-hooks/hook-openlp.plugins.presentations.lib.keynotecontroller.py
@@ -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']
diff --git a/pyinstaller-hooks/hook-openlp.plugins.presentations.lib.maclocontroller.py b/pyinstaller-hooks/hook-openlp.plugins.presentations.lib.maclocontroller.py
index f0e75ee..743dd9e 100644
--- a/pyinstaller-hooks/hook-openlp.plugins.presentations.lib.maclocontroller.py
+++ b/pyinstaller-hooks/hook-openlp.plugins.presentations.lib.maclocontroller.py
@@ -20,4 +20,4 @@
 # Temple Place, Suite 330, Boston, MA 02111-1307 USA                          #
 ###############################################################################
 
-hiddenimports = ['Pyro4']
+hiddenimports = ['Pyro5']