Show More
@@ -40,6 +40,8 b' import UserDict' | |||||
40 | import warnings |
|
40 | import warnings | |
41 | import glob |
|
41 | import glob | |
42 |
|
42 | |||
|
43 | from sets import Set as set | |||
|
44 | ||||
43 | def gethashfile(key): |
|
45 | def gethashfile(key): | |
44 | return ("%02x" % abs(hash(key) % 256))[-2:] |
|
46 | return ("%02x" % abs(hash(key) % 256))[-2:] | |
45 |
|
47 | |||
@@ -52,6 +54,7 b' class PickleShareDB(UserDict.DictMixin):' | |||||
52 | self.root.makedirs() |
|
54 | self.root.makedirs() | |
53 | # cache has { 'key' : (obj, orig_mod_time) } |
|
55 | # cache has { 'key' : (obj, orig_mod_time) } | |
54 | self.cache = {} |
|
56 | self.cache = {} | |
|
57 | ||||
55 |
|
58 | |||
56 | def __getitem__(self,key): |
|
59 | def __getitem__(self,key): | |
57 | """ db['key'] reading """ |
|
60 | """ db['key'] reading """ |
@@ -33,13 +33,15 b" def magic_history(self, parameter_s = ''):" | |||||
33 |
|
33 | |||
34 | -g: treat the arg as a pattern to grep for in (full) history |
|
34 | -g: treat the arg as a pattern to grep for in (full) history | |
35 |
|
35 | |||
|
36 | -s: show "shadow" history | |||
36 | """ |
|
37 | """ | |
37 |
|
38 | |||
|
39 | ip = self.api | |||
38 | shell = self.shell |
|
40 | shell = self.shell | |
39 | if not shell.outputcache.do_full_cache: |
|
41 | if not shell.outputcache.do_full_cache: | |
40 | print 'This feature is only available if numbered prompts are in use.' |
|
42 | print 'This feature is only available if numbered prompts are in use.' | |
41 | return |
|
43 | return | |
42 | opts,args = self.parse_options(parameter_s,'gnt',mode='list') |
|
44 | opts,args = self.parse_options(parameter_s,'gnts',mode='list') | |
43 |
|
45 | |||
44 | if not opts.has_key('t'): |
|
46 | if not opts.has_key('t'): | |
45 | input_hist = shell.input_hist_raw |
|
47 | input_hist = shell.input_hist_raw | |
@@ -68,6 +70,20 b" def magic_history(self, parameter_s = ''):" | |||||
68 | width = len(str(final)) |
|
70 | width = len(str(final)) | |
69 | line_sep = ['','\n'] |
|
71 | line_sep = ['','\n'] | |
70 | print_nums = not opts.has_key('n') |
|
72 | print_nums = not opts.has_key('n') | |
|
73 | ||||
|
74 | found = False | |||
|
75 | if pattern is not None: | |||
|
76 | sh = ip.IP.shadowhist.all() | |||
|
77 | for idx, s in sh: | |||
|
78 | if fnmatch.fnmatch(s, pattern): | |||
|
79 | print "0%d: %s" %(idx, s) | |||
|
80 | found = True | |||
|
81 | ||||
|
82 | if found: | |||
|
83 | print "===" | |||
|
84 | print "^shadow history ends, fetch by %rep <number> (must start with 0)" | |||
|
85 | print "=== start of normal history ===" | |||
|
86 | ||||
71 | for in_num in range(init,final): |
|
87 | for in_num in range(init,final): | |
72 | inline = input_hist[in_num] |
|
88 | inline = input_hist[in_num] | |
73 | if pattern is not None and not fnmatch.fnmatch(inline, pattern): |
|
89 | if pattern is not None and not fnmatch.fnmatch(inline, pattern): | |
@@ -119,6 +135,13 b' def rep_f(self, arg):' | |||||
119 | return |
|
135 | return | |
120 |
|
136 | |||
121 | if len(args) == 1: |
|
137 | if len(args) == 1: | |
|
138 | arg = args[0] | |||
|
139 | if len(arg) > 1 and arg.startswith('0'): | |||
|
140 | # get from shadow hist | |||
|
141 | num = int(arg[1:]) | |||
|
142 | line = self.shadowhist.get(num) | |||
|
143 | ip.set_next_input(str(line)) | |||
|
144 | return | |||
122 | try: |
|
145 | try: | |
123 | num = int(args[0]) |
|
146 | num = int(args[0]) | |
124 | ip.set_next_input(str(ip.IP.input_hist_raw[num]).rstrip()) |
|
147 | ip.set_next_input(str(ip.IP.input_hist_raw[num]).rstrip()) | |
@@ -150,7 +173,7 b' class ShadowHist:' | |||||
150 | if old is not _sentinel: |
|
173 | if old is not _sentinel: | |
151 | return |
|
174 | return | |
152 | newidx = self.inc_idx() |
|
175 | newidx = self.inc_idx() | |
153 | print "new",newidx |
|
176 | #print "new",newidx # dbg | |
154 | self.db.hset('shadowhist',ent, newidx) |
|
177 | self.db.hset('shadowhist',ent, newidx) | |
155 |
|
178 | |||
156 | def all(self): |
|
179 | def all(self): | |
@@ -159,11 +182,25 b' class ShadowHist:' | |||||
159 | items.sort() |
|
182 | items.sort() | |
160 | return items |
|
183 | return items | |
161 |
|
184 | |||
|
185 | def get(self, idx): | |||
|
186 | all = self.all() | |||
|
187 | ||||
|
188 | for k, v in all: | |||
|
189 | print k,v | |||
|
190 | if k == idx: | |||
|
191 | return v | |||
|
192 | ||||
162 | def test_shist(): |
|
193 | def test_shist(): | |
163 | s = ShadowHist(ip.db) |
|
194 | from IPython.Extensions import pickleshare | |
|
195 | db = pickleshare.PickleShareDB('~/shist') | |||
|
196 | s = ShadowHist(db) | |||
164 | s.add('hello') |
|
197 | s.add('hello') | |
165 | s.add('world') |
|
198 | s.add('world') | |
|
199 | s.add('hello') | |||
|
200 | s.add('hello') | |||
|
201 | s.add('karhu') | |||
166 | print "all",s.all() |
|
202 | print "all",s.all() | |
|
203 | print s.get(2) | |||
167 |
|
204 | |||
168 | def init_ipython(ip): |
|
205 | def init_ipython(ip): | |
169 | ip.expose_magic("rep",rep_f) |
|
206 | ip.expose_magic("rep",rep_f) |
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.' | |||||
6 |
|
6 | |||
7 | This file contains all the classes and helper functions specific to IPython. |
|
7 | This file contains all the classes and helper functions specific to IPython. | |
8 |
|
8 | |||
9 |
$Id: iplib.py 24 |
|
9 | $Id: iplib.py 2440 2007-06-14 19:31:36Z vivainio $ | |
10 | """ |
|
10 | """ | |
11 |
|
11 | |||
12 | #***************************************************************************** |
|
12 | #***************************************************************************** | |
@@ -60,7 +60,7 b' from sets import Set' | |||||
60 | from pprint import pprint, pformat |
|
60 | from pprint import pprint, pformat | |
61 |
|
61 | |||
62 | # IPython's own modules |
|
62 | # IPython's own modules | |
63 | import IPython |
|
63 | #import IPython | |
64 | from IPython import Debugger,OInspect,PyColorize,ultraTB |
|
64 | from IPython import Debugger,OInspect,PyColorize,ultraTB | |
65 | from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names |
|
65 | from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names | |
66 | from IPython.FakeModule import FakeModule |
|
66 | from IPython.FakeModule import FakeModule | |
@@ -74,7 +74,7 b' from IPython.usage import cmd_line_usage,interactive_usage' | |||||
74 | from IPython.genutils import * |
|
74 | from IPython.genutils import * | |
75 | from IPython.strdispatch import StrDispatch |
|
75 | from IPython.strdispatch import StrDispatch | |
76 | import IPython.ipapi |
|
76 | import IPython.ipapi | |
77 |
|
77 | import IPython.history | ||
78 | import IPython.prefilter as prefilter |
|
78 | import IPython.prefilter as prefilter | |
79 |
|
79 | |||
80 | # Globals |
|
80 | # Globals | |
@@ -620,6 +620,7 b' class InteractiveShell(object,Magic):' | |||||
620 | print r"only has ASCII characters, e.g. c:\home" |
|
620 | print r"only has ASCII characters, e.g. c:\home" | |
621 | print "Now it is",rc.ipythondir |
|
621 | print "Now it is",rc.ipythondir | |
622 | sys.exit() |
|
622 | sys.exit() | |
|
623 | self.shadowhist = IPython.history.ShadowHist(self.db) | |||
623 |
|
624 | |||
624 |
|
625 | |||
625 | def post_config_initialization(self): |
|
626 | def post_config_initialization(self): | |
@@ -2014,8 +2015,9 b' want to merge them back into the new files.""" % locals()' | |||||
2014 | except AttributeError: |
|
2015 | except AttributeError: | |
2015 | pass # re{move,place}_history_item are new in 2.4. |
|
2016 | pass # re{move,place}_history_item are new in 2.4. | |
2016 | else: |
|
2017 | else: | |
2017 | self.input_hist_raw.append('%s\n' % line) |
|
2018 | self.input_hist_raw.append('%s\n' % line) | |
2018 |
|
2019 | |||
|
2020 | self.shadowhist.add(line) | |||
2019 | try: |
|
2021 | try: | |
2020 | lineout = self.prefilter(line,continue_prompt) |
|
2022 | lineout = self.prefilter(line,continue_prompt) | |
2021 | except: |
|
2023 | except: |
General Comments 0
You need to be logged in to leave comments.
Login now