|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 # This is the uninstall script for the eric-ide server. |
|
7 # |
|
8 |
|
9 """ |
|
10 Uninstallation script for the eric-ide server. |
|
11 """ |
|
12 |
|
13 import argparse |
|
14 import contextlib |
|
15 import os |
|
16 import shutil |
|
17 import sys |
|
18 import sysconfig |
|
19 |
|
20 # Define the globals. |
|
21 currDir = os.getcwd() |
|
22 scriptsDir = None |
|
23 modDir = None |
|
24 pyModDir = None |
|
25 installPackage = "eric7" |
|
26 |
|
27 |
|
28 def exit(rcode=0): |
|
29 """ |
|
30 Exit the install script. |
|
31 |
|
32 @param rcode result code to report back |
|
33 @type int |
|
34 """ |
|
35 global currDir |
|
36 |
|
37 if sys.platform.startswith("win"): |
|
38 with contextlib.suppress(EOFError): |
|
39 input("Press enter to continue...") # secok |
|
40 |
|
41 os.chdir(currDir) |
|
42 |
|
43 sys.exit(rcode) |
|
44 |
|
45 |
|
46 def initGlobals(): |
|
47 """ |
|
48 Module function to set the values of globals that need more than a |
|
49 simple assignment. |
|
50 """ |
|
51 global modDir, pyModDir, scriptsDir |
|
52 |
|
53 # determine the platform scheme |
|
54 if sys.platform.startswith(("win", "cygwin")): |
|
55 scheme = "nt_user" |
|
56 elif sys.platform == "darwin": |
|
57 scheme = "osx_framework_user" |
|
58 else: |
|
59 scheme = "posix_user" |
|
60 |
|
61 # determine modules directory |
|
62 modDir = sysconfig.get_path("platlib") |
|
63 if not os.access(modDir, os.W_OK): |
|
64 # can't write to the standard path, use the 'user' path instead |
|
65 modDir = sysconfig.get_path("platlib", scheme) |
|
66 pyModDir = modDir |
|
67 |
|
68 # determine the scripts directory |
|
69 scriptsDir = sysconfig.get_path("scripts") |
|
70 if not os.access(scriptsDir, os.W_OK): |
|
71 # can't write to the standard path, use the 'user' path instead |
|
72 scriptsDir = sysconfig.get_path("scripts", scheme) |
|
73 |
|
74 |
|
75 def wrapperNames(dname, wfile): |
|
76 """ |
|
77 Create the platform specific names for the wrapper script. |
|
78 |
|
79 @param dname name of the directory to place the wrapper into |
|
80 @type str |
|
81 @param wfile basename (without extension) of the wrapper script |
|
82 @type str |
|
83 @return list of names of the wrapper scripts |
|
84 @rtype list of str |
|
85 """ |
|
86 wnames = ( |
|
87 [dname + "\\" + wfile + ".cmd", dname + "\\" + wfile + ".bat"] |
|
88 if sys.platform.startswith(("win", "cygwin")) |
|
89 else [dname + "/" + wfile] |
|
90 ) |
|
91 |
|
92 return wnames |
|
93 |
|
94 |
|
95 def uninstallEricServer(): |
|
96 """ |
|
97 Uninstall the old eric-ide server files. |
|
98 """ |
|
99 global installPackage, pyModDir, scriptsDir |
|
100 |
|
101 try: |
|
102 # Cleanup the package directories |
|
103 dirname = os.path.join(pyModDir, installPackage) |
|
104 if os.path.exists(dirname): |
|
105 shutil.rmtree(dirname, ignore_errors=True) |
|
106 except OSError as msg: |
|
107 sys.stderr.write("Error: {0}\nTry uninstall with admin rights.\n".format(msg)) |
|
108 exit(7) |
|
109 |
|
110 # Remove the wrapper scripts |
|
111 rem_wnames = ["eric7_server"] |
|
112 try: |
|
113 for rem_wname in rem_wnames: |
|
114 for rwname in wrapperNames(scriptsDir, rem_wname): |
|
115 if os.path.exists(rwname): |
|
116 os.remove(rwname) |
|
117 except OSError as msg: |
|
118 sys.stderr.write("Error: {0}\nTry uninstall with admin rights.\n".format(msg)) |
|
119 exit(7) |
|
120 |
|
121 |
|
122 def createArgumentParser(): |
|
123 """ |
|
124 Function to create an argument parser. |
|
125 |
|
126 @return created argument parser object |
|
127 @rtype argparse.ArgumentParser |
|
128 """ |
|
129 parser = argparse.ArgumentParser(description="Uninstall eric-ide server.") |
|
130 return parser |
|
131 |
|
132 |
|
133 def main(): |
|
134 """ |
|
135 The main function of the script. |
|
136 """ |
|
137 initGlobals() |
|
138 |
|
139 parser = createArgumentParser() |
|
140 parser.parse_args() |
|
141 |
|
142 print("\nUninstalling eric-ide server ...") |
|
143 uninstallEricServer() |
|
144 print("\nUninstallation complete.") |
|
145 print() |
|
146 |
|
147 exit(0) |
|
148 |
|
149 |
|
150 if __name__ == "__main__": |
|
151 try: |
|
152 main() |
|
153 except SystemExit: |
|
154 raise |
|
155 except Exception: |
|
156 print( |
|
157 """An internal error occured. Please report all the output""" |
|
158 """ of the program,\nincluding the following traceback, to""" |
|
159 """ eric-bugs@eric-ide.python-projects.org.\n""" |
|
160 ) |
|
161 raise |
|
162 |
|
163 # |
|
164 # eflag: noqa = M801 |