Show More
@@ -89,6 +89,11 b' class HistoryAccessor(Configurable):' | |||||
89 | PRIMARY KEY (session, line))""") |
|
89 | PRIMARY KEY (session, line))""") | |
90 | self.db.commit() |
|
90 | self.db.commit() | |
91 |
|
91 | |||
|
92 | def writeout_cache(self): | |||
|
93 | """Overridden by HistoryManager to dump the cache before certain | |||
|
94 | database lookups.""" | |||
|
95 | pass | |||
|
96 | ||||
92 | ## ------------------------------- |
|
97 | ## ------------------------------- | |
93 | ## Methods for retrieving history: |
|
98 | ## Methods for retrieving history: | |
94 | ## ------------------------------- |
|
99 | ## ------------------------------- | |
@@ -119,7 +124,6 b' class HistoryAccessor(Configurable):' | |||||
119 | return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur) |
|
124 | return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur) | |
120 | return cur |
|
125 | return cur | |
121 |
|
126 | |||
122 |
|
||||
123 | def get_session_info(self, session=0): |
|
127 | def get_session_info(self, session=0): | |
124 | """get info about a session |
|
128 | """get info about a session | |
125 |
|
129 | |||
@@ -146,7 +150,6 b' class HistoryAccessor(Configurable):' | |||||
146 | query = "SELECT * from sessions where session == ?" |
|
150 | query = "SELECT * from sessions where session == ?" | |
147 | return self.db.execute(query, (session,)).fetchone() |
|
151 | return self.db.execute(query, (session,)).fetchone() | |
148 |
|
152 | |||
149 |
|
||||
150 | def get_tail(self, n=10, raw=True, output=False, include_latest=False): |
|
153 | def get_tail(self, n=10, raw=True, output=False, include_latest=False): | |
151 | """Get the last n lines from the history database. |
|
154 | """Get the last n lines from the history database. | |
152 |
|
155 | |||
@@ -198,15 +201,14 b' class HistoryAccessor(Configurable):' | |||||
198 | self.writeout_cache() |
|
201 | self.writeout_cache() | |
199 | return self._run_sql("WHERE %s GLOB ?" % tosearch, (pattern,), |
|
202 | return self._run_sql("WHERE %s GLOB ?" % tosearch, (pattern,), | |
200 | raw=raw, output=output) |
|
203 | raw=raw, output=output) | |
201 |
|
204 | |||
202 |
def get_range(self, session |
|
205 | def get_range(self, session, start=1, stop=None, raw=True,output=False): | |
203 | """Retrieve input by session. |
|
206 | """Retrieve input by session. | |
204 |
|
207 | |||
205 | Parameters |
|
208 | Parameters | |
206 | ---------- |
|
209 | ---------- | |
207 | session : int |
|
210 | session : int | |
208 |
Session number to retrieve. |
|
211 | Session number to retrieve. | |
209 | numbers count back from current session, so -1 is previous session. |
|
|||
210 | start : int |
|
212 | start : int | |
211 | First line to retrieve. |
|
213 | First line to retrieve. | |
212 | stop : int |
|
214 | stop : int | |
@@ -226,11 +228,6 b' class HistoryAccessor(Configurable):' | |||||
226 | (session, line, input) if output is False, or |
|
228 | (session, line, input) if output is False, or | |
227 | (session, line, (input, output)) if output is True. |
|
229 | (session, line, (input, output)) if output is True. | |
228 | """ |
|
230 | """ | |
229 | if session == 0 or session==self.session_number: # Current session |
|
|||
230 | return self._get_range_session(start, stop, raw, output) |
|
|||
231 | if session < 0: |
|
|||
232 | session += self.session_number |
|
|||
233 |
|
||||
234 | if stop: |
|
231 | if stop: | |
235 | lineclause = "line >= ? AND line < ?" |
|
232 | lineclause = "line >= ? AND line < ?" | |
236 | params = (session, start, stop) |
|
233 | params = (session, start, stop) | |
@@ -398,6 +395,39 b' class HistoryManager(HistoryAccessor):' | |||||
398 | else: |
|
395 | else: | |
399 | line = input_hist[i] |
|
396 | line = input_hist[i] | |
400 | yield (0, i, line) |
|
397 | yield (0, i, line) | |
|
398 | ||||
|
399 | def get_range(self, session, start=1, stop=None, raw=True,output=False): | |||
|
400 | """Retrieve input by session. | |||
|
401 | ||||
|
402 | Parameters | |||
|
403 | ---------- | |||
|
404 | session : int | |||
|
405 | Session number to retrieve. The current session is 0, and negative | |||
|
406 | numbers count back from current session, so -1 is previous session. | |||
|
407 | start : int | |||
|
408 | First line to retrieve. | |||
|
409 | stop : int | |||
|
410 | End of line range (excluded from output itself). If None, retrieve | |||
|
411 | to the end of the session. | |||
|
412 | raw : bool | |||
|
413 | If True, return untranslated input | |||
|
414 | output : bool | |||
|
415 | If True, attempt to include output. This will be 'real' Python | |||
|
416 | objects for the current session, or text reprs from previous | |||
|
417 | sessions if db_log_output was enabled at the time. Where no output | |||
|
418 | is found, None is used. | |||
|
419 | ||||
|
420 | Returns | |||
|
421 | ------- | |||
|
422 | An iterator over the desired lines. Each line is a 3-tuple, either | |||
|
423 | (session, line, input) if output is False, or | |||
|
424 | (session, line, (input, output)) if output is True. | |||
|
425 | """ | |||
|
426 | if session <= 0: | |||
|
427 | session += self.session_number | |||
|
428 | if session==self.session_number: # Current session | |||
|
429 | return self._get_range_session(start, stop, raw, output) | |||
|
430 | return super(HistoryManager, self).get_range(session, start, stop, raw, output) | |||
401 |
|
431 | |||
402 | ## ---------------------------- |
|
432 | ## ---------------------------- | |
403 | ## Methods for storing history: |
|
433 | ## Methods for storing history: |
General Comments 0
You need to be logged in to leave comments.
Login now