src/eric7/UI/upgrader.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9324
7f7f3e47b238
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
16 import sys 16 import sys
17 import time 17 import time
18 18
19 19
20 _pyqtPackages = [ 20 _pyqtPackages = [
21 "pyqt6", "pyqt6-sip", "pyqt6-webengine", "pyqt6-charts", 21 "pyqt6",
22 "pyqt6-qscintilla", "pyqt6-qt6", "pyqt6-webengine-qt6", 22 "pyqt6-sip",
23 "pyqt6-charts-qt6" 23 "pyqt6-webengine",
24 "pyqt6-charts",
25 "pyqt6-qscintilla",
26 "pyqt6-qt6",
27 "pyqt6-webengine-qt6",
28 "pyqt6-charts-qt6",
24 ] 29 ]
25 _ericPackages = ["eric-ide"] 30 _ericPackages = ["eric-ide"]
26 31
27 32
28 def doUpgrade(packages): 33 def doUpgrade(packages):
29 """ 34 """
30 Function to upgrade the given packages via pip. 35 Function to upgrade the given packages via pip.
31 36
32 @param packages list of packages to be upgraded 37 @param packages list of packages to be upgraded
33 @type list of str 38 @type list of str
34 @return flag indicating a successful installation 39 @return flag indicating a successful installation
35 @rtype bool 40 @rtype bool
36 """ 41 """
37 exitCode = subprocess.run( # secok 42 exitCode = subprocess.run( # secok
38 [sys.executable, "-m", "pip", "install", "--prefer-binary", 43 [sys.executable, "-m", "pip", "install", "--prefer-binary", "--upgrade"]
39 "--upgrade"] + packages 44 + packages
40 ).returncode 45 ).returncode
41 ok = (exitCode == 0) 46 ok = exitCode == 0
42 47
43 return ok 48 return ok
44 49
45 50
46 def startEric(args): 51 def startEric(args):
47 """ 52 """
48 Function to start eric with the given arguments. 53 Function to start eric with the given arguments.
49 54
50 @param args list containing the start arguments 55 @param args list containing the start arguments
51 @type list of str 56 @type list of str
52 """ 57 """
53 args = [sys.executable] + args 58 args = [sys.executable] + args
54 subprocess.Popen(args) 59 subprocess.Popen(args)
61 try: 66 try:
62 ddindex = sys.argv.index("--") 67 ddindex = sys.argv.index("--")
63 except ValueError: 68 except ValueError:
64 # '--' was not found. Start eric with all parameters given. 69 # '--' was not found. Start eric with all parameters given.
65 ddindex = 0 70 ddindex = 0
66 71
67 ericStartArgs = sys.argv[ddindex + 1:] if bool(ddindex) else [] 72 ericStartArgs = sys.argv[ddindex + 1 :] if bool(ddindex) else []
68 if not ericStartArgs: 73 if not ericStartArgs:
69 # create default start arguments 74 # create default start arguments
70 ericStartArgs = ["-m", "eric7", "--start-session"] 75 ericStartArgs = ["-m", "eric7", "--start-session"]
71 76
72 upgraderArgs = sys.argv[1:ddindex] if bool(ddindex) else sys.argv[:] 77 upgraderArgs = sys.argv[1:ddindex] if bool(ddindex) else sys.argv[:]
73 78
74 upgradeType = "" 79 upgradeType = ""
75 upgradeDelay = 2 80 upgradeDelay = 2
76 81
77 for arg in upgraderArgs: 82 for arg in upgraderArgs:
78 if arg.startswith("--delay="): 83 if arg.startswith("--delay="):
79 with contextlib.suppress(ValueError): 84 with contextlib.suppress(ValueError):
80 upgradeDelay = int(arg.split("=")[1].strip()) 85 upgradeDelay = int(arg.split("=")[1].strip())
81 elif arg.startswith("--type="): 86 elif arg.startswith("--type="):
82 upgradeType = arg.split("=")[1].strip() 87 upgradeType = arg.split("=")[1].strip()
83 88
84 # wait a few seconds to give eric the chance to fully shut down 89 # wait a few seconds to give eric the chance to fully shut down
85 time.sleep(upgradeDelay) 90 time.sleep(upgradeDelay)
86 91
87 # now perform the upgrade and start eric, if it was successful 92 # now perform the upgrade and start eric, if it was successful
88 if upgradeType == "pyqt": 93 if upgradeType == "pyqt":
89 ok = doUpgrade(_pyqtPackages) 94 ok = doUpgrade(_pyqtPackages)
90 elif upgradeType == "eric": 95 elif upgradeType == "eric":
91 ok = doUpgrade(_ericPackages) 96 ok = doUpgrade(_ericPackages)
92 elif upgradeType == "ericpyqt": 97 elif upgradeType == "ericpyqt":
93 ok = doUpgrade(_ericPackages + _pyqtPackages) 98 ok = doUpgrade(_ericPackages + _pyqtPackages)
94 else: 99 else:
95 ok = False 100 ok = False
96 101
97 if ok: 102 if ok:
98 startEric(ericStartArgs) 103 startEric(ericStartArgs)
99 sys.exit(0) 104 sys.exit(0)
100 else: 105 else:
101 sys.exit(1) 106 sys.exit(1)
102 107
108
103 if __name__ == "__main__": 109 if __name__ == "__main__":
104 main() 110 main()

eric ide

mercurial