|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 |
|
7 """ |
|
8 Script to upgrade the packages eric depends on. |
|
9 |
|
10 This process must be performed while eric is closed. The script will upgrade |
|
11 the requested packages and will restart eric. |
|
12 """ |
|
13 |
|
14 import contextlib |
|
15 import subprocess |
|
16 import sys |
|
17 import time |
|
18 |
|
19 |
|
20 _pyqtPackages = [ |
|
21 "pyqt6", "pyqt6-sip", "pyqt6-webengine", "pyqt6-charts", |
|
22 "pyqt6-qscintilla", "pyqt6-qt6", "pyqt6-webengine-qt6", |
|
23 "pyqt6-charts-qt6" |
|
24 ] |
|
25 _ericPackages = ["eric-ide"] |
|
26 |
|
27 |
|
28 def doUpgrade(packages): |
|
29 """ |
|
30 Function to upgrade the given packages via pip. |
|
31 |
|
32 @param packages list of packages to be upgraded |
|
33 @type list of str |
|
34 @return flag indicating a successful installation |
|
35 @rtype bool |
|
36 """ |
|
37 exitCode = subprocess.run( # secok |
|
38 [sys.executable, "-m", "pip", "install", "--prefer-binary", |
|
39 "--upgrade"] + packages |
|
40 ).returncode |
|
41 ok = (exitCode == 0) |
|
42 |
|
43 return ok |
|
44 |
|
45 |
|
46 def startEric(args): |
|
47 """ |
|
48 Function to start eric with the given arguments. |
|
49 |
|
50 @param args list containing the start arguments |
|
51 @type list of str |
|
52 """ |
|
53 args = [sys.executable] + args |
|
54 subprocess.Popen(args) |
|
55 |
|
56 |
|
57 def main(): |
|
58 """ |
|
59 Main entry point into the upgrader. |
|
60 """ |
|
61 try: |
|
62 ddindex = sys.argv.index("--") |
|
63 except ValueError: |
|
64 # '--' was not found. Start eric with all parameters given. |
|
65 ddindex = 0 |
|
66 |
|
67 ericStartArgs = sys.argv[ddindex + 1:] if bool(ddindex) else [] |
|
68 if not ericStartArgs: |
|
69 # create default start arguments |
|
70 ericStartArgs = ["-m", "eric7", "--start-session"] |
|
71 |
|
72 upgraderArgs = sys.argv[1:ddindex] if bool(ddindex) else sys.argv[:] |
|
73 |
|
74 upgradeType = "" |
|
75 upgradeDelay = 2 |
|
76 |
|
77 for arg in upgraderArgs: |
|
78 if arg.startswith("--delay="): |
|
79 with contextlib.suppress(ValueError): |
|
80 upgradeDelay = int(arg.split("=")[1].strip()) |
|
81 elif arg.startswith("--type="): |
|
82 upgradeType = arg.split("=")[1].strip() |
|
83 |
|
84 # wait a few seconds to give eric the chance to fully shut down |
|
85 time.sleep(upgradeDelay) |
|
86 |
|
87 # now perform the upgrade and start eric, if it was successful |
|
88 if upgradeType == "pyqt": |
|
89 ok = doUpgrade(_pyqtPackages) |
|
90 elif upgradeType == "eric": |
|
91 ok = doUpgrade(_ericPackages) |
|
92 elif upgradeType == "ericpyqt": |
|
93 ok = doUpgrade(_ericPackages + _pyqtPackages) |
|
94 else: |
|
95 ok = False |
|
96 |
|
97 if ok: |
|
98 startEric(ericStartArgs) |
|
99 sys.exit(0) |
|
100 else: |
|
101 sys.exit(1) |
|
102 |
|
103 if __name__ == "__main__": |
|
104 main() |