File size: 2,437 Bytes
56d74b6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # coding=utf-8
from atlassian import Confluence
"""This example shows how to remove page by page from trash for all spaces"""
confluence = Confluence(url="http://localhost:8090", username="admin", password="admin")
def clean_pages_from_space(space_key, limit=500):
"""
Remove all pages from trash for related space
:param limit:
:param space_key:
:return:
"""
flag = True
while flag:
values = confluence.get_all_pages_from_space_trash(space=space_key, start=0, limit=limit, content_type="page")
if not values or len(values) == 0:
flag = False
print("For space {} trash is empty".format(space_key))
else:
print("Found in space {} pages as trashed {}".format(space_key, len(values)))
for value in values:
print("Removing page with title: " + value["title"])
confluence.remove_page_from_trash(value["id"])
def clean_blog_posts_from_space(space_key, limit=500):
"""
Remove all pages from trash for related space
:param limit:
:param space_key:
:return:
"""
flag = True
while flag:
values = confluence.get_all_pages_from_space_trash(
space=space_key, start=0, limit=limit, content_type="blogpost"
)
if values and len(values) > 0:
print("Found in space {} pages as trashed {}".format(space_key, len(values)))
for value in values:
print("Removing page with title: " + value["title"])
confluence.remove_page_from_trash(value["id"])
else:
flag = False
print("For space {} trash is empty".format(space_key))
def clean_all_trash_pages_from_all_spaces():
"""
Main function for retrieve space keys and provide space for cleaner
:return:
"""
limit = 50
flag = True
i = 0
while flag:
space_lists = confluence.get_all_spaces(start=i * limit, limit=limit)
if space_lists and len(space_lists) != 0:
i += 1
for space_list in space_lists:
print("Start review the space with key = " + space_list["key"])
clean_pages_from_space(space_key=space_list["key"])
clean_blog_posts_from_space(space_key=space_list["key"])
else:
flag = False
return 0
if __name__ == "__main__":
clean_all_trash_pages_from_all_spaces()
|