Show More
@@ -40,6 +40,8 b' import UserDict' | |||
|
40 | 40 | import warnings |
|
41 | 41 | import glob |
|
42 | 42 | |
|
43 | from sets import Set as set | |
|
44 | ||
|
43 | 45 | def gethashfile(key): |
|
44 | 46 | return ("%02x" % abs(hash(key) % 256))[-2:] |
|
45 | 47 | |
@@ -53,6 +55,7 b' class PickleShareDB(UserDict.DictMixin):' | |||
|
53 | 55 | # cache has { 'key' : (obj, orig_mod_time) } |
|
54 | 56 | self.cache = {} |
|
55 | 57 | |
|
58 | ||
|
56 | 59 | def __getitem__(self,key): |
|
57 | 60 | """ db['key'] reading """ |
|
58 | 61 | fil = self.root / key |
@@ -33,13 +33,15 b" def magic_history(self, parameter_s = ''):" | |||
|
33 | 33 | |
|
34 | 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 | 40 | shell = self.shell |
|
39 | 41 | if not shell.outputcache.do_full_cache: |
|
40 | 42 | print 'This feature is only available if numbered prompts are in use.' |
|
41 | 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 | 46 | if not opts.has_key('t'): |
|
45 | 47 | input_hist = shell.input_hist_raw |
@@ -68,6 +70,20 b" def magic_history(self, parameter_s = ''):" | |||
|
68 | 70 | width = len(str(final)) |
|
69 | 71 | line_sep = ['','\n'] |
|
70 | 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 | 87 | for in_num in range(init,final): |
|
72 | 88 | inline = input_hist[in_num] |
|
73 | 89 | if pattern is not None and not fnmatch.fnmatch(inline, pattern): |
@@ -119,6 +135,13 b' def rep_f(self, arg):' | |||
|
119 | 135 | return |
|
120 | 136 | |
|
121 | 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 | 145 | try: |
|
123 | 146 | num = int(args[0]) |
|
124 | 147 | ip.set_next_input(str(ip.IP.input_hist_raw[num]).rstrip()) |
@@ -150,7 +173,7 b' class ShadowHist:' | |||
|
150 | 173 | if old is not _sentinel: |
|
151 | 174 | return |
|
152 | 175 | newidx = self.inc_idx() |
|
153 | print "new",newidx | |
|
176 | #print "new",newidx # dbg | |
|
154 | 177 | self.db.hset('shadowhist',ent, newidx) |
|
155 | 178 | |
|
156 | 179 | def all(self): |
@@ -159,11 +182,25 b' class ShadowHist:' | |||
|
159 | 182 | items.sort() |
|
160 | 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 | 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 | 197 | s.add('hello') |
|
165 | 198 | s.add('world') |
|
199 | s.add('hello') | |
|
200 | s.add('hello') | |
|
201 | s.add('karhu') | |
|
166 | 202 | print "all",s.all() |
|
203 | print s.get(2) | |
|
167 | 204 | |
|
168 | 205 | def init_ipython(ip): |
|
169 | 206 | ip.expose_magic("rep",rep_f) |
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.' | |||
|
6 | 6 | |
|
7 | 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 | 60 | from pprint import pprint, pformat |
|
61 | 61 | |
|
62 | 62 | # IPython's own modules |
|
63 | import IPython | |
|
63 | #import IPython | |
|
64 | 64 | from IPython import Debugger,OInspect,PyColorize,ultraTB |
|
65 | 65 | from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names |
|
66 | 66 | from IPython.FakeModule import FakeModule |
@@ -74,7 +74,7 b' from IPython.usage import cmd_line_usage,interactive_usage' | |||
|
74 | 74 | from IPython.genutils import * |
|
75 | 75 | from IPython.strdispatch import StrDispatch |
|
76 | 76 | import IPython.ipapi |
|
77 | ||
|
77 | import IPython.history | |
|
78 | 78 | import IPython.prefilter as prefilter |
|
79 | 79 | |
|
80 | 80 | # Globals |
@@ -620,6 +620,7 b' class InteractiveShell(object,Magic):' | |||
|
620 | 620 | print r"only has ASCII characters, e.g. c:\home" |
|
621 | 621 | print "Now it is",rc.ipythondir |
|
622 | 622 | sys.exit() |
|
623 | self.shadowhist = IPython.history.ShadowHist(self.db) | |
|
623 | 624 | |
|
624 | 625 | |
|
625 | 626 | def post_config_initialization(self): |
@@ -2016,6 +2017,7 b' want to merge them back into the new files.""" % locals()' | |||
|
2016 | 2017 | else: |
|
2017 | 2018 | self.input_hist_raw.append('%s\n' % line) |
|
2018 | 2019 | |
|
2020 | self.shadowhist.add(line) | |
|
2019 | 2021 | try: |
|
2020 | 2022 | lineout = self.prefilter(line,continue_prompt) |
|
2021 | 2023 | except: |
General Comments 0
You need to be logged in to leave comments.
Login now