Skip to content

Commit 95167ae

Browse files
committed
moved powershell tilde expansion handling so it happens sooner
1 parent 76ed7de commit 95167ae

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

confluence_markdown_exporter/confluence.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ def from_json(cls, data: JsonResponse) -> "Space":
180180
@classmethod
181181
@functools.lru_cache(maxsize=100)
182182
def from_key(cls, space_key: str) -> "Space":
183-
# Personal Confluence spaces start with ~. Exporting them on Windows leads to
184-
# Powershell expanding tilde to the Users directory, which is handled here
185-
space_key = re.sub(r"^[A-Z]:\\Users\\", "~", space_key, count=1, flags=re.IGNORECASE)
186-
187183
return cls.from_json(
188184
cast("JsonResponse", confluence.get_space(space_key, expand="homepage"))
189185
)

confluence_markdown_exporter/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
from pathlib import Path
34
from typing import Annotated
45

@@ -72,13 +73,14 @@ def spaces(
7273
) -> None:
7374
from confluence_markdown_exporter.confluence import Space
7475

75-
with measure(f"Export spaces {', '.join(space_keys)}"):
76-
for space_key in space_keys:
76+
normalized_space_keys = [_normalize_space_key(key) for key in space_keys]
77+
78+
with measure(f"Export spaces {', '.join(normalized_space_keys)}"):
79+
for space_key in normalized_space_keys:
7780
override_output_path_config(output_path)
7881
space = Space.from_key(space_key)
7982
space.export()
8083

81-
8284
@app.command(help="Export all Confluence pages across all spaces to Markdown.")
8385
def all_spaces(
8486
output_path: Annotated[
@@ -125,6 +127,10 @@ def version() -> None:
125127
"""Display the current version."""
126128
typer.echo(f"confluence-markdown-exporter {__version__}")
127129

130+
def _normalize_space_key(space_key: str) -> str:
131+
# Personal Confluence spaces start with ~. Exporting them on Windows leads to
132+
# Powershell expanding tilde to the Users directory, which is handled here
133+
return re.sub(r"^[A-Z]:\\Users\\", "~", space_key, count=1, flags=re.IGNORECASE)
128134

129135
if __name__ == "__main__":
130136
app()

0 commit comments

Comments
 (0)