Skip to content
Snippets Groups Projects
Commit f580a546 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fix the docs

parent d681f75d
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,6 @@ Welcome to tempsdb's documentation!
:maxdepth: 2
:caption: Contents:
time-series
usage
exceptions
......
Time series
===========
The name of the series must be a valid name for a directory on your filesystem.
......@@ -6,6 +6,10 @@ Start off by instantiating an object
.. autoclass:: tempsdb.database.Database
:members:
You can create new databases via
.. autofunction:: tempsdb.database.create_database
Then you can create and retrieve particular series:
.. autoclass:: tempsdb.series.TimeSeries
......
......@@ -9,3 +9,6 @@ cdef class Database:
cpdef void close(self)
cpdef TimeSeries get_series(self, str name)
cpdef Database create_database(str path)
import os
import threading
from tempsdb.exceptions import DoesNotExist
from tempsdb.exceptions import DoesNotExist, AlreadyExists
from .series cimport TimeSeries
cdef class Database:
"""
A basic TempsDB object.
:param path: path to the directory with the database
"""
def __init__(self, path: str):
self.path = path
......@@ -16,16 +18,33 @@ cdef class Database:
self.lock = threading.Lock()
cpdef TimeSeries get_series(self, name: str):
cdef TimeSeries result
"""
Load and return an existing series
:param name: name of the series
:type name: str
:return: a loaded time series
:rtype: TimeSeries
:raises DoesNotExist: series does not exist
"""
cdef:
TimeSeries result
str path
if name in self.open_series:
result = self.open_series[name]
else:
path = os.path.join(self.path, name)
with self.lock:
if not os.path.isdir(os.path.join(self.path, name)):
# Check a second time due to the lock
if name in self.open_series:
return self.open_series[name]
if not os.path.isdir(path):
raise DoesNotExist('series %s does not exist' % (name, ))
self.open_series[name] = result = TimeSeries(self, name)
self.open_series[name] = result = TimeSeries(path)
return result
def __del__(self):
self.close()
cpdef void close(self):
"""
......@@ -37,3 +56,19 @@ cdef class Database:
for series in self.open_series.values():
series.close()
self.closed = True
cpdef Database create_database(str path):
"""
Creates a new, empty database
:param path: path where the DB directory will be put
:type path: str
:return: a Database object
:rtype: Database
:raises AlreadyExists: the directory exists
"""
if os.path.exists(path):
raise AlreadyExists('directory already exists')
os.mkdir(path)
return Database(path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment