##// END OF EJS Templates
Fix problem with windows installer script: html docs were not found.
Fernando Perez -
Show More
@@ -1,170 +1,179 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Tools for coloring text in ANSI terminals.
2 """Tools for coloring text in ANSI terminals.
3
3
4 $Id: ColorANSI.py 2167 2007-03-21 06:57:50Z fperez $"""
4 $Id: ColorANSI.py 2167 2007-03-21 06:57:50Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2002-2006 Fernando Perez. <fperez@colorado.edu>
7 # Copyright (C) 2002-2006 Fernando Perez. <fperez@colorado.edu>
8 #
8 #
9 # Distributed under the terms of the BSD License. The full license is in
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
10 # the file COPYING, distributed as part of this software.
11 #*****************************************************************************
11 #*****************************************************************************
12
12
13 from IPython import Release
13 from IPython import Release
14 __author__ = '%s <%s>' % Release.authors['Fernando']
14 __author__ = '%s <%s>' % Release.authors['Fernando']
15 __license__ = Release.license
15 __license__ = Release.license
16
16
17 __all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable']
17 __all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable']
18
18
19 import os
19 import os
20
20
21 from IPython.ipstruct import Struct
21 from IPython.ipstruct import Struct
22
22
23 def make_color_table(in_class):
23 def make_color_table(in_class):
24 """Build a set of color attributes in a class.
24 """Build a set of color attributes in a class.
25
25
26 Helper function for building the *TermColors classes."""
26 Helper function for building the *TermColors classes."""
27
27
28 color_templates = (
28 color_templates = (
29 ("Black" , "0;30"),
29 ("Black" , "0;30"),
30 ("Red" , "0;31"),
30 ("Red" , "0;31"),
31 ("Green" , "0;32"),
31 ("Green" , "0;32"),
32 ("Brown" , "0;33"),
32 ("Brown" , "0;33"),
33 ("Blue" , "0;34"),
33 ("Blue" , "0;34"),
34 ("Purple" , "0;35"),
34 ("Purple" , "0;35"),
35 ("Cyan" , "0;36"),
35 ("Cyan" , "0;36"),
36 ("LightGray" , "0;37"),
36 ("LightGray" , "0;37"),
37 ("DarkGray" , "1;30"),
37 ("DarkGray" , "1;30"),
38 ("LightRed" , "1;31"),
38 ("LightRed" , "1;31"),
39 ("LightGreen" , "1;32"),
39 ("LightGreen" , "1;32"),
40 ("Yellow" , "1;33"),
40 ("Yellow" , "1;33"),
41 ("LightBlue" , "1;34"),
41 ("LightBlue" , "1;34"),
42 ("LightPurple" , "1;35"),
42 ("LightPurple" , "1;35"),
43 ("LightCyan" , "1;36"),
43 ("LightCyan" , "1;36"),
44 ("White" , "1;37"), )
44 ("White" , "1;37"), )
45
45
46 for name,value in color_templates:
46 for name,value in color_templates:
47 setattr(in_class,name,in_class._base % value)
47 setattr(in_class,name,in_class._base % value)
48
48
49 # Automatically add Blink versions of the above colors. This
50 # just involves setting the attribute field (before the first
51 # semicolon) to '5'.
52 # Note: this is a little easter egg contributed by Peter Wang from
53 # Enthought at the Scipy2008 sprint :)
54 value = '5'+value[1:]
55 setattr(in_class,"Blink"+name,in_class._base % value)
56
57
49 class TermColors:
58 class TermColors:
50 """Color escape sequences.
59 """Color escape sequences.
51
60
52 This class defines the escape sequences for all the standard (ANSI?)
61 This class defines the escape sequences for all the standard (ANSI?)
53 colors in terminals. Also defines a NoColor escape which is just the null
62 colors in terminals. Also defines a NoColor escape which is just the null
54 string, suitable for defining 'dummy' color schemes in terminals which get
63 string, suitable for defining 'dummy' color schemes in terminals which get
55 confused by color escapes.
64 confused by color escapes.
56
65
57 This class should be used as a mixin for building color schemes."""
66 This class should be used as a mixin for building color schemes."""
58
67
59 NoColor = '' # for color schemes in color-less terminals.
68 NoColor = '' # for color schemes in color-less terminals.
60 Normal = '\033[0m' # Reset normal coloring
69 Normal = '\033[0m' # Reset normal coloring
61 _base = '\033[%sm' # Template for all other colors
70 _base = '\033[%sm' # Template for all other colors
62
71
63 # Build the actual color table as a set of class attributes:
72 # Build the actual color table as a set of class attributes:
64 make_color_table(TermColors)
73 make_color_table(TermColors)
65
74
66 class InputTermColors:
75 class InputTermColors:
67 """Color escape sequences for input prompts.
76 """Color escape sequences for input prompts.
68
77
69 This class is similar to TermColors, but the escapes are wrapped in \001
78 This class is similar to TermColors, but the escapes are wrapped in \001
70 and \002 so that readline can properly know the length of each line and
79 and \002 so that readline can properly know the length of each line and
71 can wrap lines accordingly. Use this class for any colored text which
80 can wrap lines accordingly. Use this class for any colored text which
72 needs to be used in input prompts, such as in calls to raw_input().
81 needs to be used in input prompts, such as in calls to raw_input().
73
82
74 This class defines the escape sequences for all the standard (ANSI?)
83 This class defines the escape sequences for all the standard (ANSI?)
75 colors in terminals. Also defines a NoColor escape which is just the null
84 colors in terminals. Also defines a NoColor escape which is just the null
76 string, suitable for defining 'dummy' color schemes in terminals which get
85 string, suitable for defining 'dummy' color schemes in terminals which get
77 confused by color escapes.
86 confused by color escapes.
78
87
79 This class should be used as a mixin for building color schemes."""
88 This class should be used as a mixin for building color schemes."""
80
89
81 NoColor = '' # for color schemes in color-less terminals.
90 NoColor = '' # for color schemes in color-less terminals.
82
91
83 if os.name == 'nt' and os.environ.get('TERM','dumb') == 'emacs':
92 if os.name == 'nt' and os.environ.get('TERM','dumb') == 'emacs':
84 # (X)emacs on W32 gets confused with \001 and \002 so we remove them
93 # (X)emacs on W32 gets confused with \001 and \002 so we remove them
85 Normal = '\033[0m' # Reset normal coloring
94 Normal = '\033[0m' # Reset normal coloring
86 _base = '\033[%sm' # Template for all other colors
95 _base = '\033[%sm' # Template for all other colors
87 else:
96 else:
88 Normal = '\001\033[0m\002' # Reset normal coloring
97 Normal = '\001\033[0m\002' # Reset normal coloring
89 _base = '\001\033[%sm\002' # Template for all other colors
98 _base = '\001\033[%sm\002' # Template for all other colors
90
99
91 # Build the actual color table as a set of class attributes:
100 # Build the actual color table as a set of class attributes:
92 make_color_table(InputTermColors)
101 make_color_table(InputTermColors)
93
102
94 class ColorScheme:
103 class ColorScheme:
95 """Generic color scheme class. Just a name and a Struct."""
104 """Generic color scheme class. Just a name and a Struct."""
96 def __init__(self,__scheme_name_,colordict=None,**colormap):
105 def __init__(self,__scheme_name_,colordict=None,**colormap):
97 self.name = __scheme_name_
106 self.name = __scheme_name_
98 if colordict is None:
107 if colordict is None:
99 self.colors = Struct(**colormap)
108 self.colors = Struct(**colormap)
100 else:
109 else:
101 self.colors = Struct(colordict)
110 self.colors = Struct(colordict)
102
111
103 def copy(self,name=None):
112 def copy(self,name=None):
104 """Return a full copy of the object, optionally renaming it."""
113 """Return a full copy of the object, optionally renaming it."""
105 if name is None:
114 if name is None:
106 name = self.name
115 name = self.name
107 return ColorScheme(name,self.colors.__dict__)
116 return ColorScheme(name,self.colors.__dict__)
108
117
109 class ColorSchemeTable(dict):
118 class ColorSchemeTable(dict):
110 """General class to handle tables of color schemes.
119 """General class to handle tables of color schemes.
111
120
112 It's basically a dict of color schemes with a couple of shorthand
121 It's basically a dict of color schemes with a couple of shorthand
113 attributes and some convenient methods.
122 attributes and some convenient methods.
114
123
115 active_scheme_name -> obvious
124 active_scheme_name -> obvious
116 active_colors -> actual color table of the active scheme"""
125 active_colors -> actual color table of the active scheme"""
117
126
118 def __init__(self,scheme_list=None,default_scheme=''):
127 def __init__(self,scheme_list=None,default_scheme=''):
119 """Create a table of color schemes.
128 """Create a table of color schemes.
120
129
121 The table can be created empty and manually filled or it can be
130 The table can be created empty and manually filled or it can be
122 created with a list of valid color schemes AND the specification for
131 created with a list of valid color schemes AND the specification for
123 the default active scheme.
132 the default active scheme.
124 """
133 """
125
134
126 # create object attributes to be set later
135 # create object attributes to be set later
127 self.active_scheme_name = ''
136 self.active_scheme_name = ''
128 self.active_colors = None
137 self.active_colors = None
129
138
130 if scheme_list:
139 if scheme_list:
131 if default_scheme == '':
140 if default_scheme == '':
132 raise ValueError,'you must specify the default color scheme'
141 raise ValueError,'you must specify the default color scheme'
133 for scheme in scheme_list:
142 for scheme in scheme_list:
134 self.add_scheme(scheme)
143 self.add_scheme(scheme)
135 self.set_active_scheme(default_scheme)
144 self.set_active_scheme(default_scheme)
136
145
137 def copy(self):
146 def copy(self):
138 """Return full copy of object"""
147 """Return full copy of object"""
139 return ColorSchemeTable(self.values(),self.active_scheme_name)
148 return ColorSchemeTable(self.values(),self.active_scheme_name)
140
149
141 def add_scheme(self,new_scheme):
150 def add_scheme(self,new_scheme):
142 """Add a new color scheme to the table."""
151 """Add a new color scheme to the table."""
143 if not isinstance(new_scheme,ColorScheme):
152 if not isinstance(new_scheme,ColorScheme):
144 raise ValueError,'ColorSchemeTable only accepts ColorScheme instances'
153 raise ValueError,'ColorSchemeTable only accepts ColorScheme instances'
145 self[new_scheme.name] = new_scheme
154 self[new_scheme.name] = new_scheme
146
155
147 def set_active_scheme(self,scheme,case_sensitive=0):
156 def set_active_scheme(self,scheme,case_sensitive=0):
148 """Set the currently active scheme.
157 """Set the currently active scheme.
149
158
150 Names are by default compared in a case-insensitive way, but this can
159 Names are by default compared in a case-insensitive way, but this can
151 be changed by setting the parameter case_sensitive to true."""
160 be changed by setting the parameter case_sensitive to true."""
152
161
153 scheme_names = self.keys()
162 scheme_names = self.keys()
154 if case_sensitive:
163 if case_sensitive:
155 valid_schemes = scheme_names
164 valid_schemes = scheme_names
156 scheme_test = scheme
165 scheme_test = scheme
157 else:
166 else:
158 valid_schemes = [s.lower() for s in scheme_names]
167 valid_schemes = [s.lower() for s in scheme_names]
159 scheme_test = scheme.lower()
168 scheme_test = scheme.lower()
160 try:
169 try:
161 scheme_idx = valid_schemes.index(scheme_test)
170 scheme_idx = valid_schemes.index(scheme_test)
162 except ValueError:
171 except ValueError:
163 raise ValueError,'Unrecognized color scheme: ' + scheme + \
172 raise ValueError,'Unrecognized color scheme: ' + scheme + \
164 '\nValid schemes: '+str(scheme_names).replace("'', ",'')
173 '\nValid schemes: '+str(scheme_names).replace("'', ",'')
165 else:
174 else:
166 active = scheme_names[scheme_idx]
175 active = scheme_names[scheme_idx]
167 self.active_scheme_name = active
176 self.active_scheme_name = active
168 self.active_colors = self[active].colors
177 self.active_colors = self[active].colors
169 # Now allow using '' as an index for the current active scheme
178 # Now allow using '' as an index for the current active scheme
170 self[''] = self[active]
179 self[''] = self[active]
@@ -1,85 +1,85 b''
1 #!python
1 #!python
2 """Windows-specific part of the installation"""
2 """Windows-specific part of the installation"""
3
3
4 import os, sys, shutil
4 import os, sys, shutil
5
5
6 def mkshortcut(target,description,link_file,*args,**kw):
6 def mkshortcut(target,description,link_file,*args,**kw):
7 """make a shortcut if it doesn't exist, and register its creation"""
7 """make a shortcut if it doesn't exist, and register its creation"""
8
8
9 create_shortcut(target, description, link_file,*args,**kw)
9 create_shortcut(target, description, link_file,*args,**kw)
10 file_created(link_file)
10 file_created(link_file)
11
11
12 def install():
12 def install():
13 """Routine to be run by the win32 installer with the -install switch."""
13 """Routine to be run by the win32 installer with the -install switch."""
14
14
15 from IPython.Release import version
15 from IPython.Release import version
16
16
17 # Get some system constants
17 # Get some system constants
18 prefix = sys.prefix
18 prefix = sys.prefix
19 python = prefix + r'\python.exe'
19 python = prefix + r'\python.exe'
20 # Lookup path to common startmenu ...
20 # Lookup path to common startmenu ...
21 ip_dir = get_special_folder_path('CSIDL_COMMON_PROGRAMS') + r'\IPython'
21 ip_dir = get_special_folder_path('CSIDL_COMMON_PROGRAMS') + r'\IPython'
22
22
23 # Some usability warnings at installation time. I don't want them at the
23 # Some usability warnings at installation time. I don't want them at the
24 # top-level, so they don't appear if the user is uninstalling.
24 # top-level, so they don't appear if the user is uninstalling.
25 try:
25 try:
26 import ctypes
26 import ctypes
27 except ImportError:
27 except ImportError:
28 print ('To take full advantage of IPython, you need ctypes from:\n'
28 print ('To take full advantage of IPython, you need ctypes from:\n'
29 'http://sourceforge.net/projects/ctypes')
29 'http://sourceforge.net/projects/ctypes')
30
30
31 try:
31 try:
32 import win32con
32 import win32con
33 except ImportError:
33 except ImportError:
34 print ('To take full advantage of IPython, you need pywin32 from:\n'
34 print ('To take full advantage of IPython, you need pywin32 from:\n'
35 'http://starship.python.net/crew/mhammond/win32/Downloads.html')
35 'http://starship.python.net/crew/mhammond/win32/Downloads.html')
36
36
37 try:
37 try:
38 import readline
38 import readline
39 except ImportError:
39 except ImportError:
40 print ('To take full advantage of IPython, you need readline from:\n'
40 print ('To take full advantage of IPython, you need readline from:\n'
41 'http://sourceforge.net/projects/uncpythontools')
41 'http://sourceforge.net/projects/uncpythontools')
42
42
43 ipybase = '"'+prefix+r'\scripts\ipython"'
43 ipybase = '"' + prefix + r'\scripts\ipython"'
44 # Create IPython entry ...
44 # Create IPython entry ...
45 if not os.path.isdir(ip_dir):
45 if not os.path.isdir(ip_dir):
46 os.mkdir(ip_dir)
46 os.mkdir(ip_dir)
47 directory_created(ip_dir)
47 directory_created(ip_dir)
48
48
49 # Create program shortcuts ...
49 # Create program shortcuts ...
50 f = ip_dir + r'\IPython.lnk'
50 f = ip_dir + r'\IPython.lnk'
51 a = ipybase
51 a = ipybase
52 mkshortcut(python,'IPython',f,a)
52 mkshortcut(python,'IPython',f,a)
53
53
54 f = ip_dir + r'\pysh.lnk'
54 f = ip_dir + r'\pysh.lnk'
55 a = ipybase+' -p sh'
55 a = ipybase+' -p sh'
56 mkshortcut(python,'IPython command prompt mode',f,a)
56 mkshortcut(python,'IPython command prompt mode',f,a)
57
57
58 f = ip_dir + r'\scipy.lnk'
58 f = ip_dir + r'\scipy.lnk'
59 a = ipybase+' -pylab -p scipy'
59 a = ipybase+' -pylab -p scipy'
60 mkshortcut(python,'IPython scipy profile',f,a)
60 mkshortcut(python,'IPython scipy profile',f,a)
61
61
62 # Create documentation shortcuts ...
62 # Create documentation shortcuts ...
63 t = prefix + r'\share\doc\ipython\manual\ipython.pdf'
63 t = prefix + r'\share\doc\ipython\manual\ipython.pdf'
64 f = ip_dir + r'\Manual in PDF.lnk'
64 f = ip_dir + r'\Manual in PDF.lnk'
65 mkshortcut(t,r'IPython Manual - PDF-Format',f)
65 mkshortcut(t,r'IPython Manual - PDF-Format',f)
66
66
67 t = prefix + r'\share\doc\ipython\manual\ipython.html'
67 t = prefix + r'\share\doc\ipython\manual\html\index.html'
68 f = ip_dir + r'\Manual in HTML.lnk'
68 f = ip_dir + r'\Manual in HTML.lnk'
69 mkshortcut(t,'IPython Manual - HTML-Format',f)
69 mkshortcut(t,'IPython Manual - HTML-Format',f)
70
70
71 # make ipython.py
71 # make ipython.py
72 shutil.copy(prefix + r'\scripts\ipython', prefix + r'\scripts\ipython.py')
72 shutil.copy(prefix + r'\scripts\ipython', prefix + r'\scripts\ipython.py')
73
73
74 def remove():
74 def remove():
75 """Routine to be run by the win32 installer with the -remove switch."""
75 """Routine to be run by the win32 installer with the -remove switch."""
76 pass
76 pass
77
77
78 # main()
78 # main()
79 if len(sys.argv) > 1:
79 if len(sys.argv) > 1:
80 if sys.argv[1] == '-install':
80 if sys.argv[1] == '-install':
81 install()
81 install()
82 elif sys.argv[1] == '-remove':
82 elif sys.argv[1] == '-remove':
83 remove()
83 remove()
84 else:
84 else:
85 print "Script was called with option %s" % sys.argv[1]
85 print "Script was called with option %s" % sys.argv[1]
General Comments 0
You need to be logged in to leave comments. Login now