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