g-raffy / pymusco

a python application to manage digitised orchestral musical scores
GNU General Public License v3.0
3 stars 1 forks source link

error Object 203 0 not defined when using stub_to_print #8

Open g-raffy opened 1 month ago

g-raffy commented 1 month ago
Object 203 0 not defined.
Traceback (most recent call last):
  File "./mno.py", line 3907, in <module>
    prints_for_20240612()
  File "./mno.py", line 3904, in prints_for_20240612
    piece.build_print(track_selector, prints_dir=output_dir)
  File "/home/graffy/private/dev/pymusco/src/pymusco/piece.py", line 232, in build_print
    stub_to_print(
  File "/home/graffy/private/dev/pymusco/src/pymusco/main.py", line 429, in stub_to_print
    toto_pdf.add_page(track_page)
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/_writer.py", line 321, in add_page
    return self._add_page(page, list.append, excluded_keys)
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/_writer.py", line 271, in _add_page
    page = cast("PageObject", page_org.clone(self, False, excluded_keys))
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/generic/_data_structures.py", line 181, in clone
    d__._clone(self, pdf_dest, force_duplicate, ignore_fields)
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/generic/_data_structures.py", line 243, in _clone
    v.clone(pdf_dest, force_duplicate, ignore_fields)
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/generic/_base.py", line 248, in clone
    assert obj is not None
AssertionError
g-raffy commented 1 month ago

Here's what I found until now:

g-raffy commented 1 month ago

Here's a test function that exhibits the bug:

def bug_shower_1(trigger_bug: bool):
    src_pdf_file_path = Path('/home/graffy/private/melting-notes/partitions/scans/888-bug.pdf')

    tmp_dir = Path('/home/graffy/private/dev/pymusco/tickets/ticket0008/tmp')

    scanned_image_file_paths = []
    with open(src_pdf_file_path, 'rb') as src_pdf_file:
        pdf_reader = PyPDF2.PdfReader(src_pdf_file)
        page_index = 0
        for page in pdf_reader.pages:
            print(f'============= page_index = {page_index}')
            # image_file_path = extract_pdf_page_main_image(page, image_dir=tmp_dir, image_name=('page%03d' % page_index))
            image_file_path = extract_pdf_page(page, image_dir=tmp_dir, image_name=f'page{page_index:03d}')
            print(image_file_path)
            # check_pdf_file(image_file_path)

            scanned_image_file_paths.append(image_file_path)
            page_index += 1

    # stamp_descs = stamp_descs if stamp_descs is not None else []

    orchestra = load_orchestra('/home/graffy/private/dev/pymusco/samples/harmony.orchestra')

    piece = load_piece_description(Path('/home/graffy/private/melting-notes/partitions/scans/888-bug.desc'), orchestra)

    dst_stub_pdf_file_path = Path('/home/graffy/private/dev/pymusco/tickets/ticket0008/stub.pdf')
    toc = piece.scan_toc

    if trigger_bug:
        stamp_descs = piece.stamp_descs
    else:
        stamp_descs = []

    images_to_pdf(StubContents(image_file_paths=scanned_image_file_paths, toc=toc, title='toto', stamp_descs=stamp_descs, page_info_line_y_pos=1.0), dst_stub_pdf_file_path)

    # check_pdf_file(dst_stub_pdf_file_path)

    dst_stub_copy_pdf_file_path = Path('/home/graffy/private/dev/pymusco/tickets/ticket0008/stub-copy.pdf')
    duplicate_pdf_file_001(dst_stub_pdf_file_path, dst_stub_copy_pdf_file_path)
    # check_pdf_file(dst_pdf_file_path)