scripts/create_windows_links.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
21 Create Desktop and Start Menu links. 21 Create Desktop and Start Menu links.
22 22
23 @param argv list of command line arguments 23 @param argv list of command line arguments
24 @type list of str 24 @type list of str
25 """ 25 """
26 regPath = ( 26 if sys.platform.startswith(("win", "cygwin")):
27 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" + 27 regPath = (
28 "\\User Shell Folders" 28 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" +
29 ) 29 "\\User Shell Folders"
30 30 )
31 # 1. create desktop shortcuts
32 regName = "Desktop"
33 desktopFolder = os.path.normpath(
34 os.path.expandvars(getWinregEntry(regName, regPath)))
35 for linkName, targetPath, iconPath in windowsDesktopEntries():
36 linkPath = os.path.join(desktopFolder, linkName)
37 createWindowsShortcut(linkPath, targetPath, iconPath)
38
39 # 2. create start menu entry and shortcuts
40 regName = "Programs"
41 programsEntry = getWinregEntry(regName, regPath)
42 if programsEntry:
43 programsFolder = os.path.normpath(os.path.expandvars(programsEntry))
44 eric7EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
45 if not os.path.exists(eric7EntryPath):
46 try:
47 os.makedirs(eric7EntryPath)
48 except OSError:
49 # maybe restrictions prohibited link creation
50 return
51 31
32 # 1. create desktop shortcuts
33 regName = "Desktop"
34 desktopFolder = os.path.normpath(
35 os.path.expandvars(getWinregEntry(regName, regPath)))
52 for linkName, targetPath, iconPath in windowsDesktopEntries(): 36 for linkName, targetPath, iconPath in windowsDesktopEntries():
53 linkPath = os.path.join(eric7EntryPath, linkName) 37 linkPath = os.path.join(desktopFolder, linkName)
54 createWindowsShortcut(linkPath, targetPath, iconPath) 38 createWindowsShortcut(linkPath, targetPath, iconPath)
39
40 # 2. create start menu entry and shortcuts
41 regName = "Programs"
42 programsEntry = getWinregEntry(regName, regPath)
43 if programsEntry:
44 programsFolder = os.path.normpath(os.path.expandvars(programsEntry))
45 eric7EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
46 if not os.path.exists(eric7EntryPath):
47 try:
48 os.makedirs(eric7EntryPath)
49 except OSError:
50 # maybe restrictions prohibited link creation
51 return
52
53 for linkName, targetPath, iconPath in windowsDesktopEntries():
54 linkPath = os.path.join(eric7EntryPath, linkName)
55 createWindowsShortcut(linkPath, targetPath, iconPath)
56 else:
57 print("This script is to be used on Windows platforms only. Aborting...")
55 58
56 59
57 def getWinregEntry(name, path): 60 def getWinregEntry(name, path):
58 """ 61 """
59 Function to get an entry from the Windows Registry. 62 Function to get an entry from the Windows Registry.

eric ide

mercurial