iamjackg / md2cf

Convert and upload Markdown documents to Confluence
MIT License
93 stars 52 forks source link

KeyError: PosixPath('.') when uploading files #19

Closed raymondve closed 2 years ago

raymondve commented 2 years ago

I get the following error when I try to upload to confluence:

$ md2cf --dry-run  --space xxx --password ${CONFLUENCE_PASSWORD} --username ${CONFLUENCE_USERNAME} --host ${CONFLUENCE_HOST} dist
Traceback (most recent call last):
  File "/home/xxx/.pyenv/versions/3.9.9/bin/md2cf", line 8, in <module>
    sys.exit(main())
  File "/home/xxx/.pyenv/versions/3.9.9/lib/python3.9/site-packages/md2cf/__main__.py", line 235, in main
    pages_to_upload += md2cf.document.get_pages_from_directory(
  File "/home/xxx/.pyenv/versions/3.9.9/lib/python3.9/site-packages/md2cf/document.py", line 85, in get_pages_from_directory
    folder_parent_title = folder_data[folder_parent_path]["title"]
KeyError: PosixPath('.')

adding "try-except" on line 85-116 will have me continue with this but is most likely not the solution.


            try:
                folder_parent_title = folder_data[folder_parent_path]["title"]

                if len(markdown_files) == 1 and collapse_single_pages:
                    parent_page_title = folder_parent_title
                else:
                    if collapse_empty:
                        folder_data[current_path]["title"] = current_path.relative_to(
                            folder_parent_path
                        )
                    if beautify_folders:
                        folder_data[current_path]["title"] = (
                            folder_data[current_path]["title"]
                            .replace("-", " ")
                            .replace("_", " ")
                            .capitalize()
                        )
                    elif use_pages_file and ".pages" in file_names:
                        with open(current_path.joinpath(".pages")) as pages_fp:
                            pages_file_contents = yaml.safe_load(pages_fp)
                        if "title" in pages_file_contents:
                            folder_data[current_path]["title"] = pages_file_contents[
                                "title"
                            ]
                    parent_page_title = folder_data[current_path]["title"]
                    processed_pages.append(
                        Page(
                            title=parent_page_title,
                            parent_title=folder_parent_title,
                            body="",
                        )
                    )
            except KeyError:
                print(f"invalld path, current_path: {current_path}")
                print(f"invalld path, type(current_path): {type(current_path)}")
                pass

output is:

invalld path, current_path: dist
invalld path, type(current_path): <class 'pathlib.PosixPath'>
iamjackg commented 2 years ago

Ah, I can't believe I missed this case... There's a bug with folder uploads that currently only makes it work with absolute paths. I'll try to fix that, in the meantime you should be able to work around it by passing the full absolute path for dist.

iamjackg commented 2 years ago

This should now be fixed in v1.1.1. Please let me know if it works for you!

raymondve commented 2 years ago

Thanks! It works now, that was quick!! Thanks a lot!