~ubuntu-branches/debian/experimental/spyder/experimental

« back to all changes in this revision

Viewing changes to scripts/spyder_win_post_install.py

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2014-05-29 09:06:26 UTC
  • mfrom: (1.1.21) (18.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140529090626-f58t82g0n5iewaxu
Tags: 2.3.0~rc+dfsg-1~experimental2
* Add spyder-common binary package for all the python2,3 common files
* debian/path
  - 0001-fix-documentation-installation.patch (deleted)
  + 0001-fix-spyderlib-path.patch (new)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# postinstall script for Spyder
2
 
"""Create Spyder start menu entries"""
3
 
 
4
 
import os
5
 
import sys
6
 
import os.path as osp
7
 
import struct
8
 
import _winreg as winreg
9
 
 
10
 
EWS = "Edit with Spyder"
11
 
KEY_C = r"Software\Classes\%s"
12
 
KEY_C0 = KEY_C % r"Python.%sFile\shell\%s"
13
 
KEY_C1 = KEY_C0 + r"\command"
14
 
 
15
 
def install():
16
 
    """Function executed when running the script with the -install switch"""
17
 
    # Create Spyder start menu folder
18
 
    start_menu = osp.join(get_special_folder_path('CSIDL_COMMON_PROGRAMS'),
19
 
                          'Spyder (Py%i.%i %i bit)' % (sys.version_info[0],
20
 
                                                       sys.version_info[1],
21
 
                                                       struct.calcsize('P')*8))
22
 
    if not osp.isdir(start_menu):
23
 
        os.mkdir(start_menu)
24
 
        directory_created(start_menu)
25
 
    
26
 
    # Create Spyder start menu entries
27
 
    python = osp.abspath(osp.join(sys.prefix, 'python.exe'))
28
 
    pythonw = osp.abspath(osp.join(sys.prefix, 'pythonw.exe'))
29
 
    script = osp.abspath(osp.join(sys.prefix, 'scripts', 'spyder'))
30
 
    workdir = "%HOMEDRIVE%%HOMEPATH%"
31
 
    import distutils.sysconfig
32
 
    lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1)
33
 
    ico_dir = osp.join(lib_dir, 'spyderlib', 'windows')
34
 
 
35
 
    desc = 'Scientific Python Development EnvironmEnt, an alternative to IDLE'
36
 
    fname = osp.join(start_menu, 'Spyder (full).lnk')
37
 
    create_shortcut(python, desc, fname, '"%s"' % script, workdir,
38
 
                    osp.join(ico_dir, 'spyder.ico'))
39
 
    file_created(fname)
40
 
 
41
 
    desc += '. Light configuration: console and variable explorer only.'
42
 
    fname = osp.join(start_menu, 'Spyder (light).lnk')
43
 
    create_shortcut(python, desc, fname,
44
 
                    '"%s" --light' % script, workdir,
45
 
                    osp.join(ico_dir, 'spyder_light.ico'))
46
 
    file_created(fname)
47
 
 
48
 
    fname = osp.join(start_menu, 'Spyder-Reset all settings.lnk')
49
 
    create_shortcut(python, 'Reset Spyder settings to defaults',
50
 
                    fname, '"%s" --reset' % script, workdir)
51
 
    file_created(fname)
52
 
 
53
 
    current = True  # only affects current user
54
 
    root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
55
 
    winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("", EWS)),
56
 
                      "", 0, winreg.REG_SZ,
57
 
                      '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix))
58
 
    winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("NoCon", EWS)),
59
 
                      "", 0, winreg.REG_SZ,
60
 
                      '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix))
61
 
 
62
 
 
63
 
def remove():
64
 
    """Function executed when running the script with the -install switch"""
65
 
    current = True  # only affects current user
66
 
    root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
67
 
    for key in (KEY_C1 % ("", EWS), KEY_C1 % ("NoCon", EWS),
68
 
                KEY_C0 % ("", EWS), KEY_C0 % ("NoCon", EWS)):
69
 
        try:
70
 
            winreg.DeleteKey(root, key)
71
 
        except WindowsError:
72
 
            pass
73
 
 
74
 
 
75
 
if __name__=='__main__':
76
 
    if len(sys.argv) > 1:
77
 
        if sys.argv[1] == '-install':
78
 
            try:
79
 
                install()
80
 
            except OSError:
81
 
                print >>sys.stderr, "Failed to create Start Menu items, "\
82
 
                                    "try running installer as administrator."
83
 
        elif sys.argv[1] == '-remove':
84
 
            remove()
