Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add directory support to flash save #19

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/ttblit/tool/flasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, subparser):

self.op_save = operations.add_parser('save', help='Save a game/file to your 32Blit')
self.op_save.add_argument('--file', type=pathlib.Path, required=True, help='File to save')
self.op_save.add_argument('--directory', type=str, default='/', help='Target directory')

self.op_flash = operations.add_parser('flash', help='Flash a game to your 32Blit')
self.op_flash.add_argument('--file', type=pathlib.Path, required=True, help='File to flash')
Expand Down Expand Up @@ -71,15 +72,19 @@ def _decorated(self, args):
sp.close()
return _decorated

def _send_file(self, serial, file, dest):
def _send_file(self, serial, file, dest, directory=None):
sent_byte_count = 0
chunk_size = 64
file_name = file.name
file_size = file.stat().st_size

if dest == 'sd':
print(f'Saving {file} ({file_size} bytes) as {file_name}')
command = f'32BLSAVE{file_name}\x00{file_size}\x00'
if directory is None:
directory = '/'
else:
directory = f'{directory}/'
print(f'Saving {file} ({file_size} bytes) as {file_name} in {directory}')
command = f'32BLSAVE{directory}{file_name}\x00{file_size}\x00'
elif dest == 'flash':
print(f'Flashing {file} ({file_size} bytes)')
command = f'32BLPROG{file_name}\x00{file_size}\x00'
Expand All @@ -98,7 +103,7 @@ def _send_file(self, serial, file, dest):

@serial_command
def run_save(self, serial, args):
self._send_file(serial, args.get('file'), 'sd')
self._send_file(serial, args.get('file'), 'sd', directory=args.get('directory', 'games'))

@serial_command
def run_flash(self, serial, args):
Expand Down