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