##// END OF EJS Templates
Allow history database access without a shell.
Thomas Kluyver -
Show More
@@ -89,6 +89,11 b' class HistoryAccessor(Configurable):'
89 89 PRIMARY KEY (session, line))""")
90 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 98 ## Methods for retrieving history:
94 99 ## -------------------------------
@@ -119,7 +124,6 b' class HistoryAccessor(Configurable):'
119 124 return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur)
120 125 return cur
121 126
122
123 127 def get_session_info(self, session=0):
124 128 """get info about a session
125 129
@@ -146,7 +150,6 b' class HistoryAccessor(Configurable):'
146 150 query = "SELECT * from sessions where session == ?"
147 151 return self.db.execute(query, (session,)).fetchone()
148 152
149
150 153 def get_tail(self, n=10, raw=True, output=False, include_latest=False):
151 154 """Get the last n lines from the history database.
152 155
@@ -198,15 +201,14 b' class HistoryAccessor(Configurable):'
198 201 self.writeout_cache()
199 202 return self._run_sql("WHERE %s GLOB ?" % tosearch, (pattern,),
200 203 raw=raw, output=output)
201
202 def get_range(self, session=0, start=1, stop=None, raw=True,output=False):
204
205 def get_range(self, session, start=1, stop=None, raw=True,output=False):
203 206 """Retrieve input by session.
204 207
205 208 Parameters
206 209 ----------
207 210 session : int
208 Session number to retrieve. The current session is 0, and negative
209 numbers count back from current session, so -1 is previous session.
211 Session number to retrieve.
210 212 start : int
211 213 First line to retrieve.
212 214 stop : int
@@ -226,11 +228,6 b' class HistoryAccessor(Configurable):'
226 228 (session, line, input) if output is False, or
227 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 231 if stop:
235 232 lineclause = "line >= ? AND line < ?"
236 233 params = (session, start, stop)
@@ -398,6 +395,39 b' class HistoryManager(HistoryAccessor):'
398 395 else:
399 396 line = input_hist[i]
400 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 433 ## Methods for storing history:
General Comments 0
You need to be logged in to leave comments. Login now