install.py

changeset 6509
884182bfd25c
parent 6500
0373580fc86c
child 6510
d8fd663f86ef
--- a/install.py	Thu Sep 20 19:36:15 2018 +0200
+++ b/install.py	Thu Sep 20 19:48:56 2018 +0200
@@ -115,7 +115,7 @@
     
     print()
     
-    if sys.platform.startswith("win"):
+    if sys.platform.startswith(("win", "cygwin")):
         # different meaning of input between Py2 and Py3
         try:
             input("Press enter to continue...")
@@ -142,7 +142,7 @@
     if sys.platform == "darwin":
         print("    {0} [-chxyz] [-a dir] [-b dir] [-d dir] [-f file] [-i dir]"
               " [-m name] [-p python] [--pyqt=version]".format(progName))
-    elif sys.platform.startswith("win"):
+    elif sys.platform.startswith(("win", "cygwin")):
         print("    {0} [-chxyz] [-a dir] [-b dir] [-d dir] [-f file]"
               " [--pyqt=version]"
               .format(progName))
@@ -164,7 +164,7 @@
     print("               (default: {0})".format(modDir))
     print("    -f file    configuration file naming the various installation"
           " paths")
-    if not sys.platform.startswith("win"):
+    if not sys.platform.startswith(("win", "cygwin")):
         print("    -i dir     temporary install prefix")
         print("               (default: {0})".format(distDir))
     if sys.platform == "darwin":
@@ -242,7 +242,7 @@
         print("Please install the 'distutils' package first.")
         exit(5)
     
-    if sys.platform.startswith("win"):
+    if sys.platform.startswith(("win", "cygwin")):
         platBinDir = sys.exec_prefix
         if platBinDir.endswith("\\"):
             platBinDir = platBinDir[:-1]
@@ -381,7 +381,7 @@
     @param wfile basename (without extension) of the wrapper script
     @return the names of the wrapper scripts
     """
-    if sys.platform.startswith("win"):
+    if sys.platform.startswith(("win", "cygwin")):
         wnames = (dname + "\\" + wfile + ".cmd",
                   dname + "\\" + wfile + ".bat")
     else:
@@ -414,7 +414,7 @@
         pyqt4opt = ""
     
     # all kinds of Windows systems
-    if sys.platform.startswith("win"):
+    if sys.platform.startswith(("win", "cygwin")):
         wname = wfile + marker + ".cmd"
         if isGuiScript:
             wrapper = \
@@ -574,6 +574,9 @@
     # Remove the menu entry for Linux systems
     if sys.platform.startswith("linux"):
         cleanUpLinuxSpecifics()
+    # Remove the Desktop and Start Menu entries for Windows systems
+    elif sys.platform.startswith(("win", "cygwin")):
+        cleanUpWindowsLinks()
     
     # Remove the wrapper scripts
     rem_wnames = [
@@ -729,6 +732,24 @@
     """
     Clean up the Desktop and Start Menu entries for Windows.
     """
+    regPath = r"Software\Microsoft\Windows\CurrentVersion\Explorer" \
+              r"\User Shell Folders"
+    # 1. cleanup desktop links
+    regName = "Desktop"
+    desktopFolder = os.path.normpath(
+            os.path.expandvars(getWinregEntry(regName, regPath)))
+    for linkName in windowsDesktopNames():
+        linkPath = os.path.join(desktopFolder, linkName)
+        if os.path.exists(linkPath):
+            os.remove(linkPath)
+    
+    # 2. cleanup start menu entry
+    regName = "Programs"
+    programsFolder = os.path.normpath(
+        os.path.expandvars(getWinregEntry(regName, regPath)))
+    eric6EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
+    if os.path.exists(eric6EntryPath):
+        shutil.rmtree(eric6EntryPath)
 
 
 def shutilCopy(src, dst, perm=0o644):
@@ -928,7 +949,7 @@
         createLinuxSpecifics()
     
     # Create Desktop and Start Menu entries for Windows systems
-    if sys.platform.startswith("win"):
+    if sys.platform.startswith(("win", "cygwin")):
         createWindowsLinks()
     
     # Create a Mac application bundle
@@ -1070,6 +1091,8 @@
             " Start Menu entries will not be created."
         )
         return
+    
+    # TODO: create the windows desktop links and start menu entries
 
 
 def createMacAppBundle(pydir):
@@ -1461,7 +1484,7 @@
             exit(1)
     
     # determine the platform dependent black list
-    if sys.platform.startswith("win"):
+    if sys.platform.startswith(("win", "cygwin")):
         PlatformBlackLists = PlatformsBlackLists["windows"]
     elif sys.platform.startswith("linux"):
         PlatformBlackLists = PlatformsBlackLists["linux"]
@@ -1634,6 +1657,56 @@
         shutil.copy(fileName + ".orig", fileName)
 
 
+def getWinregEntry(name, path):
+    """
+    Function to get an entry from the Windows Registry.
+    
+    @param name variable name
+    @type str
+    @param path registry path of the variable
+    @type str
+    @return value of requested registry variable
+    @rtype any
+    """
+    # From http://stackoverflow.com/a/35286642
+    import winreg
+    try:
+        registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0,
+                                     winreg.KEY_READ)
+        value, _ = winreg.QueryValueEx(registryKey, name)
+        winreg.CloseKey(registryKey)
+        return value
+    except WindowsError:
+        return None
+
+
+def windowsDesktopNames():
+    """
+    Function to generate the link names for the Windows Desktop.
+    
+    @return list of desktop link names
+    @rtype list of str
+    """
+    majorVersion, minorVersion = sys.version_info[:2]
+    linkTemplates = [
+        "eric6 (Python {0}.{1}).lnk",
+        "eric6 Browser (Python {0}.{1}).lnk",
+    ]
+    
+    return [l.format(majorVersion, minorVersion) for l in linkTemplates]
+
+
+def windowsProgramsEntry():
+    """
+    Function to generate the name of the Start Menu top entry.
+    
+    @return name of the Start Menu top entry
+    @rtype str
+    """
+    majorVersion, minorVersion = sys.version_info[:2]
+    return "eric6 (Python {0}.{1})".format(majorVersion, minorVersion)
+
+
 def main(argv):
     """
     The main function of the script.
@@ -1662,7 +1735,7 @@
     initGlobals()
 
     try:
-        if sys.platform.startswith("win"):
+        if sys.platform.startswith(("win", "cygwin")):
             optlist, args = getopt.getopt(
                 argv[1:], "chxyza:b:d:f:", ["help", "pyqt=", "noapis"])
         elif sys.platform == "darwin":

eric ide

mercurial