| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import argparse |
| 4 |
|
| 5 |
from briefcase.config import AppConfig |
| 6 |
from briefcase.exceptions import BriefcaseCommandError |
| 7 |
|
| 8 |
from .base import full_options |
| 9 |
from .create import CreateCommand |
| 10 |
|
| 11 |
|
| 12 |
class UpdateCommand(CreateCommand): |
| 13 |
command = "update" |
| 14 |
description = "Update the source, dependencies, and resources for an app." |
| 15 |
|
| 16 |
def add_options(self, parser): |
| 17 |
self._add_update_options(parser, update=False) |
| 18 |
self._add_test_options(parser, context_label="Update") |
| 19 |
|
| 20 |
if self.supports_debugger: |
| 21 |
self._add_debug_options(parser, context_label="Update") |
| 22 |
|
| 23 |
parser.add_argument( |
| 24 |
"-a", |
| 25 |
"--app", |
| 26 |
dest="app_name", |
| 27 |
help="Name of the app to update (if multiple apps exist in the project)", |
| 28 |
default=argparse.SUPPRESS, |
| 29 |
) |
| 30 |
|
| 31 |
def update_app( |
| 32 |
self, |
| 33 |
app: AppConfig, |
| 34 |
update_requirements: bool, |
| 35 |
update_resources: bool, |
| 36 |
update_support: bool, |
| 37 |
update_stub: bool, |
| 38 |
**options, |
| 39 |
) -> dict | None: |
| 40 |
"""Update an existing application bundle. |
| 41 |
|
| 42 |
:param app: The config object for the app |
| 43 |
:param update_requirements: Should requirements be updated? |
| 44 |
:param update_resources: Should extra resources be updated? |
| 45 |
:param update_support: Should app support be updated? |
| 46 |
:param update_stub: Should stub binary be updated? |
| 47 |
""" |
| 48 |
|
| 49 |
if app.external_package_path: |
| 50 |
raise BriefcaseCommandError( |
| 51 |
f"{app.app_name!r} is declared as an external app. External apps " |
| 52 |
"(apps defining 'external_package_path') cannot be updated." |
| 53 |
) |
| 54 |
|
| 55 |
if not self.bundle_path(app).exists(): |
| 56 |
self.console.error( |
| 57 |
"Application does not exist; call create first!", prefix=app.app_name |
| 58 |
) |
| 59 |
return |
| 60 |
|
| 61 |
self.verify_app(app) |
| 62 |
|
| 63 |
self.console.info("Updating application code...", prefix=app.app_name) |
| 64 |
self.install_app_code(app=app) |
| 65 |
|
| 66 |
if update_requirements: |
| 67 |
self.console.info("Updating requirements...", prefix=app.app_name) |
| 68 |
self.install_app_requirements(app=app) |
| 69 |
|
| 70 |
if update_resources: |
| 71 |
self.console.info("Updating application resources...", prefix=app.app_name) |
| 72 |
self.install_app_resources(app=app) |
| 73 |
|
| 74 |
if update_support: |
| 75 |
self.console.info("Updating application support...", prefix=app.app_name) |
| 76 |
self.cleanup_app_support_package(app=app) |
| 77 |
self.install_app_support_package(app=app) |
| 78 |
|
| 79 |
if update_stub: |
| 80 |
try: |
| 81 |
# If the platform uses a stub binary, the template will define a binary |
| 82 |
# revision. If this template configuration item doesn't exist, there's |
| 83 |
# no stub binary |
| 84 |
self.stub_binary_revision(app) |
| 85 |
except KeyError: |
| 86 |
pass |
| 87 |
else: |
| 88 |
self.console.info("Updating stub binary...", prefix=app.app_name) |
| 89 |
self.cleanup_stub_binary(app=app) |
| 90 |
self.install_stub_binary(app=app) |
| 91 |
|
| 92 |
self.console.info("Removing unneeded app content...", prefix=app.app_name) |
| 93 |
self.cleanup_app_content(app=app) |
| 94 |
|
| 95 |
self.console.info("Application updated.", prefix=app.app_name) |
| 96 |
|
| 97 |
def __call__( |
| 98 |
self, |
| 99 |
app: AppConfig | None = None, |
| 100 |
app_name: str | None = None, |
| 101 |
update_requirements: bool = False, |
| 102 |
update_resources: bool = False, |
| 103 |
update_support: bool = False, |
| 104 |
update_stub: bool = False, |
| 105 |
test_mode: bool = False, |
| 106 |
debugger: str | None = None, |
| 107 |
**options, |
| 108 |
) -> dict | None: |
| 109 |
apps_to_update = self.resolve_apps(app=app, app_name=app_name) |
| 110 |
|
| 111 |
# Confirm host compatibility, that all required tools are available, |
| 112 |
# and that the app configuration is finalized. |
| 113 |
self.finalize( |
| 114 |
apps=apps_to_update.values(), |
| 115 |
test_mode=test_mode, |
| 116 |
debugger=debugger, |
| 117 |
) |
| 118 |
|
| 119 |
state = None |
| 120 |
for _, app_obj in sorted(apps_to_update.items()): |
| 121 |
state = self.update_app( |
| 122 |
app_obj, |
| 123 |
update_requirements=update_requirements, |
| 124 |
update_resources=update_resources, |
| 125 |
update_support=update_support, |
| 126 |
update_stub=update_stub, |
| 127 |
**full_options(state, options), |
| 128 |
) |
| 129 |
|
| 130 |
return state |