From: Plom Heller Date: Thu, 7 May 2026 12:26:34 +0000 (+0200) Subject: Use former .print_packing_instructions for Collection.show. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/ledger?a=commitdiff_plain;h=HEAD;p=bricksplom Use former .print_packing_instructions for Collection.show. --- diff --git a/bricksplom.py b/bricksplom.py index 2239992..aa71449 100755 --- a/bricksplom.py +++ b/bricksplom.py @@ -185,7 +185,7 @@ class Design(Textfiled, Lookupable): alts: dict[str, set[str]] = {} for design_id, body in [cls.tokify(line, 2) for line in cls.lines_of(path)]: - assert design_id not in collected + assert design_id not in collected, design_id assert len(body) > 1 char_type, body = body[0], body[1:] assert char_type in {CHAR_DESIGN_ALT, CHAR_DESIGN_DESC} @@ -334,11 +334,6 @@ class Collection(Textfiled, WithDb, Lookupable): + self._format_paginated(lambda count, p_id, comment: f' {count:2} {p_id:>7} {comment}')) - def show( - self - ) -> str: - return self.raw() - def __str__( self ) -> str: @@ -347,7 +342,7 @@ class Collection(Textfiled, WithDb, Lookupable): def searchable( self ) -> str: - return self.raw() + return self.show() def _format_paginated( self, @@ -362,7 +357,7 @@ class Collection(Textfiled, WithDb, Lookupable): lines += [' -'] for count, piece_id, comment in column: lines += [format_line(count, piece_id, comment)] - return '\n'.join(lines) + '\n' + return '\n'.join(lines) def piece_listings_flat(self) -> tuple[PieceListing, ...]: 'Flattened variant of .piece_listings, no division into pages/cols.' @@ -372,30 +367,42 @@ class Collection(Textfiled, WithDb, Lookupable): collected += list(column) return tuple(collected) - def print_packing_instructions( + def show( self - ) -> None: - 'Print helper for putting into boxes all pieces of self.' - def format_line(_, piece_id, __) -> str: + ) -> str: + def format_line(count, piece_id, comment) -> str: assert self._db - box_listing, description = self._db.piece_to_box_listing(piece_id) - return f'{piece_id:>7} {box_listing} {description}' - - print(self._format_paginated(format_line)) - - def print_unpacking_instructions( - self - ) -> None: - 'Print helper for collecting from boxes all pieces of self.' - assert self._db - lines = [] - for count, piece_id, _ in self.piece_listings_flat(): - box_listing, description = self._db.piece_to_box_listing(piece_id) + piece = self._db.pieces[piece_id] + design_id = piece.design_id + tail_comment = f' # {comment}' if comment else '' color = str(self._db.colors[self._db.pieces[piece_id].color_id] ).lstrip().split(CHAR_SEP_TOKEN, maxsplit=1)[1] - lines += [f'{box_listing} {count}× {color} {description}'] - for line in sorted(lines): - print(line) + box: Optional[Box] = None + for i_box in self._db.boxes().values(): + for idx_in_box in [ + idx for idx, d_to_ls + in enumerate(i_box.designs_to_listings) + if piece_id in [listing[1] for listing in d_to_ls[1]]]: + box = i_box + break + if box: + break + if not box: + for i_box in self._db.boxes().values(): + for idx_in_box in [ + idx for idx, t + in enumerate(i_box.designs_to_listings) + if design_id in t[0].all_ids]: + box = i_box + break + if box: + break + box_listing = f'{box.id_:>2}:{idx_in_box:>2}' if box else '__:__' + return (f'{count:>2}× {piece_id:>7}:{design_id:>6} {box_listing} ' + f'{color} {self._db.designs[design_id].description}' + f'{tail_comment}') + + return f'{self}\n\n{self._format_paginated(format_line)}' class Box(WithDb, Lookupable): @@ -417,7 +424,8 @@ class Box(WithDb, Lookupable): design = design.alternate_to or design if not (designed_listings and designed_listings[-1][0] == design): designed_listings += [(design, []), ] - designed_listings[-1][1] += [listing] + target = designed_listings[-1][1] + target += [listing] self.designs_to_listings = tuple((d, tuple(ls)) for d, ls in designed_listings) @@ -536,33 +544,6 @@ class BricksDb: item = table[inquiry] return item.raw() if show_raw else item.show() - def piece_to_box_listing( - self, - piece_id: str, - ) -> tuple[str, str]: - 'For Piece of piece_id, print position in .boxes() and description.' - design = self.designs[self.pieces[piece_id].design_id] - owning_box: Optional[Box] = None - for box in self.boxes().values(): - for idx_in_box in [ - idx for idx, d_to_ls in enumerate(box.designs_to_listings) - if piece_id in [listing[1] for listing in d_to_ls[1]]]: - owning_box = box - break - if owning_box: - break - if not owning_box: - for box in self.boxes().values(): - for idx_in_box in [ - idx for idx, t in enumerate(box.designs_to_listings) - if design.id_ in t[0].all_ids]: - owning_box = box - break - if owning_box: - break - assert owning_box - return f'{box.id_:>2}:{idx_in_box:>2}', design.description - def print( self ) -> None: