##// END OF EJS Templates
Moved the traitlets based config to sandbox (created it)....
Brian Granger -
Show More
@@ -1,106 +1,102 b''
1 # encoding: utf-8
1 # encoding: utf-8
2
2
3 """This is the official entry point to IPython's configuration system. """
3 """This is the official entry point to IPython's configuration system. """
4
4
5 __docformat__ = "restructuredtext en"
5 __docformat__ = "restructuredtext en"
6
6
7 #-------------------------------------------------------------------------------
7 #-------------------------------------------------------------------------------
8 # Copyright (C) 2008 The IPython Development Team
8 # Copyright (C) 2008 The IPython Development Team
9 #
9 #
10 # Distributed under the terms of the BSD License. The full license is in
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
11 # the file COPYING, distributed as part of this software.
12 #-------------------------------------------------------------------------------
12 #-------------------------------------------------------------------------------
13
13
14 #-------------------------------------------------------------------------------
14 #-------------------------------------------------------------------------------
15 # Imports
15 # Imports
16 #-------------------------------------------------------------------------------
16 #-------------------------------------------------------------------------------
17
17
18 import os
18 import os
19 from os.path import join as pjoin
19 from os.path import join as pjoin
20
20
21 from IPython.genutils import get_home_dir, get_ipython_dir
21 from IPython.genutils import get_home_dir, get_ipython_dir
22 from IPython.external.configobj import ConfigObj
22 from IPython.external.configobj import ConfigObj
23
23
24 # Traitlets config imports
25 # from IPython.config import traitlets
26 # from IPython.config.config import *
27 # from traitlets import *
28
24
29 class ConfigObjManager(object):
25 class ConfigObjManager(object):
30
26
31 def __init__(self, configObj, filename):
27 def __init__(self, configObj, filename):
32 self.current = configObj
28 self.current = configObj
33 self.current.indent_type = ' '
29 self.current.indent_type = ' '
34 self.filename = filename
30 self.filename = filename
35 # self.write_default_config_file()
31 # self.write_default_config_file()
36
32
37 def get_config_obj(self):
33 def get_config_obj(self):
38 return self.current
34 return self.current
39
35
40 def update_config_obj(self, newConfig):
36 def update_config_obj(self, newConfig):
41 self.current.merge(newConfig)
37 self.current.merge(newConfig)
42
38
43 def update_config_obj_from_file(self, filename):
39 def update_config_obj_from_file(self, filename):
44 newConfig = ConfigObj(filename, file_error=False)
40 newConfig = ConfigObj(filename, file_error=False)
45 self.current.merge(newConfig)
41 self.current.merge(newConfig)
46
42
47 def update_config_obj_from_default_file(self, ipythondir=None):
43 def update_config_obj_from_default_file(self, ipythondir=None):
48 fname = self.resolve_file_path(self.filename, ipythondir)
44 fname = self.resolve_file_path(self.filename, ipythondir)
49 self.update_config_obj_from_file(fname)
45 self.update_config_obj_from_file(fname)
50
46
51 def write_config_obj_to_file(self, filename):
47 def write_config_obj_to_file(self, filename):
52 f = open(filename, 'w')
48 f = open(filename, 'w')
53 self.current.write(f)
49 self.current.write(f)
54 f.close()
50 f.close()
55
51
56 def write_default_config_file(self):
52 def write_default_config_file(self):
57 ipdir = get_ipython_dir()
53 ipdir = get_ipython_dir()
58 fname = pjoin(ipdir, self.filename)
54 fname = pjoin(ipdir, self.filename)
59 if not os.path.isfile(fname):
55 if not os.path.isfile(fname):
60 print "Writing the configuration file to: " + fname
56 print "Writing the configuration file to: " + fname
61 self.write_config_obj_to_file(fname)
57 self.write_config_obj_to_file(fname)
62
58
63 def _import(self, key):
59 def _import(self, key):
64 package = '.'.join(key.split('.')[0:-1])
60 package = '.'.join(key.split('.')[0:-1])
65 obj = key.split('.')[-1]
61 obj = key.split('.')[-1]
66 execString = 'from %s import %s' % (package, obj)
62 execString = 'from %s import %s' % (package, obj)
67 exec execString
63 exec execString
68 exec 'temp = %s' % obj
64 exec 'temp = %s' % obj
69 return temp
65 return temp
70
66
71 def resolve_file_path(self, filename, ipythondir = None):
67 def resolve_file_path(self, filename, ipythondir = None):
72 """Resolve filenames into absolute paths.
68 """Resolve filenames into absolute paths.
73
69
74 This function looks in the following directories in order:
70 This function looks in the following directories in order:
75
71
76 1. In the current working directory or by absolute path with ~ expanded
72 1. In the current working directory or by absolute path with ~ expanded
77 2. In ipythondir if that is set
73 2. In ipythondir if that is set
78 3. In the IPYTHONDIR environment variable if it exists
74 3. In the IPYTHONDIR environment variable if it exists
79 4. In the ~/.ipython directory
75 4. In the ~/.ipython directory
80
76
81 Note: The IPYTHONDIR is also used by the trunk version of IPython so
77 Note: The IPYTHONDIR is also used by the trunk version of IPython so
82 changing it will also affect it was well.
78 changing it will also affect it was well.
83 """
79 """
84
80
85 # In cwd or by absolute path with ~ expanded
81 # In cwd or by absolute path with ~ expanded
86 trythis = os.path.expanduser(filename)
82 trythis = os.path.expanduser(filename)
87 if os.path.isfile(trythis):
83 if os.path.isfile(trythis):
88 return trythis
84 return trythis
89
85
90 # In ipythondir if it is set
86 # In ipythondir if it is set
91 if ipythondir is not None:
87 if ipythondir is not None:
92 trythis = pjoin(ipythondir, filename)
88 trythis = pjoin(ipythondir, filename)
93 if os.path.isfile(trythis):
89 if os.path.isfile(trythis):
94 return trythis
90 return trythis
95
91
96 trythis = pjoin(get_ipython_dir(), filename)
92 trythis = pjoin(get_ipython_dir(), filename)
97 if os.path.isfile(trythis):
93 if os.path.isfile(trythis):
98 return trythis
94 return trythis
99
95
100 return None
96 return None
101
97
102
98
103
99
104
100
105
101
106
102
1 NO CONTENT: file renamed from IPython/config/config.py to sandbox/config.py
NO CONTENT: file renamed from IPython/config/config.py to sandbox/config.py
1 NO CONTENT: file renamed from IPython/config/tests/sample_config.py to sandbox/sample_config.py
NO CONTENT: file renamed from IPython/config/tests/sample_config.py to sandbox/sample_config.py
1 NO CONTENT: file renamed from IPython/config/tests/test_config.py to sandbox/test_config.py
NO CONTENT: file renamed from IPython/config/tests/test_config.py to sandbox/test_config.py
1 NO CONTENT: file renamed from IPython/config/traitlets.py to sandbox/traitlets.py
NO CONTENT: file renamed from IPython/config/traitlets.py to sandbox/traitlets.py
General Comments 0
You need to be logged in to leave comments. Login now