eric7/UI/upgrader.py

Sat, 05 Mar 2022 18:01:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Mar 2022 18:01:12 +0100
branch
eric7
changeset 8970
188ff9ce8657
child 8972
54816b8f740f
permissions
-rw-r--r--

Added capability to upgrade PyQt packages eric depends on from within eric.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Script to upgrade the packages eric depends on.

This process must be performed while eric is closed. The script will upgrade
the requested packages and will restart eric.
"""

import os
import subprocess
import sys
import time

from eric7config import getConfig


def upgradePyQt():
    """
    Function to upgrade the PyQt packages via pip.
    
    @return flag indicating a successful installation
    @rtype bool
    """
    pyqtPackages = [
        "pyqt6", "pyqt6-sip", "pyqt6-webengine", "pyqt6-charts",
        "pyqt6-qscintilla", "pyqt6-qt6", "pyqt6-webengine-qt6",
        "pyqt6-charts-qt6"
    ]
    
    exitCode = subprocess.run(                  # secok
        [sys.executable, "-m", "pip", "install", "--prefer-binary",
         "--upgrade"] + pyqtPackages
    ).returncode
    ok = (exitCode == 0)
    
    return ok


def upgradeEric():
    """
    Function to upgrade the eric-ide package via pip.
    
    @return flag indicating a successful installation
    @rtype bool
    """
    exitCode = subprocess.run(                  # secok
        [sys.executable, "-m", "pip", "install", "--prefer-binary",
         "--upgrade", "eric-ide"]
    ).returncode
    ok = (exitCode == 0)
    
    return ok


def startEric(args):
    """
    Function to start eric with the given arguments.
    
    @param args list containing the start arguments
    @type list of str
    """
    args = [sys.executable] + args
    subprocess.Popen(args)


def main():
    """
    Main entry point into the upgrader.
    """
    # wait a few seconds to give eric the chance to fully shut down
    time.sleep(2)
    
    try:
        ddindex = sys.argv.index("--")
    except ValueError:
        # '--' was not found. Start eric with all parameters given.
        ddindex = 1
    
    ericStartArgs = sys.argv[ddindex + 1:]
    if not ericStartArgs:
        # create default start arguments
        ericStartArgs = [
            os.path.join(getConfig("ericDir"), "eric7.py"),
            "--start-session",
        ]
    
    upgraderArgs = sys.argv[1:ddindex]
    
    # now perform the upgrade and start eric, if it was successful
    if upgraderArgs[0] == "--pyqt":
        ok = upgradePyQt()
    elif upgraderArgs[0] == "--eric":
        ok = upgradeEric()
    else:
        ok = False
    
    if ok:
        startEric(ericStartArgs)
        sys.exit(0)
    else:
        sys.exit(1)

if __name__ == "__main__":
    main()

eric ide

mercurial