scripts/create_windows_links.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9406
e6db5614b97e
--- a/scripts/create_windows_links.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/scripts/create_windows_links.py	Wed Jul 13 14:55:47 2022 +0200
@@ -19,24 +19,25 @@
 def main(argv):
     """
     Create Desktop and Start Menu links.
-    
+
     @param argv list of command line arguments
     @type list of str
     """
     if sys.platform.startswith(("win", "cygwin")):
         regPath = (
-            "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" +
-            "\\User Shell Folders"
+            "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"
+            + "\\User Shell Folders"
         )
-        
+
         # 1. create desktop shortcuts
         regName = "Desktop"
         desktopFolder = os.path.normpath(
-            os.path.expandvars(getWinregEntry(regName, regPath)))
+            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)
@@ -49,7 +50,7 @@
                 except OSError:
                     # maybe restrictions prohibited link creation
                     return
-            
+
             for linkName, targetPath, iconPath in windowsDesktopEntries():
                 linkPath = os.path.join(eric7EntryPath, linkName)
                 createWindowsShortcut(linkPath, targetPath, iconPath)
@@ -60,7 +61,7 @@
 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
@@ -72,10 +73,9 @@
         import winreg
     except ImportError:
         return None
-    
+
     try:
-        registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0,
-                                     winreg.KEY_READ)
+        registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0, winreg.KEY_READ)
         value, _ = winreg.QueryValueEx(registryKey, name)
         winreg.CloseKey(registryKey)
         return value
@@ -86,7 +86,7 @@
 def createWindowsShortcut(linkPath, targetPath, iconPath):
     """
     Create Windows shortcut.
-    
+
     @param linkPath path of the shortcut file
     @type str
     @param targetPath path the shortcut shall point to
@@ -96,9 +96,9 @@
     """
     from win32com.client import Dispatch
     from pywintypes import com_error
-    
+
     with contextlib.suppress(com_error):
-        shell = Dispatch('WScript.Shell')
+        shell = Dispatch("WScript.Shell")
         shortcut = shell.CreateShortCut(linkPath)
         shortcut.Targetpath = targetPath
         shortcut.WorkingDirectory = os.path.dirname(targetPath)
@@ -109,7 +109,7 @@
 def windowsDesktopNames():
     """
     Function to generate the link names for the Windows Desktop.
-    
+
     @return list of desktop link names
     @rtype list of str
     """
@@ -119,47 +119,52 @@
 def windowsDesktopEntries():
     """
     Function to generate data for the Windows Desktop links.
-    
+
     @return list of tuples containing the desktop link name,
         the link target and the icon target
     @rtype list of tuples of (str, str, str)
     """
     majorVersion, minorVersion = sys.version_info[:2]
     entriesTemplates = [
-        ("eric7 (Python {0}.{1}).lnk",
-         os.path.join(getConfig("bindir"), "eric7.cmd"),
-         os.path.join(getConfig("ericPixDir"), "eric7.ico")),
-        ("eric7 Browser (Python {0}.{1}).lnk",
-         os.path.join(getConfig("bindir"), "eric7_browser.cmd"),
-         os.path.join(getConfig("ericPixDir"), "ericWeb48.ico")),
+        (
+            "eric7 (Python {0}.{1}).lnk",
+            os.path.join(getConfig("bindir"), "eric7.cmd"),
+            os.path.join(getConfig("ericPixDir"), "eric7.ico"),
+        ),
+        (
+            "eric7 Browser (Python {0}.{1}).lnk",
+            os.path.join(getConfig("bindir"), "eric7_browser.cmd"),
+            os.path.join(getConfig("ericPixDir"), "ericWeb48.ico"),
+        ),
     ]
-    
+
     return [
-        (e[0].format(majorVersion, minorVersion), e[1], e[2])
-        for e in entriesTemplates
+        (e[0].format(majorVersion, minorVersion), e[1], e[2]) for e in entriesTemplates
     ]
 
 
 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 "eric7 (Python {0}.{1})".format(majorVersion, minorVersion)
-    
-    
+
+
 if __name__ == "__main__":
     try:
         main(sys.argv)
     except SystemExit:
         raise
     except Exception:
-        print("""An internal error occured.  Please report all the output"""
-              """ of the program,\nincluding the following traceback, to"""
-              """ eric-bugs@eric-ide.python-projects.org.\n""")
+        print(
+            """An internal error occured.  Please report all the output"""
+            """ of the program,\nincluding the following traceback, to"""
+            """ eric-bugs@eric-ide.python-projects.org.\n"""
+        )
         raise
 
 #

eric ide

mercurial