File: uninstall.py

package info (click to toggle)
convertall 0.4.2-1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 320 kB
  • ctags: 232
  • sloc: python: 2,017; sh: 110; makefile: 42
file content (81 lines) | stat: -rwxr-xr-x 2,435 bytes parent folder | download
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
#!/usr/bin/env python

"""
****************************************************************************
 uninstall.py, Linux uninstall script for ConvertAll

 Copyright (C) 2006, 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 = 'convertall'
hasData = 0

def usage(exitCode=2):
    """Display usage info and exit"""
    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: %s]' % prefixDir
    sys.exit(exitCode)

def removeAll(path):
    """Remove path, whether it is a file or a directory,
       print status"""
    print '  Removing %s...' % 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, e:
        if str(e).find('Permission denied') >= 0:
            print '\nError - must be root to remove files'
            sys.exit(4)
        raise


def main():
    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))
    global hasData
    if hasData:
        removeAll(os.path.join(prefixDir, 'share', progName))
    removeAll(os.path.join(prefixDir, 'share', 'icons', progName))
    removeAll(os.path.join(prefixDir, 'share', 'icons', '%s_lg.png' % progName))
    removeAll(os.path.join(prefixDir, 'share', 'icons', '%s_sm.png' % progName))
    removeAll(os.path.join(prefixDir, 'bin', progName))
    print 'Uninstall complete.'


if __name__ == '__main__':
    main()