Sat, 17 Nov 2018 19:36:46 +0100
install: second attempt to cope with tricks done by pywin32 at interpreter startup.
create_windows_links.py | file | annotate | diff | comparison | revisions | |
eric6.e4p | file | annotate | diff | comparison | revisions | |
install.py | file | annotate | diff | comparison | revisions |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/create_windows_links.py Sat Nov 17 19:36:46 2018 +0100 @@ -0,0 +1,199 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de> +# +# This is the install script for eric6. + +""" +Installation script for the eric6 IDE and all eric6 related tools. +""" + +from __future__ import unicode_literals, print_function + +import os +import sys + +from eric6config import getConfig + +# Define file name markers for Python variants +PythonMarkers = { + 2: "_py2", + 3: "_py3", +} + +includePythonVariant = False + + +def main(argv): + """ + Create Desktop and Start Menu links. + + @param argv list of command line arguments + @type list of str + """ + global includePythonVariant + + if "-y" in argv: + includePythonVariant = True + + 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)) + eric6EntryPath = os.path.join(programsFolder, windowsProgramsEntry()) + if not os.path.exists(eric6EntryPath): + try: + os.makedirs(eric6EntryPath) + except EnvironmentError: + # maybe restrictions prohibited link creation + return + + for linkName, targetPath, iconPath in windowsDesktopEntries(): + linkPath = os.path.join(eric6EntryPath, linkName) + createWindowsShortcut(linkPath, targetPath, iconPath) + + +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 + @type str + @return value of requested registry variable + @rtype any + """ + try: + import _winreg as winreg + except ImportError: + try: + import winreg + except ImportError: + return None + + try: + registryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0, + winreg.KEY_READ) + value, _ = winreg.QueryValueEx(registryKey, name) + winreg.CloseKey(registryKey) + return value + except WindowsError: + return None + + +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 + @type str + @param iconPath path of the icon file + @type str + """ + from win32com.client import Dispatch + from pywintypes import com_error + + try: + shell = Dispatch('WScript.Shell') + shortcut = shell.CreateShortCut(linkPath) + shortcut.Targetpath = targetPath + shortcut.WorkingDirectory = os.path.dirname(targetPath) + shortcut.IconLocation = iconPath + shortcut.save() + except com_error: + # maybe restrictions prohibited link creation + pass + + +def windowsDesktopNames(): + """ + Function to generate the link names for the Windows Desktop. + + @return list of desktop link names + @rtype list of str + """ + return [e[0] for e in windowsDesktopEntries()] + + +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) + """ + global includePythonVariant + + if includePythonVariant: + marker = PythonMarkers[sys.version_info.major] + else: + marker = "" + + majorVersion, minorVersion = sys.version_info[:2] + entriesTemplates = [ + ("eric6 (Python {0}.{1}).lnk", + os.path.join(getConfig("bindir"), "eric6" + marker + ".cmd"), + os.path.join(getConfig("ericPixDir"), "eric6.ico")), + ] + if sys.version_info.major == 2: + entriesTemplates.append(( + "eric6 Browser (Python {0}.{1}).lnk", + os.path.join(getConfig("bindir"), + "eric6_webbrowser" + marker + ".cmd"), + os.path.join(getConfig("ericPixDir"), "ericWeb48.ico") + )) + else: + entriesTemplates.append(( + "eric6 Browser (Python {0}.{1}).lnk", + os.path.join(getConfig("bindir"), + "eric6_browser" + marker + ".cmd"), + os.path.join(getConfig("ericPixDir"), "ericWeb48.ico") + )) + + return [ + (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 "eric6 (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""") + raise + +# +# eflag: noqa = M801
--- a/eric6.e4p Sat Nov 17 18:12:20 2018 +0100 +++ b/eric6.e4p Sat Nov 17 19:36:46 2018 +0100 @@ -1643,6 +1643,7 @@ <Source>__init__.py</Source> <Source>cleanupSource.py</Source> <Source>compileUiFiles.py</Source> + <Source>create_windows_links.py</Source> <Source>eric6.py</Source> <Source>eric6.pyw</Source> <Source>eric6_api.py</Source> @@ -2224,14 +2225,14 @@ </Resources> <Others> <Other>.hgignore</Other> + <Other>APIs/Python/zope-2.10.7.api</Other> + <Other>APIs/Python/zope-2.11.2.api</Other> + <Other>APIs/Python/zope-3.3.1.api</Other> <Other>APIs/Python3/PyQt4.bas</Other> <Other>APIs/Python3/PyQt5.bas</Other> <Other>APIs/Python3/QScintilla2.bas</Other> <Other>APIs/Python3/eric6.api</Other> <Other>APIs/Python3/eric6.bas</Other> - <Other>APIs/Python/zope-2.10.7.api</Other> - <Other>APIs/Python/zope-2.11.2.api</Other> - <Other>APIs/Python/zope-3.3.1.api</Other> <Other>APIs/QSS/qss.api</Other> <Other>APIs/Ruby/Ruby-1.8.7.api</Other> <Other>APIs/Ruby/Ruby-1.8.7.bas</Other>
--- a/install.py Sat Nov 17 18:12:20 2018 +0100 +++ b/install.py Sat Nov 17 19:36:46 2018 +0100 @@ -1108,17 +1108,23 @@ "pywin32", "\nThe Python package 'pywin32' could not be imported." ) - if not installed: + if installed: + # create the links via an external script to get around some + # startup magic done by pywin32.pth + args = [ + sys.executable, + os.path.join(os.path.dirname(__file__), + "create_windows_links.py"), + ] + if includePythonVariant: + args.append("-y") + subprocess.call(args) + else: print( "\nThe Python package 'pywin32' is not installed. Desktop and" " Start Menu entries will not be created." ) - return - - import site - knownPaths = site.removeduppaths() - knownPaths = site.addusersitepackages(knownPaths) - knownPaths = site.addsitepackages(knownPaths) + return regPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" + \ "\\User Shell Folders" @@ -1831,7 +1837,8 @@ """ The main function of the script. - @param argv the list of command line arguments. + @param argv list of command line arguments + @type list of str """ import getopt