eric6/UI/UserInterface.py

branch
multi_processing
changeset 7818
5c9271c2f662
parent 7802
eefe954f01e8
parent 7814
6fa40642ed7c
child 7853
35dcac32984a
--- a/eric6/UI/UserInterface.py	Sun Oct 18 12:35:30 2020 +0200
+++ b/eric6/UI/UserInterface.py	Sat Oct 31 12:18:29 2020 +0100
@@ -10,6 +10,10 @@
 import os
 import sys
 import logging
+import shutil
+import json
+import datetime
+import getpass
 
 from PyQt5.QtCore import (
     pyqtSlot, QTimer, QFile, QFileInfo, pyqtSignal, PYQT_VERSION_STR, QDate,
@@ -41,6 +45,7 @@
 
 import Preferences
 import Utilities
+import Globals
 
 import UI.PixmapCache
 
@@ -1445,7 +1450,100 @@
             # 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:
+                        installDateTime = datetime.datetime.now(tz=None)
+                        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"] = getpass.getuser()
+                            installInfo["exe"] = sys.executable
+                        installInfo["installed"] = True
+                        installInfo["installed_on"] = installDateTime.strftime(
+                            "%Y-%m-%d %H:%M:%S")
+                        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
+        else:
+            changed = False
+            with open(installInfoFile, "r") as infoFile:
+                installInfo = json.load(infoFile)
+            
+            # 1. adapt stored file to latest format
+            if "install_cwd" not in installInfo:
+                installInfo["install_cwd"] = ""
+                installInfo["install_cwd_edited"] = False
+                changed = True
+            if "installed_on" not in installInfo:
+                installInfo["installed_on"] = ""
+                changed = True
+            
+            # 2. merge new data into stored file
+            filename = os.path.join(getConfig("ericDir"), "eric6install.json")
+            if os.path.exists(filename):
+                # eric was updated via the install.py script
+                if (
+                    os.path.getmtime(filename) >
+                    os.path.getmtime(installInfoFile)
+                ):
+                    if not installInfo["edited"]:
+                        shutil.copy2(filename, installInfoFile)
+                    else:
+                        with open(filename, "r") as infoFile:
+                            installInfo2 = json.load(infoFile)
+                        if not installInfo["install_cwd_edited"]:
+                            installInfo2["install_cwd"] = installInfo[
+                                "install_cwd"]
+                        if not installInfo["exe_edited"]:
+                            installInfo2["exe"] = installInfo["exe"]
+                        if not installInfo["argv_edited"]:
+                            installInfo2["argv"] = installInfo["argv"]
+                        if not installInfo["eric_edited"]:
+                            installInfo2["eric"] = installInfo["eric"]
+                        installInfo = installInfo2
+                        changed = True
+            else:
+                filename = os.path.join(getConfig("ericDir"),
+                                        "eric6installpip.json")
+                if os.path.exists(filename):
+                    # eric was updated via pip (i.e. eric-ide)
+                    # just update the installation date and time
+                    installDateTime = datetime.datetime.now(tz=None)
+                    installInfo["installed_on"] = installDateTime.strftime(
+                        "%Y-%m-%d %H:%M:%S")
+                    changed = True
+            
+            if changed:
+                with open(installInfoFile, "w") as infoFile:
+                    json.dump(installInfo, infoFile, indent=2)
+    
     def __createDockWindow(self, name):
         """
         Private method to create a dock window with common properties.
@@ -2103,6 +2201,20 @@
         self.showErrorLogAct.triggered.connect(self.__showErrorLog)
         self.actions.append(self.showErrorLogAct)
         
+        self.showInstallInfoAct = E5Action(
+            self.tr('Show Install Info'),
+            self.tr('Show Install &Info...'),
+            0, 0, self, 'show_install_info')
+        self.showInstallInfoAct.setStatusTip(self.tr(
+            'Show Installation Information'))
+        self.showInstallInfoAct.setWhatsThis(self.tr(
+            """<b>Show Install Info...</b>"""
+            """<p>Opens a dialog showing some information about the"""
+            """ installation process.</p>"""
+        ))
+        self.showInstallInfoAct.triggered.connect(self.__showInstallInfo)
+        self.actions.append(self.showInstallInfoAct)
+        
         self.reportBugAct = E5Action(
             self.tr('Report Bug'),
             self.tr('Report &Bug...'),
@@ -3133,6 +3245,8 @@
         self.__menus["help"].addAction(self.checkUpdateAct)
         self.__menus["help"].addAction(self.showVersionsAct)
         self.__menus["help"].addSeparator()
+        self.__menus["help"].addAction(self.showInstallInfoAct)
+        self.__menus["help"].addSeparator()
         self.__menus["help"].addAction(self.showErrorLogAct)
         self.__menus["help"].addAction(self.reportBugAct)
         self.__menus["help"].addAction(self.requestFeatureAct)
@@ -3508,6 +3622,9 @@
         self.showVersionsAct.setEnabled(not self.__inVersionCheck)
         self.showErrorLogAct.setEnabled(self.__hasErrorLog())
         
+        infoFileName = Globals.getInstallInfoFilePath()
+        self.showInstallInfoAct.setEnabled(os.path.exists(infoFileName))
+        
         self.showMenu.emit("Help", self.__menus["help"])
     
     def __showSettingsMenu(self):
@@ -3730,7 +3847,17 @@
             from .ErrorLogDialog import ErrorLogDialog
             dlg = ErrorLogDialog(logFile, True, self)
             dlg.show()
-        
+    
+    def __showInstallInfo(self):
+        """
+        Private slot to show a dialog containing information about the
+        installation process.
+        """
+        from .InstallInfoDialog import InstallInfoDialog
+        dlg = InstallInfoDialog(self)
+        if dlg.wasLoaded():
+            dlg.exec()
+    
     def __compareFiles(self):
         """
         Private slot to handle the Compare Files dialog.

eric ide

mercurial