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 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#!/usr/bin/env python
"""
****************************************************************************
uninstall.py, Linux uninstall script for TreeLine
Copyright (C) 2018, Douglas W. Bell
This is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License, either Version 2 or any later
version. This program is distributed in the hope that it will be useful,
but WITTHOUT ANY WARRANTY. See the included LICENSE file for details.
*****************************************************************************
"""
import sys
import os.path
import getopt
import shutil
prefixDir = '/usr/local'
progName = 'treeline'
def usage(exitCode=2):
"""Display usage info and exit.
Arguments:
exitCode -- the code to retuen when exiting.
"""
global prefixDir
print('Usage:')
print(' python uninstall.py [-h] [-p dir]')
print('where:')
print(' -h display this help message')
print(' -p dir install prefix [default: {0}]'.format(prefixDir))
sys.exit(exitCode)
def removeAll(path):
"""Remove path, whether it is a file or a directory,
print status"""
print(' Removing {0}...'.format(path))
try:
if os.path.isdir(path):
shutil.rmtree(path)
elif os.path.isfile(path):
os.remove(path)
else:
print(' not found')
return
print(' done')
except OSError as e:
if str(e).find('Permission denied') >= 0:
print('\nError - must be root to remove files')
sys.exit(4)
raise
def main():
"""Main uninstaller function.
"""
try:
opts, args = getopt.getopt(sys.argv[1:], 'hp:')
except getopt.GetoptError:
usage(2)
global prefixDir
for opt, val in opts:
if opt == '-h':
usage(0)
elif opt == '-p':
prefixDir = val
print('Removing files...')
global progName
removeAll(os.path.join(prefixDir, 'lib', progName))
removeAll(os.path.join(prefixDir, 'share', 'doc', progName))
removeAll(os.path.join(prefixDir, 'share', progName))
removeAll(os.path.join(prefixDir, 'share', 'icons', progName))
removeAll(os.path.join(prefixDir, 'share', 'icons', 'hicolor', '48x48',
'apps', progName + '-icon.png'))
removeAll(os.path.join(prefixDir, 'share', 'icons', 'hicolor', 'scalable',
'apps', progName + '-icon.svg'))
removeAll(os.path.join(prefixDir, 'share', 'applications',
progName + '.desktop'))
removeAll(os.path.join(prefixDir, 'bin', progName))
print('Uninstall complete.')
if __name__ == '__main__':
main()
|