Implementing code to record and/or guess some information about the installation process.

Sun, 18 Oct 2020 18:51:45 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 18 Oct 2020 18:51:45 +0200
changeset 7804
1cbc27e34ec6
parent 7803
97f77d69c6f0
child 7805
3cad282e8409

Implementing code to record and/or guess some information about the installation process.

eric6/Globals/__init__.py file | annotate | diff | comparison | revisions
eric6/UI/UserInterface.py file | annotate | diff | comparison | revisions
eric6/eric6.py file | annotate | diff | comparison | revisions
scripts/install.py file | annotate | diff | comparison | revisions
setup.py file | annotate | diff | comparison | revisions
--- a/eric6/Globals/__init__.py	Sun Oct 18 12:42:37 2020 +0200
+++ b/eric6/Globals/__init__.py	Sun Oct 18 18:51:45 2020 +0200
@@ -20,6 +20,8 @@
     QDir, QByteArray, QCoreApplication, QT_VERSION, QProcess, qVersion
 )
 
+from eric6config import getConfig
+
 # names of the various settings objects
 settingsNameOrganization = "Eric6"
 settingsNameGlobal = "eric6"
@@ -213,6 +215,23 @@
     return hp
 
 
+def getInstallInfoFilePath():
+    """
+    Public method to get the path name of the install info file.
+    
+    @return file path of the install info file
+    @rtype str
+    """
+    filename = "eric6install.{0}.json".format(
+        getConfig("ericDir")
+        .replace("\\", "_")
+        .replace("/", "_")
+        .replace(" ", "_")
+        .strip("_")
+    )
+    return os.path.join(getConfigDir(), filename)
+
+
 def setConfigDir(d):
     """
     Module function to set the name of the directory storing the config data.
--- a/eric6/UI/UserInterface.py	Sun Oct 18 12:42:37 2020 +0200
+++ b/eric6/UI/UserInterface.py	Sun Oct 18 18:51:45 2020 +0200
@@ -10,6 +10,8 @@
 import os
 import sys
 import logging
+import shutil
+import json
 
 from PyQt5.QtCore import (
     pyqtSlot, QTimer, QFile, QFileInfo, pyqtSignal, PYQT_VERSION_STR, QDate,
@@ -1457,7 +1459,46 @@
             # no files, project or multiproject was given
             if not self.__noOpenAtStartup:
                 self.__openOnStartup()
-        
+    
+    def processInstallInfoFile(self):
+        """
+        Public method to process the file containing installation information.
+        """
+        import Globals
+        
+        installInfoFile = Globals.getInstallInfoFilePath()
+        if not os.path.exists(installInfoFile):
+            filename = os.path.join(getConfig("ericDir"), "eric6install.json")
+            if os.path.exists(filename):
+                # eric was installed via the install.py script
+                shutil.copy2(filename, installInfoFile)
+            else:
+                filename = os.path.join(getConfig("ericDir"),
+                                        "eric6installpip.json")
+                if os.path.exists(filename):
+                    # eric was installed via pip (i.e. eric-ide)
+                    try:
+                        with open(filename, "r") as infoFile:
+                            installInfo = json.load(infoFile)
+                        installInfo["guessed"] = True
+                        installInfo["eric"] = getConfig("ericDir")
+                        installInfo["virtualenv"] = (
+                            installInfo["eric"].startswith(
+                                os.path.expanduser("~"))
+                        )
+                        if installInfo["virtualenv"]:
+                            installInfo["user"] = os.getlogin()
+                            installInfo["exe"] = sys.executable
+                        installInfo["installed"] = True
+                        installInfo["remarks"] = ""
+                        installInfo["sudo"] = not os.access(
+                            installInfo["eric"], os.W_OK)
+                        with open(installInfoFile, "w") as infoFile:
+                            json.dump(installInfo, infoFile, indent=2)
+                    except EnvironmentError:
+                        # ignore this
+                        pass
+    
     def __createDockWindow(self, name):
         """
         Private method to create a dock window with common properties.
--- a/eric6/eric6.py	Sun Oct 18 12:42:37 2020 +0200
+++ b/eric6/eric6.py	Sun Oct 18 18:51:45 2020 +0200
@@ -237,6 +237,7 @@
     
     mainWindow.checkForErrorLog()
     mainWindow.processArgs(args)
+    mainWindow.processInstallInfoFile()
     mainWindow.checkProjectsWorkspace()
     mainWindow.checkConfigurationStatus()
     mainWindow.performVersionCheck(False)
--- a/scripts/install.py	Sun Oct 18 12:42:37 2020 +0200
+++ b/scripts/install.py	Sun Oct 18 18:51:45 2020 +0200
@@ -52,6 +52,9 @@
 macAppBundlePath = defaultMacAppBundlePath
 macPythonExe = defaultMacPythonExe
 
