-
-
Notifications
You must be signed in to change notification settings - Fork 77
feat: incremental download using lockfile #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1e5181b
90f211c
8691524
0b5dbd3
6bac022
6edb622
70617ea
d34eff7
bd13853
2516f41
5029d3d
4201ccf
8603a3b
dd86763
5263c39
6f15581
02562ff
509d3e6
4253132
ed2f5a1
f899267
a115f39
1439186
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| from confluence_markdown_exporter.utils.app_data_store import get_settings | ||
| from confluence_markdown_exporter.utils.app_data_store import set_setting | ||
| from confluence_markdown_exporter.utils.config_interactive import main_config_menu_loop | ||
| from confluence_markdown_exporter.utils.lockfile import LockfileManager | ||
| from confluence_markdown_exporter.utils.measure_time import measure | ||
| from confluence_markdown_exporter.utils.platform_compat import handle_powershell_tilde_expansion | ||
| from confluence_markdown_exporter.utils.type_converter import str_to_bool | ||
|
|
@@ -32,12 +33,22 @@ def pages( | |
| help="Directory to write exported Markdown files to. Overrides config if set." | ||
| ), | ||
| ] = None, | ||
| *, | ||
| lockfile: Annotated[ | ||
| bool, | ||
| typer.Option( | ||
| "--lockfile", | ||
| help="Enable lock file tracking for exported pages.", | ||
| ), | ||
| ] = False, | ||
| ) -> None: | ||
| from confluence_markdown_exporter.confluence import Page | ||
|
|
||
| with measure(f"Export pages {', '.join(pages)}"): | ||
| override_output_path_config(output_path) | ||
| if lockfile: | ||
| LockfileManager.init() | ||
| for page in pages: | ||
| override_output_path_config(output_path) | ||
| _page = Page.from_id(int(page)) if page.isdigit() else Page.from_url(page) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| _page.export() | ||
|
|
||
|
|
@@ -51,12 +62,29 @@ def pages_with_descendants( | |
| help="Directory to write exported Markdown files to. Overrides config if set." | ||
| ), | ||
| ] = None, | ||
| *, | ||
| lockfile: Annotated[ | ||
| bool, | ||
| typer.Option( | ||
| "--lockfile", | ||
| help="Enable lock file tracking for exported pages.", | ||
| ), | ||
| ] = False, | ||
naoki-tateyama marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| incremental: Annotated[ | ||
| bool, | ||
| typer.Option( | ||
| "--incremental", | ||
| help="Only export pages that have changed since last export.", | ||
| ), | ||
| ] = False, | ||
| ) -> None: | ||
| from confluence_markdown_exporter.confluence import Page | ||
|
|
||
| with measure(f"Export pages {', '.join(pages)} with descendants"): | ||
| override_output_path_config(output_path) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if lockfile or incremental: | ||
| LockfileManager.init() | ||
| for page in pages: | ||
| override_output_path_config(output_path) | ||
| _page = Page.from_id(int(page)) if page.isdigit() else Page.from_url(page) | ||
| _page.export_with_descendants() | ||
|
|
||
|
|
@@ -70,6 +98,21 @@ def spaces( | |
| help="Directory to write exported Markdown files to. Overrides config if set." | ||
| ), | ||
| ] = None, | ||
| *, | ||
| lockfile: Annotated[ | ||
| bool, | ||
| typer.Option( | ||
| "--lockfile", | ||
| help="Enable lock file tracking for exported pages.", | ||
| ), | ||
| ] = False, | ||
| incremental: Annotated[ | ||
| bool, | ||
| typer.Option( | ||
| "--incremental", | ||
| help="Only export pages that have changed since last export.", | ||
| ), | ||
| ] = False, | ||
| ) -> None: | ||
| from confluence_markdown_exporter.confluence import Space | ||
|
|
||
|
|
@@ -78,8 +121,10 @@ def spaces( | |
| normalized_space_keys = [handle_powershell_tilde_expansion(key) for key in space_keys] | ||
|
|
||
| with measure(f"Export spaces {', '.join(normalized_space_keys)}"): | ||
| override_output_path_config(output_path) | ||
| if lockfile or incremental: | ||
| LockfileManager.init() | ||
| for space_key in normalized_space_keys: | ||
| override_output_path_config(output_path) | ||
| space = Space.from_key(space_key) | ||
| space.export() | ||
|
|
||
|
|
@@ -92,11 +137,28 @@ def all_spaces( | |
| help="Directory to write exported Markdown files to. Overrides config if set." | ||
| ), | ||
| ] = None, | ||
| *, | ||
| lockfile: Annotated[ | ||
| bool, | ||
| typer.Option( | ||
| "--lockfile", | ||
| help="Enable lock file tracking for exported pages.", | ||
| ), | ||
| ] = False, | ||
| incremental: Annotated[ | ||
| bool, | ||
| typer.Option( | ||
| "--incremental", | ||
| help="Only export pages that have changed since last export.", | ||
| ), | ||
| ] = False, | ||
| ) -> None: | ||
| from confluence_markdown_exporter.confluence import Organization | ||
|
|
||
| with measure("Export all spaces"): | ||
| override_output_path_config(output_path) | ||
| if lockfile or incremental: | ||
| LockfileManager.init() | ||
| org = Organization.from_api() | ||
| org.export() | ||
|
|
||
|
|
@@ -125,6 +187,33 @@ def config( | |
| main_config_menu_loop(jump_to) | ||
|
|
||
|
|
||
| @app.command(help="Delete exported files that are not tracked in the lockfile.") | ||
| def prune( | ||
|
||
| output_path: Annotated[ | ||
| Path | None, | ||
| typer.Option(help="Directory containing exported Markdown files. Overrides config if set."), | ||
| ] = None, | ||
| *, | ||
| dry_run: Annotated[ | ||
| bool, | ||
| typer.Option( | ||
| "--dry-run", | ||
| help="Show files that would be deleted without actually deleting them.", | ||
| ), | ||
| ] = False, | ||
| ) -> None: | ||
| """Delete exported files not tracked in the lockfile.""" | ||
| override_output_path_config(output_path) | ||
| LockfileManager.init() | ||
| deleted = LockfileManager.cleanup_untracked(dry_run=dry_run) | ||
| if dry_run: | ||
| typer.echo(f"Would delete {len(deleted)} file(s):") | ||
| for path in deleted: | ||
| typer.echo(f" {path}") | ||
| else: | ||
| typer.echo(f"Deleted {len(deleted)} file(s).") | ||
|
|
||
|
|
||
| @app.command(help="Show the current version of confluence-markdown-exporter.") | ||
| def version() -> None: | ||
| """Display the current version.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could prefilter before starting the tqdm to only show a progressbar for pages to be exported:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 02562ff.