From 1599f053a24fde408b93acde155512239155f314 Mon Sep 17 00:00:00 2001 From: John Swinbank Date: Sat, 13 Jan 2018 08:06:36 -0800 Subject: [PATCH] Create event DB dir if non-extant. --- comet/utility/event_db.py | 2 ++ comet/utility/test/test_event_db.py | 8 ++++++++ docs/history.rst | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/comet/utility/event_db.py b/comet/utility/event_db.py index c0f6856..dfd316f 100644 --- a/comet/utility/event_db.py +++ b/comet/utility/event_db.py @@ -22,6 +22,8 @@ class Event_DB(object): def __init__(self, root): + if not os.path.exists(root): + os.makedirs(root) self.root = root self.databases = defaultdict(Lock) diff --git a/comet/utility/test/test_event_db.py b/comet/utility/test/test_event_db.py index 1386d1f..73e43fd 100644 --- a/comet/utility/test/test_event_db.py +++ b/comet/utility/test/test_event_db.py @@ -2,6 +2,7 @@ # Event database tests. import tempfile +import time import shutil from multiprocessing.pool import ThreadPool from itertools import repeat @@ -17,6 +18,13 @@ def setUp(self): self.event_db = Event_DB(self.event_db_dir) self.event = DummyEvent() + def test_non_existing_dir(self): + # If the root for the Event_DB doesn't exist, we should create it. + # Note the relative path means that this DB will be created in the + # _trial_temp directory. + event_db = Event_DB("event_db_test_%s" % (time.time(),)) + self.assertTrue(event_db.check_event(self.event)) + def test_unseen(self): # Unseen event -> return True self.assertTrue(self.event_db.check_event(self.event)) diff --git a/docs/history.rst b/docs/history.rst index 50ceb33..a992cf3 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -30,11 +30,16 @@ In Development - Log the return code of failed external commands at level ``WARN``. Log standard output and error at level ``DEBUG``. +- Automatically create the event DB directory if it doesn't exist. Thanks to + Tim Staley for the suggestion. (`GitHub #54`_, `GitHub #55`_) + .. _does not fully support Python 3: https://twistedmatrix.com/trac/milestone/Python-3.x .. _Twisted 16.0: http://labs.twistedmatrix.com/2016/03/twisted-160-released.html .. _GitHub #10: https://github.com/jdswinbank/Comet/issues/10 .. _GitHub #39: https://github.com/jdswinbank/Comet/issues/39 .. _GitHub #41: https://github.com/jdswinbank/Comet/issues/41 +.. _GitHub #41: https://github.com/jdswinbank/Comet/issues/54 +.. _GitHub #41: https://github.com/jdswinbank/Comet/issues/55 Version 2.0.x -------------