forked from ipython/ipython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ville
authored and
ville
committed
Feb 16, 2008
0 parents
commit 2f09c2a
Showing
192 changed files
with
62,224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax: glob | ||
|
||
*~ | ||
*.tmp | ||
*.pyc | ||
*.bak | ||
*.tgz | ||
*.org | ||
*.rej | ||
.svn/ | ||
.bzr/ | ||
.settings/ | ||
.project | ||
*.diff | ||
IPython_crash_report.txt | ||
|
||
syntax: regexp | ||
.*\#.*\#$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
link doc/ChangeLog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tools for coloring text in ANSI terminals. | ||
$Id: ColorANSI.py 2167 2007-03-21 06:57:50Z fperez $""" | ||
|
||
#***************************************************************************** | ||
# Copyright (C) 2002-2006 Fernando Perez. <[email protected]> | ||
# | ||
# Distributed under the terms of the BSD License. The full license is in | ||
# the file COPYING, distributed as part of this software. | ||
#***************************************************************************** | ||
|
||
from IPython import Release | ||
__author__ = '%s <%s>' % Release.authors['Fernando'] | ||
__license__ = Release.license | ||
|
||
__all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable'] | ||
|
||
import os | ||
|
||
from IPython.ipstruct import Struct | ||
|
||
def make_color_table(in_class): | ||
"""Build a set of color attributes in a class. | ||
Helper function for building the *TermColors classes.""" | ||
|
||
color_templates = ( | ||
("Black" , "0;30"), | ||
("Red" , "0;31"), | ||
("Green" , "0;32"), | ||
("Brown" , "0;33"), | ||
("Blue" , "0;34"), | ||
("Purple" , "0;35"), | ||
("Cyan" , "0;36"), | ||
("LightGray" , "0;37"), | ||
("DarkGray" , "1;30"), | ||
("LightRed" , "1;31"), | ||
("LightGreen" , "1;32"), | ||
("Yellow" , "1;33"), | ||
("LightBlue" , "1;34"), | ||
("LightPurple" , "1;35"), | ||
("LightCyan" , "1;36"), | ||
("White" , "1;37"), ) | ||
|
||
for name,value in color_templates: | ||
setattr(in_class,name,in_class._base % value) | ||
|
||
class TermColors: | ||
"""Color escape sequences. | ||
This class defines the escape sequences for all the standard (ANSI?) | ||
colors in terminals. Also defines a NoColor escape which is just the null | ||
string, suitable for defining 'dummy' color schemes in terminals which get | ||
confused by color escapes. | ||
This class should be used as a mixin for building color schemes.""" | ||
|
||
NoColor = '' # for color schemes in color-less terminals. | ||
Normal = '\033[0m' # Reset normal coloring | ||
_base = '\033[%sm' # Template for all other colors | ||
|
||
# Build the actual color table as a set of class attributes: | ||
make_color_table(TermColors) | ||
|
||
class InputTermColors: | ||
"""Color escape sequences for input prompts. | ||
This class is similar to TermColors, but the escapes are wrapped in \001 | ||
and \002 so that readline can properly know the length of each line and | ||
can wrap lines accordingly. Use this class for any colored text which | ||
needs to be used in input prompts, such as in calls to raw_input(). | ||
This class defines the escape sequences for all the standard (ANSI?) | ||
colors in terminals. Also defines a NoColor escape which is just the null | ||
string, suitable for defining 'dummy' color schemes in terminals which get | ||
confused by color escapes. | ||
This class should be used as a mixin for building color schemes.""" | ||
|
||
NoColor = '' # for color schemes in color-less terminals. | ||
|
||
if os.name == 'nt' and os.environ.get('TERM','dumb') == 'emacs': | ||
# (X)emacs on W32 gets confused with \001 and \002 so we remove them | ||
Normal = '\033[0m' # Reset normal coloring | ||
_base = '\033[%sm' # Template for all other colors | ||
else: | ||
Normal = '\001\033[0m\002' # Reset normal coloring | ||
_base = '\001\033[%sm\002' # Template for all other colors | ||
|
||
# Build the actual color table as a set of class attributes: | ||
make_color_table(InputTermColors) | ||
|
||
class ColorScheme: | ||
"""Generic color scheme class. Just a name and a Struct.""" | ||
def __init__(self,__scheme_name_,colordict=None,**colormap): | ||
self.name = __scheme_name_ | ||
if colordict is None: | ||
self.colors = Struct(**colormap) | ||
else: | ||
self.colors = Struct(colordict) | ||
|
||
def copy(self,name=None): | ||
"""Return a full copy of the object, optionally renaming it.""" | ||
if name is None: | ||
name = self.name | ||
return ColorScheme(name,self.colors.__dict__) | ||
|
||
class ColorSchemeTable(dict): | ||
"""General class to handle tables of color schemes. | ||
It's basically a dict of color schemes with a couple of shorthand | ||
attributes and some convenient methods. | ||
active_scheme_name -> obvious | ||
active_colors -> actual color table of the active scheme""" | ||
|
||
def __init__(self,scheme_list=None,default_scheme=''): | ||
"""Create a table of color schemes. | ||
The table can be created empty and manually filled or it can be | ||
created with a list of valid color schemes AND the specification for | ||
the default active scheme. | ||
""" | ||
|
||
# create object attributes to be set later | ||
self.active_scheme_name = '' | ||
self.active_colors = None | ||
|
||
if scheme_list: | ||
if default_scheme == '': | ||
raise ValueError,'you must specify the default color scheme' | ||
for scheme in scheme_list: | ||
self.add_scheme(scheme) | ||
self.set_active_scheme(default_scheme) | ||
|
||
def copy(self): | ||
"""Return full copy of object""" | ||
return ColorSchemeTable(self.values(),self.active_scheme_name) | ||
|
||
def add_scheme(self,new_scheme): | ||
"""Add a new color scheme to the table.""" | ||
if not isinstance(new_scheme,ColorScheme): | ||
raise ValueError,'ColorSchemeTable only accepts ColorScheme instances' | ||
self[new_scheme.name] = new_scheme | ||
|
||
def set_active_scheme(self,scheme,case_sensitive=0): | ||
"""Set the currently active scheme. | ||
Names are by default compared in a case-insensitive way, but this can | ||
be changed by setting the parameter case_sensitive to true.""" | ||
|
||
scheme_names = self.keys() | ||
if case_sensitive: | ||
valid_schemes = scheme_names | ||
scheme_test = scheme | ||
else: | ||
valid_schemes = [s.lower() for s in scheme_names] | ||
scheme_test = scheme.lower() | ||
try: | ||
scheme_idx = valid_schemes.index(scheme_test) | ||
except ValueError: | ||
raise ValueError,'Unrecognized color scheme: ' + scheme + \ | ||
'\nValid schemes: '+str(scheme_names).replace("'', ",'') | ||
else: | ||
active = scheme_names[scheme_idx] | ||
self.active_scheme_name = active | ||
self.active_colors = self[active].colors | ||
# Now allow using '' as an index for the current active scheme | ||
self[''] = self[active] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Configuration loader | ||
$Id: ConfigLoader.py 1005 2006-01-12 08:39:26Z fperez $""" | ||
|
||
#***************************************************************************** | ||
# Copyright (C) 2001-2006 Fernando Perez. <[email protected]> | ||
# | ||
# Distributed under the terms of the BSD License. The full license is in | ||
# the file COPYING, distributed as part of this software. | ||
#***************************************************************************** | ||
|
||
from IPython import Release | ||
__author__ = '%s <%s>' % Release.authors['Fernando'] | ||
__license__ = Release.license | ||
|
||
import exceptions | ||
import os | ||
from pprint import pprint | ||
|
||
from IPython import ultraTB | ||
from IPython.ipstruct import Struct | ||
from IPython.genutils import * | ||
|
||
class ConfigLoaderError(exceptions.Exception): | ||
"""Exception for ConfigLoader class.""" | ||
|
||
def __init__(self,args=None): | ||
self.args = args | ||
|
||
class ConfigLoader: | ||
|
||
"""Configuration file loader capable of handling recursive inclusions and | ||
with parametrized conflict resolution for multiply found keys.""" | ||
|
||
def __init__(self,conflict=None,field_sep=None,reclimit=15): | ||
|
||
"""The reclimit parameter controls the number of recursive | ||
configuration file inclusions. This way we can stop early on (before | ||
python's own recursion limit is hit) if there is a circular | ||
inclusion. | ||
- conflict: dictionary for conflict resolutions (see Struct.merge()) | ||
""" | ||
self.conflict = conflict | ||
self.field_sep = field_sep | ||
self.reset(reclimit) | ||
|
||
def reset(self,reclimit=15): | ||
self.reclimit = reclimit | ||
self.recdepth = 0 | ||
self.included = [] | ||
|
||
def load(self,fname,convert=None,recurse_key='',incpath = '.',**kw): | ||
"""Load a configuration file, return the resulting Struct. | ||
Call: load_config(fname,convert=None,conflict=None,recurse_key='') | ||
- fname: file to load from. | ||
- convert: dictionary of type conversions (see read_dict()) | ||
- recurse_key: keyword in dictionary to trigger recursive file | ||
inclusions. | ||
""" | ||
|
||
if self.recdepth > self.reclimit: | ||
raise ConfigLoaderError, 'maximum recursive inclusion of rcfiles '+\ | ||
'exceeded: ' + `self.recdepth` + \ | ||
'.\nMaybe you have a circular chain of inclusions?' | ||
self.recdepth += 1 | ||
fname = filefind(fname,incpath) | ||
data = Struct() | ||
# avoid including the same file more than once | ||
if fname in self.included: | ||
return data | ||
Xinfo = ultraTB.AutoFormattedTB() | ||
if convert==None and recurse_key : convert = {qwflat:recurse_key} | ||
# for production, change warn to 0: | ||
data.merge(read_dict(fname,convert,fs=self.field_sep,strip=1, | ||
warn=0,no_empty=0,**kw)) | ||
# keep track of successfully loaded files | ||
self.included.append(fname) | ||
if recurse_key in data.keys(): | ||
for incfilename in data[recurse_key]: | ||
found=0 | ||
try: | ||
incfile = filefind(incfilename,incpath) | ||
except IOError: | ||
if os.name in ['nt','dos']: | ||
try: | ||
# Try again with '.ini' extension | ||
incfilename += '.ini' | ||
incfile = filefind(incfilename,incpath) | ||
except IOError: | ||
found = 0 | ||
else: | ||
found = 1 | ||
else: | ||
found = 0 | ||
else: | ||
found = 1 | ||
if found: | ||
try: | ||
data.merge(self.load(incfile,convert,recurse_key, | ||
incpath,**kw), | ||
self.conflict) | ||
except: | ||
Xinfo() | ||
warn('Problem loading included file: '+ | ||
`incfilename` + '. Ignoring it...') | ||
else: | ||
warn('File `%s` not found. Included by %s' % (incfilename,fname)) | ||
|
||
return data | ||
|
||
# end ConfigLoader |
Oops, something went wrong.