+installInfoName = "eric6install.json"
+installInfo = {}
+
 # Define blacklisted versions of the prerequisites
 BlackLists = {
     "sip": [],
@@ -1233,6 +1236,13 @@
                                            "MicroPython", "*.api"))):
                     apis.append(os.path.basename(apiName))
     
+    if sys.platform == "darwin":
+        macConfig = (
+            """    'macAppBundlePath': r'{0}',\n"""
+            """    'macAppBundleName': r'{1}',\n"""
+        ).format(macAppBundlePath, macAppBundleName)
+    else:
+        macConfig = ""
     config = (
         """# -*- coding: utf-8 -*-\n"""
         """#\n"""
@@ -1257,8 +1267,7 @@
         """    'mdir': r'{13}',\n"""
         """    'apidir': r'{14}',\n"""
         """    'apis': {15},\n"""
-        """    'macAppBundlePath': r'{16}',\n"""
-        """    'macAppBundleName': r'{17}',\n"""
+        """{16}"""
         """}}\n"""
         """\n"""
         """def getConfig(name):\n"""
@@ -1287,11 +1296,34 @@
         cfg['ericCodeTemplatesDir'], cfg['ericOthersDir'],
         cfg['bindir'], cfg['mdir'],
         cfg['apidir'], sorted(apis),
-        macAppBundlePath, macAppBundleName,
+        macConfig,
     )
     copyToFile(configName, config)
 
 
+def createInstallInfo():
+    """
+    Record information about the way eric6 was installed.
+    """
+    global installInfo, cfg
+    
+    try:
+        installInfo["sudo"] = os.getuid() == 0
+    except AttributeError:
+        installInfo["sudo"] = False
+    installInfo["user"] = os.getlogin()
+    installInfo["exe"] = sys.executable
+    installInfo["argv"] = sys.argv[:]
+    installInfo["eric"] = cfg["ericDir"]
+    installInfo["virtualenv"] = installInfo["eric"].startswith(
+        os.path.expanduser("~"))
+    installInfo["installed"] = True
+    installInfo["guessed"] = False
+    installInfo["edited"] = False
+    installInfo["pip"] = False
+    installInfo["remarks"] = ""
+
+
 def pipInstall(packageName, message):
     """
     Install the given package via pip.
@@ -1936,6 +1968,8 @@
     print("\nCreating configuration file ...")
     createConfig()
 
+    createInstallInfo()
+    
     # Compile .ui files
     print("\nCompiling user interface files ...")
     # step 1: remove old Ui_*.py files
@@ -1970,6 +2004,10 @@
     print("\nInstalling eric6 ...")
     res = installEric()
     
+    with open(os.path.join(cfg["ericDir"],
+                           installInfoName), "w") as installInfoFile:
+        json.dump(installInfo, installInfoFile, indent=2)
+    
     # do some cleanup
     try:
         if installFromSource:
--- a/setup.py	Sun Oct 18 12:42:37 2020 +0200
+++ b/setup.py	Sun Oct 18 18:51:45 2020 +0200
@@ -14,9 +14,12 @@
 import shutil
 import fnmatch
 import datetime
+import json
 
 from setuptools import setup, find_packages
 
+installInfoName = "eric6installpip.json"
+
 ######################################################################
 ## some helper functions below
 ######################################################################
@@ -241,6 +244,32 @@
     from PyQt5.uic import compileUiDir
     compileUiDir(dirName, True, __pyName)
 
+
+def createInstallInfoFile(dirName):
+    """
+    Create a file containing some rudimentary install information.
+    
+    @param dirName name of the directory to compile UI files for
+    @type str
+    """
+    global installInfoName
+    
+    installInfo = {
+        "sudo": False,
+        "user": "",
+        "exe": "",
+        "argv": "",
+        "eric": "",
+        "virtualenv": False,
+        "installed": False,
+        "guessed": False,
+        "edited": False,
+        "pip": True,
+        "remarks": "",
+    }
+    with open(os.path.join(dirName, installInfoName), "w") as infoFile:
+        json.dump(installInfo, infoFile, indent=2)
+
 ######################################################################
 ## setup() below
 ######################################################################
@@ -257,6 +286,7 @@
     compileUiFiles(sourceDir)
     prepareInfoFile(infoFileName, Version)
     prepareAppdataFile(appdataFileName, Version)
+    createInstallInfoFile(sourceDir)
     print("Preparation finished")           # __IGNORE_WARNING_M801__
 
 setup(
@@ -323,6 +353,7 @@
              ".bas", ".dat", ".xbel", ".xml", ".js"]
         ) + ["i18n/eric6_de.qm", "i18n/eric6_en.qm", "i18n/eric6_es.qm",
              "i18n/eric6_ru.qm",
+             installInfoName,
              ]
     },
     entry_points={

eric ide

mercurial