Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions md2cf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ def get_parser():
help="only upload pages and attachments that have changed. "
"This adds a hash of the page or attachment contents to the update message",
)
parser.add_argument(
"--clear",
action="store_true",
help="delete all subpages in the space or of the parent pages before uploading new ones.",
Comment thread
stevengoossensB marked this conversation as resolved.
Outdated
)
parser.add_argument(
"file_list",
type=Path,
Expand Down Expand Up @@ -317,6 +322,25 @@ def main():
)
sys.exit(1)

# if --clear is detected, we need to delete all the pages in the space or subpages of the parent pages
if args.clear:
pages_to_delete = []
if args.parent_id:
pages_to_delete = confluence.get_all_pages_from_parent_id(args.parent_id)

# Don't implement cleaning of whole space
# else:
# pages_to_delete = confluence.get_all_pages_from_space(args.space)

Comment thread
stevengoossensB marked this conversation as resolved.
Outdated
for page in pages_to_delete:
try:
confluence.delete_page(page)
console.log(f"Deleted page {page.title}")
except HTTPError as e:
error_console.log(
f"Failed to delete page {page.title} with error {e.response.content}"
)

pages_to_upload = collect_pages_to_upload(args)

page_title_counts = Counter([page.title for page in pages_to_upload])
Expand Down
16 changes: 15 additions & 1 deletion md2cf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ def __init__(
def _request(self, method, path, **kwargs):
r = self.api.request(method, urljoin(self.host, path), **kwargs)
r.raise_for_status()
return bunchify(r.json())

if r.status_code != 204:
return bunchify(r.json())
else:
return None
Comment thread
stevengoossensB marked this conversation as resolved.

def _get(self, path, **kwargs):
return self._request("GET", path, **kwargs)
Expand All @@ -77,6 +81,9 @@ def _post(self, path, **kwargs):
def _put(self, path, **kwargs):
return self._request("PUT", path, **kwargs)

def _delete(self, path, **kwargs):
return self._request("DELETE", path, **kwargs)

def get_page(
self,
title=None,
Expand Down Expand Up @@ -212,6 +219,13 @@ def update_page(

return self._put(f"content/{page.id}", json=update_structure)

def delete_page(self, confluence_page):
return self._delete(f"content/{confluence_page.id}")

def get_all_pages_from_parent_id(self, parent_id):
Comment thread
stevengoossensB marked this conversation as resolved.
pages = self._get(f"content/{parent_id}/child/page")['results']
return pages

def get_attachment(self, confluence_page, name):
existing_attachments = self._get(
f"content/{confluence_page.id}/child/attachment",
Expand Down