##// END OF EJS Templates
Moving things from tools to new utils directory.
Brian Granger -
Show More
@@ -62,7 +62,7 b' import unittest'
62
62
63 from doctest import *
63 from doctest import *
64
64
65 from IPython.tools import utils
65 from IPython.utils import genutils
66 from IPython.core import ipapi
66 from IPython.core import ipapi
67
67
68 ###########################################################################
68 ###########################################################################
@@ -481,8 +481,8 b' class IPDocTestLoader(unittest.TestLoader):'
481
481
482 if dt_files is None: dt_files = []
482 if dt_files is None: dt_files = []
483 if dt_modules is None: dt_modules = []
483 if dt_modules is None: dt_modules = []
484 self.dt_files = utils.list_strings(dt_files)
484 self.dt_files = genutils.list_strings(dt_files)
485 self.dt_modules = utils.list_strings(dt_modules)
485 self.dt_modules = genutils.list_strings(dt_modules)
486 if test_finder is None:
486 if test_finder is None:
487 test_finder = doctest.DocTestFinder(parser=IPDocTestParser())
487 test_finder = doctest.DocTestFinder(parser=IPDocTestParser())
488 self.test_finder = test_finder
488 self.test_finder = test_finder
@@ -31,7 +31,7 b' import sys'
31
31
32 import nose.tools as nt
32 import nose.tools as nt
33
33
34 from IPython.tools import utils
34 from IPython.utils import genutils
35 from IPython.testing import decorators as dec
35 from IPython.testing import decorators as dec
36
36
37 #-----------------------------------------------------------------------------
37 #-----------------------------------------------------------------------------
@@ -84,6 +84,6 b' def full_path(startPath,files):'
84 ['/a.txt']
84 ['/a.txt']
85 """
85 """
86
86
87 files = utils.list_strings(files)
87 files = genutils.list_strings(files)
88 base = os.path.split(startPath)[0]
88 base = os.path.split(startPath)[0]
89 return [ os.path.join(base,f) for f in files ]
89 return [ os.path.join(base,f) for f in files ]
@@ -23,7 +23,7 b' import os'
23 import sys
23 import sys
24
24
25 # From this project
25 # From this project
26 from IPython.tools import utils
26 from IPython.utils import genutils
27
27
28 # path to our own installation, so we can find source files under this.
28 # path to our own installation, so we can find source files under this.
29 TEST_PATH = os.path.dirname(os.path.abspath(__file__))
29 TEST_PATH = os.path.dirname(os.path.abspath(__file__))
@@ -82,6 +82,6 b' def fullPath(startPath,files):'
82 ['/a.txt']
82 ['/a.txt']
83 """
83 """
84
84
85 files = utils.list_strings(files)
85 files = genutils.list_strings(files)
86 base = os.path.split(startPath)[0]
86 base = os.path.split(startPath)[0]
87 return [ os.path.join(base,f) for f in files ]
87 return [ os.path.join(base,f) for f in files ]
@@ -1424,14 +1424,6 b' def qw_lol(indata):'
1424 else:
1424 else:
1425 return qw(indata)
1425 return qw(indata)
1426
1426
1427 #-----------------------------------------------------------------------------
1428 def list_strings(arg):
1429 """Always return a list of strings, given a string or list of strings
1430 as input."""
1431
1432 if type(arg) in StringTypes: return [arg]
1433 else: return arg
1434
1435 #----------------------------------------------------------------------------
1427 #----------------------------------------------------------------------------
1436 def grep(pat,list,case=1):
1428 def grep(pat,list,case=1):
1437 """Simple minded grep-like function.
1429 """Simple minded grep-like function.
@@ -2169,4 +2161,101 b' def num_cpus():'
2169 ncpus = 1
2161 ncpus = 1
2170 return ncpus
2162 return ncpus
2171
2163
2164 def extract_vars(*names,**kw):
2165 """Extract a set of variables by name from another frame.
2166
2167 :Parameters:
2168 - `*names`: strings
2169 One or more variable names which will be extracted from the caller's
2170 frame.
2171
2172 :Keywords:
2173 - `depth`: integer (0)
2174 How many frames in the stack to walk when looking for your variables.
2175
2176
2177 Examples:
2178
2179 In [2]: def func(x):
2180 ...: y = 1
2181 ...: print extractVars('x','y')
2182 ...:
2183
2184 In [3]: func('hello')
2185 {'y': 1, 'x': 'hello'}
2186 """
2187
2188 depth = kw.get('depth',0)
2189
2190 callerNS = sys._getframe(depth+1).f_locals
2191 return dict((k,callerNS[k]) for k in names)
2192
2193
2194 def extract_vars_above(*names):
2195 """Extract a set of variables by name from another frame.
2196
2197 Similar to extractVars(), but with a specified depth of 1, so that names
2198 are exctracted exactly from above the caller.
2199
2200 This is simply a convenience function so that the very common case (for us)
2201 of skipping exactly 1 frame doesn't have to construct a special dict for
2202 keyword passing."""
2203
2204 callerNS = sys._getframe(2).f_locals
2205 return dict((k,callerNS[k]) for k in names)
2206
2207 def shexp(s):
2208 """Expand $VARS and ~names in a string, like a shell
2209
2210 :Examples:
2211
2212 In [2]: os.environ['FOO']='test'
2213
2214 In [3]: shexp('variable FOO is $FOO')
2215 Out[3]: 'variable FOO is test'
2216 """
2217 return os.path.expandvars(os.path.expanduser(s))
2218
2219
2220 def list_strings(arg):
2221 """Always return a list of strings, given a string or list of strings
2222 as input.
2223
2224 :Examples:
2225
2226 In [7]: list_strings('A single string')
2227 Out[7]: ['A single string']
2228
2229 In [8]: list_strings(['A single string in a list'])
2230 Out[8]: ['A single string in a list']
2231
2232 In [9]: list_strings(['A','list','of','strings'])
2233 Out[9]: ['A', 'list', 'of', 'strings']
2234 """
2235
2236 if isinstance(arg,basestring): return [arg]
2237 else: return arg
2238
2239 def marquee(txt='',width=78,mark='*'):
2240 """Return the input string centered in a 'marquee'.
2241
2242 :Examples:
2243
2244 In [16]: marquee('A test',40)
2245 Out[16]: '**************** A test ****************'
2246
2247 In [17]: marquee('A test',40,'-')
2248 Out[17]: '---------------- A test ----------------'
2249
2250 In [18]: marquee('A test',40,' ')
2251 Out[18]: ' A test '
2252
2253 """
2254 if not txt:
2255 return (mark*width)[:width]
2256 nmark = (width-len(txt)-2)/len(mark)/2
2257 if nmark < 0: nmark =0
2258 marks = mark*nmark
2259 return '%s %s %s' % (marks,txt,marks)
2260
2172 #*************************** end of file <genutils.py> **********************
2261 #*************************** end of file <genutils.py> **********************
1 NO CONTENT: file renamed from IPython/tools/growl.py to IPython/utils/growl.py
NO CONTENT: file renamed from IPython/tools/growl.py to IPython/utils/growl.py
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now