slpkg/clean.py

47 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/python3
2015-05-26 06:51:43 +03:00
# -*- coding: utf-8 -*-
2015-05-28 06:07:13 +03:00
2015-05-26 06:51:43 +03:00
import os
import shutil
class Clean:
2015-05-26 06:51:43 +03:00
"""Clean all data like man page, log files, PACKAGES.TXT and
2015-06-05 14:42:52 +03:00
configuration files. This is useful if "slpkg" installed via
"pip" because pip uninstalls only Python packages and script
and not data. So if uninstall with "# pip uninstall slpkg" after
run "# python clean.py" to remove all data and configuration files.
2015-06-13 16:23:48 +03:00
NOTE: Run this script as root."""
2015-05-26 06:51:43 +03:00
def __init__(self):
2015-05-26 07:30:22 +03:00
self.files = [
"/usr/man/man8/slpkg.8.gz",
"/etc/bash_completion.d/slpkg.bash-completion",
"/etc/fish/completions/slpkg.fish"
]
2022-05-31 11:55:18 +03:00
2015-05-26 07:30:22 +03:00
self.dirs = [
"/etc/slpkg/",
"/var/log/slpkg/",
"/var/lib/slpkg/",
"/tmp/slpkg/"
]
2015-05-26 06:51:43 +03:00
def start(self):
2015-05-26 07:30:22 +03:00
for f in self.files:
2022-05-31 11:55:18 +03:00
2015-05-26 07:30:22 +03:00
if os.path.isfile(f):
print(f"Remove file --> {f}")
2015-05-26 07:30:22 +03:00
os.remove(f)
2022-05-31 11:55:18 +03:00
2015-05-26 07:30:22 +03:00
for d in self.dirs:
2022-05-31 11:55:18 +03:00
2015-05-26 07:30:22 +03:00
if os.path.exists(d):
print(f"Remove directory --> {d}")
2015-05-26 07:30:22 +03:00
shutil.rmtree(d)
2015-05-26 06:51:43 +03:00
2015-06-05 14:42:52 +03:00
if __name__ == "__main__":
clean = Clean()
clean.start()