Skip to content

Commit cf70dd7

Browse files
committed
repl_installer: get script from resources
1 parent b51f3e7 commit cf70dd7

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

pybricksdev/repl_installer.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
from asyncio import run, sleep
66
from zipfile import ZipFile
77
from hashlib import sha256
8+
from importlib.resources import path
89

9-
from pybricksdev.connections import CharacterGlue, USBConnection
10-
from pybricksdev.flash import crc32_checksum
10+
from . import resources
11+
12+
from .connections import CharacterGlue, USBConnection
13+
from .flash import crc32_checksum
1114

1215

1316
class USBREPLConnection(CharacterGlue, USBConnection):
@@ -128,10 +131,11 @@ async def install(self, firmware_archive_path):
128131
await self.upload_file('_pybricks/__init__.py', b'# Intentionally left blank.')
129132

130133
# Upload installation script.
131-
with open('pybricksdev/resources/install_pybricks.py', "rb") as install_script:
132-
install_blob = install_script.read()
133-
install_hash = sha256(install_blob).hexdigest().encode('utf-8')
134-
await self.upload_file('_pybricks/install.py', install_blob)
134+
with path(resources, resources.INSTALL_PYBRICKS) as install_path:
135+
with open(install_path, "rb") as install_script:
136+
install_blob = install_script.read()
137+
install_hash = sha256(install_blob).hexdigest().encode('utf-8')
138+
await self.upload_file('_pybricks/install.py', install_blob)
135139

136140
# Upload file with hashes to verify uploaded file integrity.
137141
await self.upload_file('_pybricks/hash.txt', pybricks_hash + b"\n" + install_hash + b"\n")

pybricksdev/resources/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
DFU_UTIL_EXE = "dfu-util.exe"
1414
"""Windows version of dfu-util executable."""
15+
16+
INSTALL_PYBRICKS = "install_pybricks.py"
17+
"""Dual boot installation script to run on official SPIKE Prime firmware."""

0 commit comments

Comments
 (0)