ikiwiki: Completely uninstall app

Tests:
1. Create a wiki and a blog
2. Reinstall the app and confirm the sites get deleted

Signed-off-by: nbenedek <contact@nbenedek.me>
[sunil: Update docstrings, make uninstall fail-safe]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
nbenedek 2023-04-07 00:41:30 +02:00 committed by Sunil Mohan Adapa
parent 53f4edb016
commit b2ad4088aa
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 17 additions and 7 deletions

View File

@ -112,6 +112,11 @@ class IkiwikiApp(app_module.App):
privileged.setup()
self.enable()
def uninstall(self):
"""De-configure and uninstall the app."""
super().uninstall()
privileged.uninstall()
class IkiwikiBackupRestore(BackupRestore):
"""Component to handle Ikiwiki restore"""

View File

@ -2,6 +2,7 @@
"""Configure ikiwiki."""
import os
import pathlib
import re
import shutil
import subprocess
@ -96,10 +97,14 @@ def delete(name: str):
raise ValueError(
'Error: {0} is not a correct wiki/blog name.'.format(name))
try:
shutil.rmtree(html_folder)
shutil.rmtree(wiki_folder)
shutil.rmtree(wiki_folder + '.git')
os.remove(wiki_folder + '.setup')
except FileNotFoundError:
raise RuntimeError('Unable to delete wiki/blog')
shutil.rmtree(html_folder, ignore_errors=True)
shutil.rmtree(wiki_folder, ignore_errors=True)
shutil.rmtree(wiki_folder + '.git', ignore_errors=True)
pathlib.Path(wiki_folder + '.setup').unlink(missing_ok=True)
@privileged
def uninstall():
"""Remove all ikiwiki sites."""
for site in get_sites():
delete(site[0])