##// END OF EJS Templates
sprinkled UsageError around
vivainio -
Show More
@@ -1,7 +1,7 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 2747 2007-09-08 14:01:45Z vivainio $"""
4 $Id: Magic.py 2748 2007-09-08 14:32:40Z vivainio $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -60,7 +60,7 b' from IPython.genutils import *'
60 60 from IPython import platutils
61 61 import IPython.generics
62 62 import IPython.ipapi
63
63 from IPython.ipapi import UsageError
64 64 #***************************************************************************
65 65 # Utility functions
66 66 def on_off(tag):
@@ -349,7 +349,7 b' license. To use profiling, please install"python2.3-profiler" from non-free.""")'
349 349 try:
350 350 opts,args = getopt(argv,opt_str,*long_opts)
351 351 except GetoptError,e:
352 raise GetoptError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
352 raise UsageError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
353 353 " ".join(long_opts)))
354 354 for o,a in opts:
355 355 if o.startswith('--'):
@@ -1895,7 +1895,11 b' Currently the magic system has the following functions:\\n"""'
1895 1895 macs = [k for k,v in self.shell.user_ns.items() if isinstance(v, Macro)]
1896 1896 macs.sort()
1897 1897 return macs
1898 if len(args) == 1:
1899 raise UsageError(
1900 "%macro insufficient args; usage '%macro name n1-n2 n3-4...")
1898 1901 name,ranges = args[0], args[1:]
1902
1899 1903 #print 'rng',ranges # dbg
1900 1904 lines = self.extract_input_slices(ranges,opts.has_key('r'))
1901 1905 macro = Macro(lines)
@@ -2272,7 +2276,8 b' Currently the magic system has the following functions:\\n"""'
2272 2276
2273 2277 new_scheme = parameter_s.strip()
2274 2278 if not new_scheme:
2275 print 'You must specify a color scheme.'
2279 raise UsageError(
2280 "%colors: you must specify a color scheme. See '%colors?'")
2276 2281 return
2277 2282 # local shortcut
2278 2283 shell = self.shell
@@ -2613,8 +2618,7 b' Defaulting color scheme to \'NoColor\'"""'
2613 2618 try:
2614 2619 ps = self.shell.user_ns['_dh'][-2]
2615 2620 except IndexError:
2616 print 'No previous directory to change to.'
2617 return
2621 raise UsageError('%cd -: No previous directory to change to.')
2618 2622 # jump to bookmark if needed
2619 2623 else:
2620 2624 if not os.path.isdir(ps) or opts.has_key('b'):
@@ -2626,9 +2630,8 b' Defaulting color scheme to \'NoColor\'"""'
2626 2630 ps = target
2627 2631 else:
2628 2632 if opts.has_key('b'):
2629 error("Bookmark '%s' not found. "
2633 raise UsageError("Bookmark '%s' not found. "
2630 2634 "Use '%%bookmark -l' to see your bookmarks." % ps)
2631 return
2632 2635
2633 2636 # at this point ps should point to the target dir
2634 2637 if ps:
@@ -2682,7 +2685,7 b' Defaulting color scheme to \'NoColor\'"""'
2682 2685 """Change to directory popped off the top of the stack.
2683 2686 """
2684 2687 if not self.shell.dir_stack:
2685 raise IPython.ipapi.UsageError("%popd on empty stack")
2688 raise UsageError("%popd on empty stack")
2686 2689 top = self.shell.dir_stack.pop(0)
2687 2690 self.magic_cd(top)
2688 2691 print "popd ->",top
@@ -2984,8 +2987,7 b' Defaulting color scheme to \'NoColor\'"""'
2984 2987
2985 2988 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2986 2989 if len(args) > 2:
2987 error('You can only give at most two arguments')
2988 return
2990 raise UsageError("%bookmark: too many arguments")
2989 2991
2990 2992 bkms = self.db.get('bookmarks',{})
2991 2993
@@ -2993,12 +2995,15 b' Defaulting color scheme to \'NoColor\'"""'
2993 2995 try:
2994 2996 todel = args[0]
2995 2997 except IndexError:
2996 error('You must provide a bookmark to delete')
2998 raise UsageError(
2999 "%bookmark -d: must provide a bookmark to delete")
2997 3000 else:
2998 3001 try:
2999 3002 del bkms[todel]
3000 except:
3001 error("Can't delete bookmark '%s'" % todel)
3003 except KeyError:
3004 raise UsageError(
3005 "%%bookmark -d: Can't delete bookmark '%s'" % todel)
3006
3002 3007 elif opts.has_key('r'):
3003 3008 bkms = {}
3004 3009 elif opts.has_key('l'):
@@ -3014,7 +3019,7 b' Defaulting color scheme to \'NoColor\'"""'
3014 3019 print fmt % (bk,bkms[bk])
3015 3020 else:
3016 3021 if not args:
3017 error("You must specify the bookmark name")
3022 raise UsageError("%bookmark: You must specify the bookmark name")
3018 3023 elif len(args)==1:
3019 3024 bkms[args[0]] = os.getcwd()
3020 3025 elif len(args)==2:
@@ -3,6 +3,11 b''
3 3 * Magic.py (%pushd, %popd, %dirs): Fix dir stack - push *current*
4 4 directory, not the target directory.
5 5
6 * ipapi.py, Magic.py, iplib.py: Add ipapi.UsageError, a lighter weight
7 exception that won't print the tracebacks. Switched many magics to
8 raise them on error situations, also GetoptError is not printed
9 anymore.
10
6 11 2007-09-07 Ville Vainio <vivainio@gmail.com>
7 12
8 13 * iplib.py: do not auto-alias "dir", it screws up other dir auto
General Comments 0
You need to be logged in to leave comments. Login now