3 Commits

Author SHA1 Message Date
6645c4443b playlistdb: micropython does not have bytes.removeprefix()
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m22s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 10s
2025-09-06 21:50:55 +02:00
bb18717ec2 app: Fix bug when a tag that has no playlist is encountered 2025-09-06 21:50:55 +02:00
3ea30116e6 playlistdb: Allow up to 100k tracks; Add validate method; docstrings
- Increase the formatting of playlist entries to allow up to 100000
  tracks. Also enforce that playlist entries are indexed by integers
  using the validate method.

- Add a validate method to validate the data stored in the
  btreedb. Optionally dump the contents to stdout. For testing, add a
  validate+dump by default when opening the db. This can be removed once
  the playlistdb is validated.
2025-09-06 21:50:55 +02:00

View File

@@ -65,7 +65,7 @@ class BTreeDB(IPlaylistDB):
@staticmethod
def _keyPlaylistEntry(tag, pos):
return b''.join([tag, b'/playlist/', "{:05}".format(pos).encode()])
return b''.join([tag, b'/playlist/', '{:05}'.format(pos).encode()])
@staticmethod
def _keyPlaylistStart(tag):
@@ -159,6 +159,7 @@ class BTreeDB(IPlaylistDB):
result = True
last_tag = None
last_pos = None
index_width = None
for k in self.db.keys():
fields = k.split(b'/')
if len(fields) <= 1:
@@ -180,11 +181,15 @@ class BTreeDB(IPlaylistDB):
print(f'Malformed playlist entry: {k!r}')
result = False
continue
if index_width is not None and len(fields[2]) != index_width:
print(f'Inconsistent index width for {last_tag} at {idx}')
result = False
if (last_pos is not None and last_pos + 1 != idx) or \
(last_pos is None and idx != 0):
print(f'Bad playlist entry sequence for {last_tag} at {idx}')
result = False
last_pos = idx
index_width = len(fields[2])
if dump:
print(f'\tTrack {idx}: {self.db[k]!r}')
elif fields[1] == b'playlistpos':