85
 
        else:
86
 
            print >>sys.stderr, "Unknown command line option %s" % sys.argv[1]
 
1
# postinstall script for Spyder
 
2
"""Create Spyder start menu entries"""
 
3
 
 
4
from __future__ import print_function
 
5
 
 
6
import os
 
7
import sys
 
8
import os.path as osp
 
9
import struct
 
10
try:
 
11
    # Python 2
 
12
    import _winreg as winreg
 
13
except ImportError:
 
14
    # Python 3
 
15
    import winreg
 
16
 
 
17
 
 
18
EWS = "Edit with Spyder"
 
19
KEY_C = r"Software\Classes\%s"
 
20
KEY_C0 = KEY_C % r"Python.%sFile\shell\%s"
 
21
KEY_C1 = KEY_C0 + r"\command"
 
22
 
 
23
def install():
 
24
    """Function executed when running the script with the -install switch"""
 
25
    # Create Spyder start menu folder
 
26
    start_menu = osp.join(get_special_folder_path('CSIDL_COMMON_PROGRAMS'),
 
27
                          'Spyder (Py%i.%i %i bit)' % (sys.version_info[0],
 
28
                                                       sys.version_info[1],
 
29
                                                       struct.calcsize('P')*8))
 
30
    if not osp.isdir(start_menu):
 
31
        os.mkdir(start_menu)
 
32
        directory_created(start_menu)
 
33
    
 
34
    # Create Spyder start menu entries
 
35
    python = osp.abspath(osp.join(sys.prefix, 'python.exe'))
 
36
    pythonw = osp.abspath(osp.join(sys.prefix, 'pythonw.exe'))
 
37
    script = osp.abspath(osp.join(sys.prefix, 'scripts', 'spyder'))
 
38
    workdir = "%HOMEDRIVE%%HOMEPATH%"
 
39
    import distutils.sysconfig
 
40
    lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1)
 
41
    ico_dir = osp.join(lib_dir, 'spyderlib', 'windows')
 
42
 
 
43
    desc = 'Scientific Python Development EnvironmEnt, an alternative to IDLE'
 
44
    fname = osp.join(start_menu, 'Spyder (full).lnk')
 
45
    create_shortcut(python, desc, fname, '"%s"' % script, workdir,
 
46
                    osp.join(ico_dir, 'spyder.ico'))
 
47
    file_created(fname)
 
48
 
 
49
    desc += '. Light configuration: console and variable explorer only.'
 
50
    fname = osp.join(start_menu, 'Spyder (light).lnk')
 
51
    create_shortcut(python, desc, fname,
 
52
                    '"%s" --light' % script, workdir,
 
53
                    osp.join(ico_dir, 'spyder_light.ico'))
 
54
    file_created(fname)
 
55
 
 
56
    fname = osp.join(start_menu, 'Spyder-Reset all settings.lnk')
 
57
    create_shortcut(python, 'Reset Spyder settings to defaults',
 
58
                    fname, '"%s" --reset' % script, workdir)
 
59
    file_created(fname)
 
60
 
 
61
    current = True  # only affects current user
 
62
    root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
 
63
    winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("", EWS)),
 
64
                      "", 0, winreg.REG_SZ,
 
65
                      '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix))
 
66
    winreg.SetValueEx(winreg.CreateKey(root, KEY_C1 % ("NoCon", EWS)),
 
67
                      "", 0, winreg.REG_SZ,
 
68
                      '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw, sys.prefix))
 
69
 
 
70
 
 
71
def remove():
 
72
    """Function executed when running the script with the -install switch"""
 
73
    current = True  # only affects current user
 
74
    root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE
 
75
    for key in (KEY_C1 % ("", EWS), KEY_C1 % ("NoCon", EWS),
 
76
                KEY_C0 % ("", EWS), KEY_C0 % ("NoCon", EWS)):
 
77
        try:
 
78
            winreg.DeleteKey(root, key)
 
79
        except WindowsError:
 
80
            pass
 
81
 
 
82
 
 
83
if __name__=='__main__':
 
84
    if len(sys.argv) > 1:
 
85
        if sys.argv[1] == '-install':
 
86
            try:
 
87
                install()
 
88
            except OSError:
 
89
                print("Failed to create Start Menu items, try running "\
 
90
                      "installer as administrator.", file=sys.stderr)
 
91
        elif sys.argv[1] == '-remove':
 
92
            remove()
 
93
        else:
 
94
            print("Unknown command line option %s" % sys.argv[1],
 
95
                  file=sys.stderr)