scripts/create_windows_links.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
--- a/scripts/create_windows_links.py	Tue Jul 05 16:34:43 2022 +0200
+++ b/scripts/create_windows_links.py	Thu Jul 07 11:23:56 2022 +0200
@@ -23,35 +23,38 @@
     @param argv list of command line arguments
     @type list of str
     """
-    regPath = (
-        "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" +
-        "\\User Shell Folders"
-    )
-    
-    # 1. create desktop shortcuts
-    regName = "Desktop"
-    desktopFolder = os.path.normpath(
-        os.path.expandvars(getWinregEntry(regName, regPath)))
-    for linkName, targetPath, iconPath in windowsDesktopEntries():
-        linkPath = os.path.join(desktopFolder, linkName)
-        createWindowsShortcut(linkPath, targetPath, iconPath)
-    
-    # 2. create start menu entry and shortcuts
-    regName = "Programs"
-    programsEntry = getWinregEntry(regName, regPath)
-    if programsEntry:
-        programsFolder = os.path.normpath(os.path.expandvars(programsEntry))
-        eric7EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
-        if not os.path.exists(eric7EntryPath):
-            try:
-                os.makedirs(eric7EntryPath)
-            except OSError:
-                # maybe restrictions prohibited link creation
-                return
+    if sys.platform.startswith(("win", "cygwin")):
+        regPath = (
+            "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" +
+            "\\User Shell Folders"
+        )
+        
+        # 1. create desktop shortcuts
+        regName = "Desktop"
+        desktopFolder = os.path.normpath(
+            os.path.expandvars(getWinregEntry(regName, regPath)))
+        for linkName, targetPath, iconPath in windowsDesktopEntries():
+            linkPath = os.path.join(desktopFolder, linkName)
+            createWindowsShortcut(linkPath, targetPath, iconPath)
         
-        for linkName, targetPath, iconPath in windowsDesktopEntries():
-            linkPath = os.path.join(eric7EntryPath, linkName)
-            createWindowsShortcut(linkPath, targetPath, iconPath)
+        # 2. create start menu entry and shortcuts
+        regName = "Programs"
+        programsEntry = getWinregEntry(regName, regPath)
+        if programsEntry:
+            programsFolder = os.path.normpath(os.path.expandvars(programsEntry))
+            eric7EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
+            if not os.path.exists(eric7EntryPath):
+                try:
+                    os.makedirs(eric7EntryPath)
+                except OSError:
+                    # maybe restrictions prohibited link creation
+                    return
+            
+            for linkName, targetPath, iconPath in windowsDesktopEntries():
+                linkPath = os.path.join(eric7EntryPath, linkName)
+                createWindowsShortcut(linkPath, targetPath, iconPath)
+    else:
+        print("This script is to be used on Windows platforms only. Aborting...")
 
 
 def getWinregEntry(name, path):

eric ide

mercurial