-
Notifications
You must be signed in to change notification settings - Fork 4
/
uninstall.py
executable file
·84 lines (74 loc) · 2.41 KB
/
uninstall.py
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
#!/usr/bin/env python
#
# Copyright (C) 2006-2018 CZ.NIC, z. s. p. o.
#
# This file is part of FRED.
#
# FRED is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FRED is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FRED. If not, see <https://www.gnu.org/licenses/>.
import re, os
from distutils.sysconfig import get_config_var, get_python_lib
from setup import APP_SCRIPTS
def remove_all(top):
for root, dirs, files in os.walk(top, topdown=False):
for name in files:
path = os.path.join(root, name)
print 'Remove file:', path
try:
os.remove(path)
except OSError, msg:
print 'OSError:', msg
return 0
for name in dirs:
path = os.path.join(root, name)
print 'Remove folder:', path
try:
os.rmdir(path)
except OSError, msg:
print 'OSError:', msg
return 0
return 1
def check_root_privileges():
try:
import pwd
except ImportError:
return 1 # platform is not Unix
if pwd.getpwuid(os.getuid())[0] != 'root':
print 'Error: Unsufficient privileges. For uninstallation you need root privileges.'
return 0
return 1
def main():
if not check_root_privileges():
return 0
status = 1
print "REMOVE LIBRARY"
for name in ('fred', ):
pathname = os.path.join(get_python_lib(), name)
print pathname
if not remove_all(pathname):
status = 0
print "REMOVE SCRIPTS"
for name in APP_SCRIPTS:
pathname = os.path.join(get_config_var('BINDIR'), name)
print 'Remove script:', pathname
try:
os.remove(pathname)
except OSError, msg:
print 'OSError:', msg
status = 0
return status
if __name__ == '__main__':
if main():
print 'OK. Uninstall process completed successfully.'
else:
print 'Uninstall process failed.'