Show More
@@ -8,13 +8,7 b' import atexit' | |||||
8 | import datetime |
|
8 | import datetime | |
9 | import os |
|
9 | import os | |
10 | import re |
|
10 | import re | |
11 | try: |
|
11 | import sqlite3 | |
12 | import sqlite3 |
|
|||
13 | except ImportError: |
|
|||
14 | try: |
|
|||
15 | from pysqlite2 import dbapi2 as sqlite3 |
|
|||
16 | except ImportError: |
|
|||
17 | sqlite3 = None |
|
|||
18 | import threading |
|
12 | import threading | |
19 |
|
13 | |||
20 | from traitlets.config.configurable import LoggingConfigurable |
|
14 | from traitlets.config.configurable import LoggingConfigurable | |
@@ -49,26 +43,8 b' class DummyDB(object):' | |||||
49 | pass |
|
43 | pass | |
50 |
|
44 | |||
51 |
|
45 | |||
52 | @decorator |
|
46 | DatabaseError = sqlite3.DatabaseError | |
53 | def needs_sqlite(f, self, *a, **kw): |
|
47 | OperationalError = sqlite3.OperationalError | |
54 | """Decorator: return an empty list in the absence of sqlite.""" |
|
|||
55 | if sqlite3 is None or not self.enabled: |
|
|||
56 | return [] |
|
|||
57 | else: |
|
|||
58 | return f(self, *a, **kw) |
|
|||
59 |
|
||||
60 |
|
||||
61 | if sqlite3 is not None: |
|
|||
62 | DatabaseError = sqlite3.DatabaseError |
|
|||
63 | OperationalError = sqlite3.OperationalError |
|
|||
64 | else: |
|
|||
65 | @undoc |
|
|||
66 | class DatabaseError(Exception): |
|
|||
67 | "Dummy exception when sqlite could not be imported. Should never occur." |
|
|||
68 |
|
||||
69 | @undoc |
|
|||
70 | class OperationalError(Exception): |
|
|||
71 | "Dummy exception when sqlite could not be imported. Should never occur." |
|
|||
72 |
|
48 | |||
73 | # use 16kB as threshold for whether a corrupt history db should be saved |
|
49 | # use 16kB as threshold for whether a corrupt history db should be saved | |
74 | # that should be at least 100 entries or so |
|
50 | # that should be at least 100 entries or so | |
@@ -302,7 +278,6 b' class HistoryAccessor(HistoryAccessorBase):' | |||||
302 | return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur) |
|
278 | return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur) | |
303 | return cur |
|
279 | return cur | |
304 |
|
280 | |||
305 | @needs_sqlite |
|
|||
306 | @catch_corrupt_db |
|
281 | @catch_corrupt_db | |
307 | def get_session_info(self, session): |
|
282 | def get_session_info(self, session): | |
308 | """Get info about a session. |
|
283 | """Get info about a session. | |
@@ -558,7 +533,6 b' class HistoryManager(HistoryAccessor):' | |||||
558 | profile_dir = self.shell.profile_dir.location |
|
533 | profile_dir = self.shell.profile_dir.location | |
559 | return os.path.join(profile_dir, 'history.sqlite') |
|
534 | return os.path.join(profile_dir, 'history.sqlite') | |
560 |
|
535 | |||
561 | @needs_sqlite |
|
|||
562 | def new_session(self, conn=None): |
|
536 | def new_session(self, conn=None): | |
563 | """Get a new session number.""" |
|
537 | """Get a new session number.""" | |
564 | if conn is None: |
|
538 | if conn is None: | |
@@ -769,7 +743,6 b' class HistoryManager(HistoryAccessor):' | |||||
769 | conn.execute("INSERT INTO output_history VALUES (?, ?, ?)", |
|
743 | conn.execute("INSERT INTO output_history VALUES (?, ?, ?)", | |
770 | (self.session_number,)+line) |
|
744 | (self.session_number,)+line) | |
771 |
|
745 | |||
772 | @needs_sqlite |
|
|||
773 | def writeout_cache(self, conn=None): |
|
746 | def writeout_cache(self, conn=None): | |
774 | """Write any entries in the cache to the database.""" |
|
747 | """Write any entries in the cache to the database.""" | |
775 | if conn is None: |
|
748 | if conn is None: | |
@@ -818,7 +791,6 b' class HistorySavingThread(threading.Thread):' | |||||
818 | self.enabled = history_manager.enabled |
|
791 | self.enabled = history_manager.enabled | |
819 | atexit.register(self.stop) |
|
792 | atexit.register(self.stop) | |
820 |
|
793 | |||
821 | @needs_sqlite |
|
|||
822 | def run(self): |
|
794 | def run(self): | |
823 | # We need a separate db connection per thread: |
|
795 | # We need a separate db connection per thread: | |
824 | try: |
|
796 | try: |
General Comments 0
You need to be logged in to leave comments.
Login now