Debian Codegraph @

src/briefcase/integrations/rcedit.py

raw
1 from __future__ import annotations
2
3 from collections.abc import Collection
4 from pathlib import Path
5
6 from briefcase.exceptions import MissingToolError
7 from briefcase.integrations.base import ManagedTool, ToolCache
8
9
10 class RCEdit(ManagedTool):
11 name = "rcedit"
12 full_name = "RCEdit"
13 supported_host_os: Collection[str] = {"Windows"}
14
15 @property
16 def download_url(self) -> str:
17 return (
18 "https://github.com/electron/rcedit/releases/download/v2.0.0/rcedit-x64.exe"
19 )
20
21 @property
22 def rcedit_path(self) -> Path:
23 return self.tools.base_path / "rcedit-x64.exe"
24
25 @classmethod
26 def verify_install(cls, tools: ToolCache, install: bool = True, **kwargs) -> RCEdit:
27 """Verify that rcedit is available.
28
29 :param tools: ToolCache of available tools
30 :param install: Should the tool be installed if it is not found?
31 :returns: A valid rcedit tool wrapper. If rcedit is not available, and was not
32 installed, raises MissingToolError.
33 """
34 # short circuit since already verified and available
35 if hasattr(tools, "rcedit"):
36 return tools.rcedit
37
38 rcedit = RCEdit(tools=tools)
39
40 if not rcedit.exists():
41 if install:
42 tools.console.info(
43 "RCEdit was not found; downloading and installing...",
44 prefix=cls.name,
45 )
46 rcedit.install()
47 else:
48 raise MissingToolError("RCEdit")
49
50 tools.rcedit = rcedit
51 return rcedit
52
53 def exists(self) -> bool:
54 return self.rcedit_path.exists()
55
56 def install(self):
57 """Download and install RCEdit."""
58 self.tools.file.download(
59 url=self.download_url,
60 download_path=self.tools.base_path,
61 role="RCEdit",
62 )
63
64 def uninstall(self):
65 """Uninstall RCEdit."""
66 with self.tools.console.wait_bar("Removing old RCEdit install..."):
67 self.rcedit_path.unlink()