##// END OF EJS Templates
log history db failure before calling init_db...
Min RK -
Show More
@@ -1,18 +1,10 b''
1 """ History related magics and functionality """
1 """ History related magics and functionality """
2 #-----------------------------------------------------------------------------
3 # Copyright (C) 2010-2011 The IPython Development Team.
4 #
5 # Distributed under the terms of the BSD License.
6 #
7 # The full license is in the file COPYING.txt, distributed with this software.
8 #-----------------------------------------------------------------------------
9
2
10 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
11 # Imports
4 # Distributed under the terms of the Modified BSD License.
12 #-----------------------------------------------------------------------------
5
13 from __future__ import print_function
6 from __future__ import print_function
14
7
15 # Stdlib imports
16 import atexit
8 import atexit
17 import datetime
9 import datetime
18 import os
10 import os
@@ -24,9 +16,9 b' except ImportError:'
24 from pysqlite2 import dbapi2 as sqlite3
16 from pysqlite2 import dbapi2 as sqlite3
25 except ImportError:
17 except ImportError:
26 sqlite3 = None
18 sqlite3 = None
19 import sys
27 import threading
20 import threading
28
21
29 # Our own packages
30 from traitlets.config.configurable import LoggingConfigurable
22 from traitlets.config.configurable import LoggingConfigurable
31 from decorator import decorator
23 from decorator import decorator
32 from IPython.utils.decorators import undoc
24 from IPython.utils.decorators import undoc
@@ -88,15 +80,15 b' def catch_corrupt_db(f, self, *a, **kw):'
88 """
80 """
89 try:
81 try:
90 return f(self, *a, **kw)
82 return f(self, *a, **kw)
91 except (DatabaseError, OperationalError):
83 except (DatabaseError, OperationalError) as e:
92 if os.path.isfile(self.hist_file):
84 if os.path.isfile(self.hist_file):
93 # Try to move the file out of the way
85 # Try to move the file out of the way
94 base,ext = os.path.splitext(self.hist_file)
86 base,ext = os.path.splitext(self.hist_file)
95 newpath = base + '-corrupt' + ext
87 newpath = base + '-corrupt' + ext
96 os.rename(self.hist_file, newpath)
88 os.rename(self.hist_file, newpath)
89 print("ERROR! History file wasn't a valid SQLite database (%s)." % e,
90 "It was moved to %s" % newpath, "and a new file created.", file=sys.stderr)
97 self.init_db()
91 self.init_db()
98 print("ERROR! History file wasn't a valid SQLite database.",
99 "It was moved to %s" % newpath, "and a new file created.")
100 return []
92 return []
101
93
102 else:
94 else:
General Comments 0
You need to be logged in to leave comments. Login now