From: W. Trevor King Date: Mon, 5 Jan 2009 15:09:24 +0000 (-0500) Subject: Added error specific to missing database files. X-Git-Tag: 0.4~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=80d7ee3494260fbb02bf1641c289d1af6a6428a9;p=chemdb.git Added error specific to missing database files. Better than a general assert error. --- diff --git a/text_db.py b/text_db.py index 06d31fc..0d0bf72 100644 --- a/text_db.py +++ b/text_db.py @@ -77,7 +77,8 @@ class text_db (object) : Assert that the database exists on disk. Print a reasonable error if it does not. """ - assert self.exists(), "Missing database file %s" % self.curpath() + if not self.exists(): + raise missingDatabaseFile(self.curpath()) def _open(self) : "Load the database from disk" self._assert_exists() @@ -253,6 +254,13 @@ class text_db (object) : self._records.append(['']*len(self._header)) return record +class missingDatabaseFile (Exception) : + "Specified database file does not exist" + def __init__(self, path): + msg = "Missing database file %s" % path + Exception.__init__(self, msg) + self.path = path + class indexStringError (Exception) : "invalid index string format" pass