Skip to content

Commit

Permalink
Create event DB dir if non-extant.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdswinbank committed Jan 13, 2018
1 parent 467d054 commit 1599f05
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions comet/utility/event_db.py
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions comet/utility/test/test_event_db.py
Expand Up @@ -2,6 +2,7 @@
# Event database tests.

import tempfile
import time
import shutil
from multiprocessing.pool import ThreadPool
from itertools import repeat
Expand All @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions docs/history.rst
Expand Up @@ -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
-------------
Expand Down

0 comments on commit 1599f05

Please sign in to comment.