##// END OF EJS Templates
Small fixes as per @certik's review.
Fernando Perez -
Show More
@@ -109,7 +109,7 b' class AutoMagics(Magics):'
109 else:
109 else:
110 arg = 'toggle'
110 arg = 'toggle'
111
111
112 if not arg in (0, 1, 2,'toggle'):
112 if not arg in (0, 1, 2, 'toggle'):
113 error('Valid modes: (0->Off, 1->Smart, 2->Full')
113 error('Valid modes: (0->Off, 1->Smart, 2->Full')
114 return
114 return
115
115
@@ -71,7 +71,7 b' class BasicMagics(Magics):'
71 mode = parameter_s.split()[0][1:]
71 mode = parameter_s.split()[0][1:]
72 if mode == 'rest':
72 if mode == 'rest':
73 rest_docs = []
73 rest_docs = []
74 except:
74 except IndexError:
75 pass
75 pass
76
76
77 magic_docs = []
77 magic_docs = []
@@ -249,7 +249,7 b' class CodeMagics(Magics):'
249 filename = make_filename(args)
249 filename = make_filename(args)
250 datafile = 1
250 datafile = 1
251 warn('Could not find file where `%s` is defined.\n'
251 warn('Could not find file where `%s` is defined.\n'
252 'Opening a file named `%s`' % (args,filename))
252 'Opening a file named `%s`' % (args, filename))
253 # Now, make sure we can actually read the source (if it was
253 # Now, make sure we can actually read the source (if it was
254 # in a temp file it's gone by now).
254 # in a temp file it's gone by now).
255 if datafile:
255 if datafile:
@@ -259,8 +259,8 b' class CodeMagics(Magics):'
259 except IOError:
259 except IOError:
260 filename = make_filename(args)
260 filename = make_filename(args)
261 if filename is None:
261 if filename is None:
262 warn('The file `%s` where `%s` was defined cannot '
262 warn('The file `%s` where `%s` was defined '
263 'be read.' % (filename,data))
263 'cannot be read.' % (filename, data))
264 return
264 return
265 use_temp = False
265 use_temp = False
266
266
@@ -448,9 +448,9 b' class NamespaceMagics(Magics):'
448 vdtype = var.dtype
448 vdtype = var.dtype
449
449
450 if vbytes < 100000:
450 if vbytes < 100000:
451 print aformat % (vshape,vsize,vdtype,vbytes)
451 print aformat % (vshape, vsize, vdtype, vbytes)
452 else:
452 else:
453 print aformat % (vshape,vsize,vdtype,vbytes),
453 print aformat % (vshape, vsize, vdtype, vbytes),
454 if vbytes < Mb:
454 if vbytes < Mb:
455 print '(%s kb)' % (vbytes/kb,)
455 print '(%s kb)' % (vbytes/kb,)
456 else:
456 else:
@@ -463,7 +463,7 b' class NamespaceMagics(Magics):'
463 'backslashreplace')
463 'backslashreplace')
464 except:
464 except:
465 vstr = "<object with id %d (str() failed)>" % id(var)
465 vstr = "<object with id %d (str() failed)>" % id(var)
466 vstr = vstr.replace('\n','\\n')
466 vstr = vstr.replace('\n', '\\n')
467 if len(vstr) < 50:
467 if len(vstr) < 50:
468 print vstr
468 print vstr
469 else:
469 else:
@@ -316,7 +316,7 b' class OSMagics(Magics):'
316
316
317 if ps in bkms:
317 if ps in bkms:
318 target = bkms[ps]
318 target = bkms[ps]
319 print '(bookmark:%s) -> %s' % (ps,target)
319 print '(bookmark:%s) -> %s' % (ps, target)
320 ps = target
320 ps = target
321 else:
321 else:
322 if 'b' in opts:
322 if 'b' in opts:
@@ -522,24 +522,24 b' class OSMagics(Magics):'
522 .s (or .spstr): value as space-separated string.
522 .s (or .spstr): value as space-separated string.
523 """
523 """
524
524
525 opts,args = self.parse_options(parameter_s,'lv')
525 opts,args = self.parse_options(parameter_s, 'lv')
526 # Try to get a variable name and command to run
526 # Try to get a variable name and command to run
527 try:
527 try:
528 # the variable name must be obtained from the parse_options
528 # the variable name must be obtained from the parse_options
529 # output, which uses shlex.split to strip options out.
529 # output, which uses shlex.split to strip options out.
530 var,_ = args.split('=',1)
530 var,_ = args.split('=', 1)
531 var = var.strip()
531 var = var.strip()
532 # But the command has to be extracted from the original input
532 # But the command has to be extracted from the original input
533 # parameter_s, not on what parse_options returns, to avoid the
533 # parameter_s, not on what parse_options returns, to avoid the
534 # quote stripping which shlex.split performs on it.
534 # quote stripping which shlex.split performs on it.
535 _,cmd = parameter_s.split('=',1)
535 _,cmd = parameter_s.split('=', 1)
536 except ValueError:
536 except ValueError:
537 var,cmd = '',''
537 var,cmd = '',''
538 # If all looks ok, proceed
538 # If all looks ok, proceed
539 split = 'l' in opts
539 split = 'l' in opts
540 out = self.shell.getoutput(cmd, split=split)
540 out = self.shell.getoutput(cmd, split=split)
541 if 'v' in opts:
541 if 'v' in opts:
542 print '%s ==\n%s' % (var,pformat(out))
542 print '%s ==\n%s' % (var, pformat(out))
543 if var:
543 if var:
544 self.shell.user_ns.update({var:out})
544 self.shell.user_ns.update({var:out})
545 else:
545 else:
@@ -127,7 +127,7 b' class StoreMagics(Magics):'
127 vars = self.db.keys('autorestore/*')
127 vars = self.db.keys('autorestore/*')
128 vars.sort()
128 vars.sort()
129 if vars:
129 if vars:
130 size = max(map(len,vars))
130 size = max(map(len, vars))
131 else:
131 else:
132 size = 0
132 size = 0
133
133
@@ -137,7 +137,7 b' class StoreMagics(Magics):'
137 for var in vars:
137 for var in vars:
138 justkey = os.path.basename(var)
138 justkey = os.path.basename(var)
139 # print 30 first characters from every var
139 # print 30 first characters from every var
140 print fmt % (justkey,repr(get(var,'<unavailable>'))[:50])
140 print fmt % (justkey, repr(get(var, '<unavailable>'))[:50])
141
141
142 # default action - store the variable
142 # default action - store the variable
143 else:
143 else:
@@ -145,17 +145,17 b' class StoreMagics(Magics):'
145 if len(args) > 1 and args[1].startswith('>'):
145 if len(args) > 1 and args[1].startswith('>'):
146 fnam = os.path.expanduser(args[1].lstrip('>').lstrip())
146 fnam = os.path.expanduser(args[1].lstrip('>').lstrip())
147 if args[1].startswith('>>'):
147 if args[1].startswith('>>'):
148 fil = open(fnam,'a')
148 fil = open(fnam, 'a')
149 else:
149 else:
150 fil = open(fnam,'w')
150 fil = open(fnam, 'w')
151 obj = ip.ev(args[0])
151 obj = ip.ev(args[0])
152 print "Writing '%s' (%s) to file '%s'." % (args[0],
152 print "Writing '%s' (%s) to file '%s'." % (args[0],
153 obj.__class__.__name__, fnam)
153 obj.__class__.__name__, fnam)
154
154
155
155
156 if not isinstance (obj,basestring):
156 if not isinstance (obj, basestring):
157 from pprint import pprint
157 from pprint import pprint
158 pprint(obj,fil)
158 pprint(obj, fil)
159 else:
159 else:
160 fil.write(obj)
160 fil.write(obj)
161 if not obj.endswith('\n'):
161 if not obj.endswith('\n'):
General Comments 0
You need to be logged in to leave comments. Login now