2019-11-30 22:56:50 +01:00
|
|
|
#!/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
|
|
|
|
|
|
|
|
|
2019-12-06 13:10:42 +01:00
|
|
|
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
|
2019-01-21 22:10:46 +01:00
|
|
|
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):
|
2020-01-20 18:50:40 +01:00
|
|
|
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):
|
2020-01-20 18:50:40 +01:00
|
|
|
print(f"Remove directory --> {d}")
|
2015-05-26 07:30:22 +03:00
|
|
|
shutil.rmtree(d)
|
2015-05-26 06:51:43 +03:00
|
|
|
|
2019-01-21 22:10:46 +01:00
|
|
|
|
2015-06-05 14:42:52 +03:00
|
|
|
if __name__ == "__main__":
|
2019-12-06 13:10:42 +01:00
|
|
|
clean = Clean()
|
|
|
|
clean.start()
|