|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 # This is the uninstall script for the eric6 debug client. |
|
7 # |
|
8 |
|
9 """ |
|
10 Unnstallation script for the eric6 debug clients. |
|
11 """ |
|
12 |
|
13 from __future__ import unicode_literals, print_function |
|
14 |
|
15 import sys |
|
16 import os |
|
17 import shutil |
|
18 import distutils.sysconfig |
|
19 |
|
20 if sys.version_info[0] == 2: |
|
21 import sip |
|
22 sip.setapi('QString', 2) |
|
23 |
|
24 # Define the globals. |
|
25 progName = None |
|
26 currDir = os.getcwd() |
|
27 modDir = None |
|
28 pyModDir = None |
|
29 installPackage = "eric6DebugClients" |
|
30 |
|
31 |
|
32 def exit(rcode=0): |
|
33 """ |
|
34 Exit the install script. |
|
35 |
|
36 @param rcode result code to report back (integer) |
|
37 """ |
|
38 global currDir |
|
39 |
|
40 if sys.platform.startswith("win"): |
|
41 # different meaning of input between Py2 and Py3 |
|
42 try: |
|
43 input("Press enter to continue...") |
|
44 except (EOFError, SyntaxError): |
|
45 pass |
|
46 |
|
47 os.chdir(currDir) |
|
48 |
|
49 sys.exit(rcode) |
|
50 |
|
51 |
|
52 def usage(rcode=2): |
|
53 """ |
|
54 Display a usage message and exit. |
|
55 |
|
56 @param rcode return code passed back to the calling process (integer) |
|
57 """ |
|
58 global progName |
|
59 |
|
60 print("Usage:") |
|
61 print(" {0} [-h]".format(progName)) |
|
62 print("where:") |
|
63 print(" -h display this help message") |
|
64 |
|
65 exit(rcode) |
|
66 |
|
67 |
|
68 def initGlobals(): |
|
69 """ |
|
70 Module function to set the values of globals that need more than a |
|
71 simple assignment. |
|
72 """ |
|
73 global modDir, pyModDir |
|
74 |
|
75 modDir = distutils.sysconfig.get_python_lib(True) |
|
76 pyModDir = modDir |
|
77 |
|
78 |
|
79 def uninstallEricDebugClients(): |
|
80 """ |
|
81 Uninstall the old eric debug client files. |
|
82 """ |
|
83 global pyModDir |
|
84 |
|
85 try: |
|
86 # Cleanup the install directories |
|
87 dirname = os.path.join(pyModDir, installPackage) |
|
88 if os.path.exists(dirname): |
|
89 shutil.rmtree(dirname, True) |
|
90 except (IOError, OSError) as msg: |
|
91 sys.stderr.write( |
|
92 'Error: {0}\nTry uninstall with admin rights.\n'.format(msg)) |
|
93 exit(7) |
|
94 |
|
95 |
|
96 def main(argv): |
|
97 """ |
|
98 The main function of the script. |
|
99 |
|
100 @param argv the list of command line arguments. |
|
101 """ |
|
102 import getopt |
|
103 |
|
104 initGlobals() |
|
105 |
|
106 # Parse the command line. |
|
107 global progName |
|
108 progName = os.path.basename(argv[0]) |
|
109 |
|
110 try: |
|
111 optlist, args = getopt.getopt(argv[1:], "hy") |
|
112 except getopt.GetoptError: |
|
113 usage() |
|
114 |
|
115 for opt, arg in optlist: |
|
116 if opt in ["-h", "--help"]: |
|
117 usage(0) |
|
118 |
|
119 print("\nUninstalling eric6 debug clients ...") |
|
120 uninstallEricDebugClients() |
|
121 print("\nUninstallation complete.") |
|
122 print() |
|
123 |
|
124 exit(0) |
|
125 |
|
126 |
|
127 if __name__ == "__main__": |
|
128 try: |
|
129 main(sys.argv) |
|
130 except SystemExit: |
|
131 raise |
|
132 except Exception: |
|
133 print("""An internal error occured. Please report all the output""" |
|
134 """ of the program,\nincluding the following traceback, to""" |
|
135 """ eric-bugs@eric-ide.python-projects.org.\n""") |
|
136 raise |
|
137 |
|
138 # |
|
139 # eflag: noqa = M801 |