install.py

changeset 6510
d8fd663f86ef
parent 6509
884182bfd25c
child 6530
25b9dcfd6fcc
equal deleted inserted replaced
6509:884182bfd25c 6510:d8fd663f86ef
730 730
731 def cleanUpWindowsLinks(): 731 def cleanUpWindowsLinks():
732 """ 732 """
733 Clean up the Desktop and Start Menu entries for Windows. 733 Clean up the Desktop and Start Menu entries for Windows.
734 """ 734 """
735 regPath = r"Software\Microsoft\Windows\CurrentVersion\Explorer" \ 735 try:
736 r"\User Shell Folders" 736 from pywintypes import com_error # __IGNORE_WARNING__
737 except ImportError:
738 # links were not created by install.py
739 return
740
741 regPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" + \
742 "\\User Shell Folders"
743
737 # 1. cleanup desktop links 744 # 1. cleanup desktop links
738 regName = "Desktop" 745 regName = "Desktop"
739 desktopFolder = os.path.normpath( 746 desktopEntry = getWinregEntry(regName, regPath)
740 os.path.expandvars(getWinregEntry(regName, regPath))) 747 if desktopEntry:
741 for linkName in windowsDesktopNames(): 748 desktopFolder = os.path.normpath(os.path.expandvars(desktopEntry))
742 linkPath = os.path.join(desktopFolder, linkName) 749 for linkName in windowsDesktopNames():
743 if os.path.exists(linkPath): 750 linkPath = os.path.join(desktopFolder, linkName)
744 os.remove(linkPath) 751 if os.path.exists(linkPath):
752 try:
753 os.remove(linkPath)
754 except EnvironmentError:
755 # maybe restrictions prohibited link removal
756 print("Could not remove '{0}'.".format(linkPath))
745 757
746 # 2. cleanup start menu entry 758 # 2. cleanup start menu entry
747 regName = "Programs" 759 regName = "Programs"
748 programsFolder = os.path.normpath( 760 programsEntry = getWinregEntry(regName, regPath)
749 os.path.expandvars(getWinregEntry(regName, regPath))) 761 if programsEntry:
750 eric6EntryPath = os.path.join(programsFolder, windowsProgramsEntry()) 762 programsFolder = os.path.normpath(os.path.expandvars(programsEntry))
751 if os.path.exists(eric6EntryPath): 763 eric6EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
752 shutil.rmtree(eric6EntryPath) 764 if os.path.exists(eric6EntryPath):
765 try:
766 shutil.rmtree(eric6EntryPath)
767 except EnvironmentError:
768 # maybe restrictions prohibited link removal
769 print("Could not remove '{0}'.".format(eric6EntryPath))
753 770
754 771
755 def shutilCopy(src, dst, perm=0o644): 772 def shutilCopy(src, dst, perm=0o644):
756 """ 773 """
757 Wrapper function around shutil.copy() to ensure the permissions. 774 Wrapper function around shutil.copy() to ensure the permissions.
947 # Create menu entry for Linux systems 964 # Create menu entry for Linux systems
948 if sys.platform.startswith("linux"): 965 if sys.platform.startswith("linux"):
949 createLinuxSpecifics() 966 createLinuxSpecifics()
950 967
951 # Create Desktop and Start Menu entries for Windows systems 968 # Create Desktop and Start Menu entries for Windows systems
952 if sys.platform.startswith(("win", "cygwin")): 969 elif sys.platform.startswith(("win", "cygwin")):
953 createWindowsLinks() 970 createWindowsLinks()
954 971
955 # Create a Mac application bundle 972 # Create a Mac application bundle
956 if sys.platform == "darwin": 973 elif sys.platform == "darwin":
957 createMacAppBundle(cfg['ericDir']) 974 createMacAppBundle(cfg['ericDir'])
958 975
959 return 0 976 return 0
960 977
961 978
1082 def createWindowsLinks(): 1099 def createWindowsLinks():
1083 """ 1100 """
1084 Create Desktop and Start Menu links. 1101 Create Desktop and Start Menu links.
1085 """ 1102 """
1086 try: 1103 try:
1087 from win32com.client import Dispatch 1104 # check, if pywin32 is available
1105 from win32com.client import Dispatch # __IGNORE_WARNING__
1088 except ImportError: 1106 except ImportError:
1089 print( 1107 print(
1090 "\nThe Python package 'pywin32' is not installed. Desktop and" 1108 "\nThe Python package 'pywin32' is not installed. Desktop and"
1091 " Start Menu entries will not be created." 1109 " Start Menu entries will not be created."
1092 ) 1110 )
1093 return 1111 return
1094 1112
1095 # TODO: create the windows desktop links and start menu entries 1113 regPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" + \
1114 "\\User Shell Folders"
1115
1116 # 1. create desktop shortcuts
1117 regName = "Desktop"
1118 desktopFolder = os.path.normpath(
1119 os.path.expandvars(getWinregEntry(regName, regPath)))
1120 for linkName, targetPath, iconPath in windowsDesktopEntries():
1121 linkPath = os.path.join(desktopFolder, linkName)
1122 createWindowsShortcut(linkPath, targetPath, iconPath)
1123
1124 # 2. create start menu entry and shortcuts
1125 regName = "Programs"
1126 programsEntry = getWinregEntry(regName, regPath)
1127 if programsEntry:
1128 programsFolder = os.path.normpath(os.path.expandvars(programsEntry))
1129 eric6EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
1130 if not os.path.exists(eric6EntryPath):
1131 try:
1132 os.makedirs(eric6EntryPath)
1133 except EnvironmentError:
1134 # maybe restrictions prohibited link creation
1135 return
1136
1137 for linkName, targetPath, iconPath in windowsDesktopEntries():
1138 linkPath = os.path.join(eric6EntryPath, linkName)
1139 createWindowsShortcut(linkPath, targetPath, iconPath)
1096 1140
1097 1141
1098 def createMacAppBundle(pydir): 1142 def createMacAppBundle(pydir):
1099 """ 1143 """
1100 Create a Mac application bundle. 1144 Create a Mac application bundle.
1666 @param path registry path of the variable 1710 @param path registry path of the variable
1667 @type str 1711 @type str
1668 @return value of requested registry variable 1712 @return value of requested registry variable
1669 @rtype any 1713 @rtype any
1670 """ 1714 """
1671 # From http://stackoverflow.com/a/35286642 1715 try:
1672 import winreg 1716 import _winreg as winreg
1717 except ImportError:
1718 try:
1719 import winreg
1720 except ImportError:
1721 return None
1722
1673 try: 1723 try:
1674 registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0, 1724 registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0,
1675 winreg.KEY_READ) 1725 winreg.KEY_READ)
1676 value, _ = winreg.QueryValueEx(registryKey, name) 1726 value, _ = winreg.QueryValueEx(registryKey, name)
1677 winreg.CloseKey(registryKey) 1727 winreg.CloseKey(registryKey)
1678 return value 1728 return value
1679 except WindowsError: 1729 except WindowsError:
1680 return None 1730 return None
1681 1731
1682 1732
1733 def createWindowsShortcut(linkPath, targetPath, iconPath):
1734 """
1735 Create Windows shortcut.
1736
1737 @param linkPath path of the shortcut file
1738 @type str
1739 @param targetPath path the shortcut shall point to
1740 @type str
1741 @param iconPath path of the icon file
1742 @type str
1743 """
1744 from win32com.client import Dispatch
1745 from pywintypes import com_error
1746
1747 try:
1748 shell = Dispatch('WScript.Shell')
1749 shortcut = shell.CreateShortCut(linkPath)
1750 shortcut.Targetpath = targetPath
1751 shortcut.WorkingDirectory = os.path.dirname(targetPath)
1752 shortcut.IconLocation = iconPath
1753 shortcut.save()
1754 except com_error:
1755 # maybe restrictions prohibited link creation
1756 pass
1757
1758
1683 def windowsDesktopNames(): 1759 def windowsDesktopNames():
1684 """ 1760 """
1685 Function to generate the link names for the Windows Desktop. 1761 Function to generate the link names for the Windows Desktop.
1686 1762
1687 @return list of desktop link names 1763 @return list of desktop link names
1688 @rtype list of str 1764 @rtype list of str
1689 """ 1765 """
1766 return [e[0] for e in windowsDesktopEntries()]
1767
1768
1769 def windowsDesktopEntries():
1770 """
1771 Function to generate data for the Windows Desktop links.
1772
1773 @return list of tuples containing the desktop link name,
1774 the link target and the icon target
1775 @rtype list of tuples of (str, str, str)
1776 """
1777 global cfg, includePythonVariant
1778
1779 if includePythonVariant:
1780 marker = PythonMarkers[sys.version_info.major]
1781 else:
1782 marker = ""
1783
1690 majorVersion, minorVersion = sys.version_info[:2] 1784 majorVersion, minorVersion = sys.version_info[:2]
1691 linkTemplates = [ 1785 entriesTemplates = [
1692 "eric6 (Python {0}.{1}).lnk", 1786 ("eric6 (Python {0}.{1}).lnk",
1693 "eric6 Browser (Python {0}.{1}).lnk", 1787 os.path.join(cfg["bindir"], "eric6" + marker + ".cmd"),
1788 os.path.join(cfg["ericPixDir"], "eric6.ico")),
1694 ] 1789 ]
1695 1790 if sys.version_info.major == 2:
1696 return [l.format(majorVersion, minorVersion) for l in linkTemplates] 1791 entriesTemplates.append((
1792 "eric6 Browser (Python {0}.{1}).lnk",
1793 os.path.join(cfg["bindir"], "eric6_webbrowser" + marker + ".cmd"),
1794 os.path.join(cfg["ericPixDir"], "ericWeb48.ico")
1795 ))
1796 else:
1797 entriesTemplates.append((
1798 "eric6 Browser (Python {0}.{1}).lnk",
1799 os.path.join(cfg["bindir"], "eric6_browser" + marker + ".cmd"),
1800 os.path.join(cfg["ericPixDir"], "ericWeb48.ico")
1801 ))
1802
1803 return [
1804 (e[0].format(majorVersion, minorVersion), e[1], e[2])
1805 for e in entriesTemplates
1806 ]
1697 1807
1698 1808
1699 def windowsProgramsEntry(): 1809 def windowsProgramsEntry():
1700 """ 1810 """
1701 Function to generate the name of the Start Menu top entry. 1811 Function to generate the name of the Start Menu top entry.

eric ide

mercurial