|
| 1 | +import subprocess |
| 2 | + |
| 3 | +from briefcase.commands import ( |
| 4 | + BuildCommand, |
| 5 | + CreateCommand, |
| 6 | + PackageCommand, |
| 7 | + PublishCommand, |
| 8 | + RunCommand, |
| 9 | + UpdateCommand |
| 10 | +) |
| 11 | +from briefcase.config import BaseConfig |
| 12 | +from briefcase.exceptions import BriefcaseCommandError |
| 13 | +from briefcase.platforms.macOS import macOSMixin, macOSPackageMixin |
| 14 | + |
| 15 | + |
| 16 | +class macOSAppMixin(macOSMixin): |
| 17 | + output_format = 'app' |
| 18 | + |
| 19 | + def binary_path(self, app): |
| 20 | + return self.bundle_path(app) / '{app.formal_name}.app'.format(app=app) |
| 21 | + |
| 22 | + def distribution_path(self, app): |
| 23 | + return self.binary_path(app) |
| 24 | + |
| 25 | + |
| 26 | +class macOSAppCreateCommand(macOSAppMixin, CreateCommand): |
| 27 | + description = "Create and populate a macOS app." |
| 28 | + |
| 29 | + |
| 30 | +class macOSAppUpdateCommand(macOSAppMixin, UpdateCommand): |
| 31 | + description = "Update an existing macOS app." |
| 32 | + |
| 33 | + |
| 34 | +class macOSAppBuildCommand(macOSAppMixin, BuildCommand): |
| 35 | + description = "Build a macOS app." |
| 36 | + |
| 37 | + |
| 38 | +class macOSAppRunCommand(macOSAppMixin, RunCommand): |
| 39 | + description = "Run a macOS app." |
| 40 | + |
| 41 | + def run_app(self, app: BaseConfig, **kwargs): |
| 42 | + """ |
| 43 | + Start the application. |
| 44 | +
|
| 45 | + :param app: The config object for the app |
| 46 | + :param base_path: The path to the project directory. |
| 47 | + """ |
| 48 | + print() |
| 49 | + print('[{app.app_name}] Starting app...'.format( |
| 50 | + app=app |
| 51 | + )) |
| 52 | + try: |
| 53 | + print() |
| 54 | + self.subprocess.run( |
| 55 | + [ |
| 56 | + 'open', |
| 57 | + self.binary_path(app), |
| 58 | + ], |
| 59 | + check=True, |
| 60 | + ) |
| 61 | + except subprocess.CalledProcessError: |
| 62 | + print() |
| 63 | + raise BriefcaseCommandError( |
| 64 | + "Unable to start app {app.app_name}.".format(app=app) |
| 65 | + ) |
| 66 | + |
| 67 | + |
| 68 | +class macOSAppPackageCommand(macOSAppMixin, macOSPackageMixin, PackageCommand): |
| 69 | + description = "Package a macOS app for distribution." |
| 70 | + |
| 71 | + |
| 72 | +class macOSAppPublishCommand(macOSAppMixin, PublishCommand): |
| 73 | + description = "Publish a macOS app." |
| 74 | + |
| 75 | + |
| 76 | +# Declare the briefcase command bindings |
| 77 | +create = macOSAppCreateCommand # noqa |
| 78 | +update = macOSAppUpdateCommand # noqa |
| 79 | +build = macOSAppBuildCommand # noqa |
| 80 | +run = macOSAppRunCommand # noqa |
| 81 | +package = macOSAppPackageCommand # noqa |
| 82 | +publish = macOSAppPublishCommand # noqa |
0 commit comments