install.py

changeset 6509
884182bfd25c
parent 6500
0373580fc86c
child 6510
d8fd663f86ef
equal deleted inserted replaced
6508:51897256fc83 6509:884182bfd25c
113 """ 113 """
114 global currDir 114 global currDir
115 115
116 print() 116 print()
117 117
118 if sys.platform.startswith("win"): 118 if sys.platform.startswith(("win", "cygwin")):
119 # different meaning of input between Py2 and Py3 119 # different meaning of input between Py2 and Py3
120 try: 120 try:
121 input("Press enter to continue...") 121 input("Press enter to continue...")
122 except (EOFError, SyntaxError): 122 except (EOFError, SyntaxError):
123 pass 123 pass
140 print() 140 print()
141 print("Usage:") 141 print("Usage:")
142 if sys.platform == "darwin": 142 if sys.platform == "darwin":
143 print(" {0} [-chxyz] [-a dir] [-b dir] [-d dir] [-f file] [-i dir]" 143 print(" {0} [-chxyz] [-a dir] [-b dir] [-d dir] [-f file] [-i dir]"
144 " [-m name] [-p python] [--pyqt=version]".format(progName)) 144 " [-m name] [-p python] [--pyqt=version]".format(progName))
145 elif sys.platform.startswith("win"): 145 elif sys.platform.startswith(("win", "cygwin")):
146 print(" {0} [-chxyz] [-a dir] [-b dir] [-d dir] [-f file]" 146 print(" {0} [-chxyz] [-a dir] [-b dir] [-d dir] [-f file]"
147 " [--pyqt=version]" 147 " [--pyqt=version]"
148 .format(progName)) 148 .format(progName))
149 else: 149 else:
150 print(" {0} [-chxyz] [-a dir] [-b dir] [-d dir] [-f file] [-i dir]" 150 print(" {0} [-chxyz] [-a dir] [-b dir] [-d dir] [-f file] [-i dir]"
162 print(" (default: {0})".format(platBinDir)) 162 print(" (default: {0})".format(platBinDir))
163 print(" -d dir where eric6 python files will be installed") 163 print(" -d dir where eric6 python files will be installed")
164 print(" (default: {0})".format(modDir)) 164 print(" (default: {0})".format(modDir))
165 print(" -f file configuration file naming the various installation" 165 print(" -f file configuration file naming the various installation"
166 " paths") 166 " paths")
167 if not sys.platform.startswith("win"): 167 if not sys.platform.startswith(("win", "cygwin")):
168 print(" -i dir temporary install prefix") 168 print(" -i dir temporary install prefix")
169 print(" (default: {0})".format(distDir)) 169 print(" (default: {0})".format(distDir))
170 if sys.platform == "darwin": 170 if sys.platform == "darwin":
171 print(" -m name name of the Mac app bundle") 171 print(" -m name name of the Mac app bundle")
172 print(" (default: {0})".format(macAppBundleName)) 172 print(" (default: {0})".format(macAppBundleName))
240 import distutils.sysconfig 240 import distutils.sysconfig
241 except ImportError: 241 except ImportError:
242 print("Please install the 'distutils' package first.") 242 print("Please install the 'distutils' package first.")
243 exit(5) 243 exit(5)
244 244
245 if sys.platform.startswith("win"): 245 if sys.platform.startswith(("win", "cygwin")):
246 platBinDir = sys.exec_prefix 246 platBinDir = sys.exec_prefix
247 if platBinDir.endswith("\\"): 247 if platBinDir.endswith("\\"):
248 platBinDir = platBinDir[:-1] 248 platBinDir = platBinDir[:-1]
249 platBinDirOld = platBinDir 249 platBinDirOld = platBinDir
250 platBinDir = os.path.join(platBinDir, "Scripts") 250 platBinDir = os.path.join(platBinDir, "Scripts")
379 379
380 @param dname name of the directory to place the wrapper into 380 @param dname name of the directory to place the wrapper into
381 @param wfile basename (without extension) of the wrapper script 381 @param wfile basename (without extension) of the wrapper script
382 @return the names of the wrapper scripts 382 @return the names of the wrapper scripts
383 """ 383 """
384 if sys.platform.startswith("win"): 384 if sys.platform.startswith(("win", "cygwin")):
385 wnames = (dname + "\\" + wfile + ".cmd", 385 wnames = (dname + "\\" + wfile + ".cmd",
386 dname + "\\" + wfile + ".bat") 386 dname + "\\" + wfile + ".bat")
387 else: 387 else:
388 wnames = (dname + "/" + wfile, ) 388 wnames = (dname + "/" + wfile, )
389 389
412 pyqt4opt = " --pyqt4" 412 pyqt4opt = " --pyqt4"
413 else: 413 else:
414 pyqt4opt = "" 414 pyqt4opt = ""
415 415
416 # all kinds of Windows systems 416 # all kinds of Windows systems
417 if sys.platform.startswith("win"): 417 if sys.platform.startswith(("win", "cygwin")):
418 wname = wfile + marker + ".cmd" 418 wname = wfile + marker + ".cmd"
419 if isGuiScript: 419 if isGuiScript:
420 wrapper = \ 420 wrapper = \
421 '''@echo off\n''' \ 421 '''@echo off\n''' \
422 '''start "" "{2}\\pythonw.exe"''' \ 422 '''start "" "{2}\\pythonw.exe"''' \
572 global pyModDir, progLanguages 572 global pyModDir, progLanguages
573 573
574 # Remove the menu entry for Linux systems 574 # Remove the menu entry for Linux systems
575 if sys.platform.startswith("linux"): 575 if sys.platform.startswith("linux"):
576 cleanUpLinuxSpecifics() 576 cleanUpLinuxSpecifics()
577 # Remove the Desktop and Start Menu entries for Windows systems
578 elif sys.platform.startswith(("win", "cygwin")):
579 cleanUpWindowsLinks()
577 580
578 # Remove the wrapper scripts 581 # Remove the wrapper scripts
579 rem_wnames = [ 582 rem_wnames = [
580 "eric6_api", "eric6_compare", 583 "eric6_api", "eric6_compare",
581 "eric6_configure", "eric6_diff", 584 "eric6_configure", "eric6_diff",
727 730
728 def cleanUpWindowsLinks(): 731 def cleanUpWindowsLinks():
729 """ 732 """
730 Clean up the Desktop and Start Menu entries for Windows. 733 Clean up the Desktop and Start Menu entries for Windows.
731 """ 734 """
735 regPath = r"Software\Microsoft\Windows\CurrentVersion\Explorer" \
736 r"\User Shell Folders"
737 # 1. cleanup desktop links
738 regName = "Desktop"
739 desktopFolder = os.path.normpath(
740 os.path.expandvars(getWinregEntry(regName, regPath)))
741 for linkName in windowsDesktopNames():
742 linkPath = os.path.join(desktopFolder, linkName)
743 if os.path.exists(linkPath):
744 os.remove(linkPath)
745
746 # 2. cleanup start menu entry
747 regName = "Programs"
748 programsFolder = os.path.normpath(
749 os.path.expandvars(getWinregEntry(regName, regPath)))
750 eric6EntryPath = os.path.join(programsFolder, windowsProgramsEntry())
751 if os.path.exists(eric6EntryPath):
752 shutil.rmtree(eric6EntryPath)
732 753
733 754
734 def shutilCopy(src, dst, perm=0o644): 755 def shutilCopy(src, dst, perm=0o644):
735 """ 756 """
736 Wrapper function around shutil.copy() to ensure the permissions. 757 Wrapper function around shutil.copy() to ensure the permissions.
926 # Create menu entry for Linux systems 947 # Create menu entry for Linux systems
927 if sys.platform.startswith("linux"): 948 if sys.platform.startswith("linux"):
928 createLinuxSpecifics() 949 createLinuxSpecifics()
929 950
930 # Create Desktop and Start Menu entries for Windows systems 951 # Create Desktop and Start Menu entries for Windows systems
931 if sys.platform.startswith("win"): 952 if sys.platform.startswith(("win", "cygwin")):
932 createWindowsLinks() 953 createWindowsLinks()
933 954
934 # Create a Mac application bundle 955 # Create a Mac application bundle
935 if sys.platform == "darwin": 956 if sys.platform == "darwin":
936 createMacAppBundle(cfg['ericDir']) 957 createMacAppBundle(cfg['ericDir'])
1068 print( 1089 print(
1069 "\nThe Python package 'pywin32' is not installed. Desktop and" 1090 "\nThe Python package 'pywin32' is not installed. Desktop and"
1070 " Start Menu entries will not be created." 1091 " Start Menu entries will not be created."
1071 ) 1092 )
1072 return 1093 return
1094
1095 # TODO: create the windows desktop links and start menu entries
1073 1096
1074 1097
1075 def createMacAppBundle(pydir): 1098 def createMacAppBundle(pydir):
1076 """ 1099 """
1077 Create a Mac application bundle. 1100 Create a Mac application bundle.
1459 .format(" or ".join(altModules))) 1482 .format(" or ".join(altModules)))
1460 if not altModulesOK: 1483 if not altModulesOK:
1461 exit(1) 1484 exit(1)
1462 1485
1463 # determine the platform dependent black list 1486 # determine the platform dependent black list
1464 if sys.platform.startswith("win"): 1487 if sys.platform.startswith(("win", "cygwin")):
1465 PlatformBlackLists = PlatformsBlackLists["windows"] 1488 PlatformBlackLists = PlatformsBlackLists["windows"]
1466 elif sys.platform.startswith("linux"): 1489 elif sys.platform.startswith("linux"):
1467 PlatformBlackLists = PlatformsBlackLists["linux"] 1490 PlatformBlackLists = PlatformsBlackLists["linux"]
1468 else: 1491 else:
1469 PlatformBlackLists = PlatformsBlackLists["mac"] 1492 PlatformBlackLists = PlatformsBlackLists["mac"]
1632 copyToFile(fileName, text) 1655 copyToFile(fileName, text)
1633 else: 1656 else:
1634 shutil.copy(fileName + ".orig", fileName) 1657 shutil.copy(fileName + ".orig", fileName)
1635 1658
1636 1659
1660 def getWinregEntry(name, path):
1661 """
1662 Function to get an entry from the Windows Registry.
1663
1664 @param name variable name
1665 @type str
1666 @param path registry path of the variable
1667 @type str
1668 @return value of requested registry variable
1669 @rtype any
1670 """
1671 # From http://stackoverflow.com/a/35286642
1672 import winreg
1673 try:
1674 registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0,
1675 winreg.KEY_READ)
1676 value, _ = winreg.QueryValueEx(registryKey, name)
1677 winreg.CloseKey(registryKey)
1678 return value
1679 except WindowsError:
1680 return None
1681
1682
1683 def windowsDesktopNames():
1684 """
1685 Function to generate the link names for the Windows Desktop.
1686
1687 @return list of desktop link names
1688 @rtype list of str
1689 """
1690 majorVersion, minorVersion = sys.version_info[:2]
1691 linkTemplates = [
1692 "eric6 (Python {0}.{1}).lnk",
1693 "eric6 Browser (Python {0}.{1}).lnk",
1694 ]
1695
1696 return [l.format(majorVersion, minorVersion) for l in linkTemplates]
1697
1698
1699 def windowsProgramsEntry():
1700 """
1701 Function to generate the name of the Start Menu top entry.
1702
1703 @return name of the Start Menu top entry
1704 @rtype str
1705 """
1706 majorVersion, minorVersion = sys.version_info[:2]
1707 return "eric6 (Python {0}.{1})".format(majorVersion, minorVersion)
1708
1709
1637 def main(argv): 1710 def main(argv):
1638 """ 1711 """
1639 The main function of the script. 1712 The main function of the script.
1640 1713
1641 @param argv the list of command line arguments. 1714 @param argv the list of command line arguments.
1660 1733
1661 determinePyQtVariant() 1734 determinePyQtVariant()
1662 initGlobals() 1735 initGlobals()
1663 1736
1664 try: 1737 try:
1665 if sys.platform.startswith("win"): 1738 if sys.platform.startswith(("win", "cygwin")):
1666 optlist, args = getopt.getopt( 1739 optlist, args = getopt.getopt(
1667 argv[1:], "chxyza:b:d:f:", ["help", "pyqt=", "noapis"]) 1740 argv[1:], "chxyza:b:d:f:", ["help", "pyqt=", "noapis"])
1668 elif sys.platform == "darwin": 1741 elif sys.platform == "darwin":
1669 optlist, args = getopt.getopt( 1742 optlist, args = getopt.getopt(
1670 argv[1:], "chxyza:b:d:f:i:m:n:p:", ["help", "pyqt=", "noapis"]) 1743 argv[1:], "chxyza:b:d:f:i:m:n:p:", ["help", "pyqt=", "noapis"])

eric ide

mercurial