Mini Shell

Direktori : /opt/tier1adv/bin/
Upload File :
Current File : //opt/tier1adv/bin/rmpwb

#!/opt/imh-python/bin/python3
"""Removes pwb"""
import argparse
import sys
from pathlib import Path
import shutil
import rads

sys.path.insert(0, '/opt/support/lib')
from arg_types import cpuser_safe_arg


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('user', type=cpuser_safe_arg, help='username')
    user = parser.parse_args().user
    home = Path('/home', user)
    dirs = [
        home / f"{user}PrivateDataDir",
        home / 'public_html/Preview',
        home / 'public_html/Site',
        home / 'public_html/SiteMgr',
        home / 'public_html/images/1',
        home / 'public_html/images/ThumbNails',
    ]
    dirs = [x for x in dirs if x.is_dir()]
    files = [
        home / 'public_html/cgi-bin/dataclct.cgi',
        home / 'public_html/cgi-bin/Dispatcher.cfg',
        home / 'public_html/cgi-bin/PowerCounter.cgi',
        home / 'public_html/cgi-bin/PowerManager.cgi',
        home / 'public_html/cgi-bin/PowerShopper.cgi',
        home / 'public_html/cgi-bin/SharedBinDir.cfg',
        home / 'public_html/cgi-bin/WebInfo.cgi',
        home / 'public_html/FlashInfo.txt',
        home / 'public_html/_index.html',
        home / 'public_html/_PrivateHtmlTest.html',
        home / f'public_html/MySharedHtDocsSubDir_{user}',
        home / 'public_html/cgi-bin/cgiecho',
        home / 'public_html/cgi-bin/cgiemail',
        home / 'public_html/cgi-bin/entropybanner.cgi',
        home / 'public_html/randhtml.cgi',
    ]
    files = [x for x in files if x.is_file()]
    if dirs:
        print("pwb directories found:")
        print(*dirs, sep='\n')
    if files:
        print('\npwb files found:')
        print(*files, sep='\n')
    if not dirs and not files:
        sys.exit('No pwb files found to delete')
    if not rads.prompt_y_n("Delete?"):
        sys.exit(0)
    for path in dirs:
        shutil.rmtree(path, ignore_errors=True)
    for path in files:
        path.unlink(missing_ok=True)
    print("pwb uninstalled for", user)
    print("Check the cgi-bin and images for extra directories")


if __name__ == '__main__':
    main()

Zerion Mini Shell 1.0