eric7/UI/upgrader.py

branch
eric7
changeset 8970
188ff9ce8657
child 8972
54816b8f740f
equal deleted inserted replaced
8969:52a07d67f4ed 8970:188ff9ce8657
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 os
15 import subprocess
16 import sys
17 import time
18
19 from eric7config import getConfig
20
21
22 def upgradePyQt():
23 """
24 Function to upgrade the PyQt packages via pip.
25
26 @return flag indicating a successful installation
27 @rtype bool
28 """
29 pyqtPackages = [
30 "pyqt6", "pyqt6-sip", "pyqt6-webengine", "pyqt6-charts",
31 "pyqt6-qscintilla", "pyqt6-qt6", "pyqt6-webengine-qt6",
32 "pyqt6-charts-qt6"
33 ]
34
35 exitCode = subprocess.run( # secok
36 [sys.executable, "-m", "pip", "install", "--prefer-binary",
37 "--upgrade"] + pyqtPackages
38 ).returncode
39 ok = (exitCode == 0)
40
41 return ok
42
43
44 def upgradeEric():
45 """
46 Function to upgrade the eric-ide package via pip.
47
48 @return flag indicating a successful installation
49 @rtype bool
50 """
51 exitCode = subprocess.run( # secok
52 [sys.executable, "-m", "pip", "install", "--prefer-binary",
53 "--upgrade", "eric-ide"]
54 ).returncode
55 ok = (exitCode == 0)
56
57 return ok
58
59
60 def startEric(args):
61 """
62 Function to start eric with the given arguments.
63
64 @param args list containing the start arguments
65 @type list of str
66 """
67 args = [sys.executable] + args
68 subprocess.Popen(args)
69
70
71 def main():
72 """
73 Main entry point into the upgrader.
74 """
75 # wait a few seconds to give eric the chance to fully shut down
76 time.sleep(2)
77
78 try:
79 ddindex = sys.argv.index("--")
80 except ValueError:
81 # '--' was not found. Start eric with all parameters given.
82 ddindex = 1
83
84 ericStartArgs = sys.argv[ddindex + 1:]
85 if not ericStartArgs:
86 # create default start arguments
87 ericStartArgs = [
88 os.path.join(getConfig("ericDir"), "eric7.py"),
89 "--start-session",
90 ]
91
92 upgraderArgs = sys.argv[1:ddindex]
93
94 # now perform the upgrade and start eric, if it was successful
95 if upgraderArgs[0] == "--pyqt":
96 ok = upgradePyQt()
97 elif upgraderArgs[0] == "--eric":
98 ok = upgradeEric()
99 else:
100 ok = False
101
102 if ok:
103 startEric(ericStartArgs)
104 sys.exit(0)
105 else:
106 sys.exit(1)
107
108 if __name__ == "__main__":
109 main()

eric ide

mercurial