##// END OF EJS Templates
Merging changes from Gael. These are fixes to make frontend 2.4 happy.
Merging changes from Gael. These are fixes to make frontend 2.4 happy.

File last commit:

r1713:3f571b84
r1714:7b23eefb merge
Show More
api.py
106 lines | 3.3 KiB | text/x-python | PythonLexer
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234 # encoding: utf-8
"""This is the official entry point to IPython's configuration system. """
__docformat__ = "restructuredtext en"
#-------------------------------------------------------------------------------
# Copyright (C) 2008 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Imports
#-------------------------------------------------------------------------------
import os
Brian Granger
All security related files (*.furl and *.pem) are now put in a default...
r1609 from os.path import join as pjoin
Brian Granger
Created genutils.get_ipython_dir to encapsulate the logic...
r1608 from IPython.genutils import get_home_dir, get_ipython_dir
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234 from IPython.external.configobj import ConfigObj
Stefan van der Walt
Merge sconfig branch.
r1253 # Traitlets config imports
Brian Granger
Ahhh, config has 2.5isms in it. Beginning to debug.
r1713 # from IPython.config import traitlets
# from IPython.config.config import *
# from traitlets import *
Stefan van der Walt
Merge sconfig branch.
r1253
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234 class ConfigObjManager(object):
def __init__(self, configObj, filename):
self.current = configObj
self.current.indent_type = ' '
self.filename = filename
# self.write_default_config_file()
def get_config_obj(self):
return self.current
def update_config_obj(self, newConfig):
self.current.merge(newConfig)
def update_config_obj_from_file(self, filename):
newConfig = ConfigObj(filename, file_error=False)
self.current.merge(newConfig)
def update_config_obj_from_default_file(self, ipythondir=None):
fname = self.resolve_file_path(self.filename, ipythondir)
self.update_config_obj_from_file(fname)
def write_config_obj_to_file(self, filename):
f = open(filename, 'w')
self.current.write(f)
f.close()
def write_default_config_file(self):
ipdir = get_ipython_dir()
Brian Granger
All security related files (*.furl and *.pem) are now put in a default...
r1609 fname = pjoin(ipdir, self.filename)
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234 if not os.path.isfile(fname):
print "Writing the configuration file to: " + fname
self.write_config_obj_to_file(fname)
def _import(self, key):
package = '.'.join(key.split('.')[0:-1])
obj = key.split('.')[-1]
execString = 'from %s import %s' % (package, obj)
exec execString
exec 'temp = %s' % obj
return temp
def resolve_file_path(self, filename, ipythondir = None):
"""Resolve filenames into absolute paths.
This function looks in the following directories in order:
1. In the current working directory or by absolute path with ~ expanded
2. In ipythondir if that is set
3. In the IPYTHONDIR environment variable if it exists
4. In the ~/.ipython directory
Note: The IPYTHONDIR is also used by the trunk version of IPython so
changing it will also affect it was well.
"""
# In cwd or by absolute path with ~ expanded
trythis = os.path.expanduser(filename)
if os.path.isfile(trythis):
return trythis
# In ipythondir if it is set
if ipythondir is not None:
Brian Granger
All security related files (*.furl and *.pem) are now put in a default...
r1609 trythis = pjoin(ipythondir, filename)
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234 if os.path.isfile(trythis):
return trythis
Brian Granger
All security related files (*.furl and *.pem) are now put in a default...
r1609 trythis = pjoin(get_ipython_dir(), filename)
Brian E Granger
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
r1234 if os.path.isfile(trythis):
return trythis
return None