"import nilmdb" doesn't do much; "import nilmdb.client" or "import nilmdb.server" is now required.tags/nilmdb-1.3.0
@@ -1,7 +1,9 @@ | |||
"""Main NilmDB import""" | |||
from nilmdb.server import NilmDB, Server | |||
from nilmdb.client import Client | |||
# These aren't imported automatically, because loading the server | |||
# stuff isn't always necessary. | |||
#from nilmdb.server import NilmDB, Server | |||
#from nilmdb.client import Client | |||
from nilmdb._version import get_versions | |||
__version__ = get_versions()['version'] | |||
@@ -2,7 +2,6 @@ | |||
"""Class for performing HTTP client requests via libcurl""" | |||
import nilmdb | |||
import nilmdb.utils | |||
import nilmdb.client.httpclient | |||
from nilmdb.client.errors import ClientError | |||
@@ -1,6 +1,5 @@ | |||
"""HTTP client library""" | |||
import nilmdb | |||
import nilmdb.utils | |||
from nilmdb.client.errors import ClientError, ServerError, Error | |||
@@ -1,6 +1,7 @@ | |||
"""Command line client functionality""" | |||
import nilmdb | |||
import nilmdb.client | |||
from nilmdb.utils.printf import * | |||
from nilmdb.utils import datetime_tz | |||
import nilmdb.utils.time | |||
@@ -84,7 +85,7 @@ class Cmdline(object): | |||
if "verify" in self.args: | |||
self.args.verify(self) | |||
self.client = nilmdb.Client(self.args.url) | |||
self.client = nilmdb.client.Client(self.args.url) | |||
# Make a test connection to make sure things work, | |||
# unless the particular command requests that we don't. | |||
@@ -1,5 +1,4 @@ | |||
from nilmdb.utils.printf import * | |||
import nilmdb | |||
import nilmdb.client | |||
from argparse import RawDescriptionHelpFormatter as raw_form | |||
@@ -1,5 +1,4 @@ | |||
from nilmdb.utils.printf import * | |||
import nilmdb | |||
import nilmdb.client | |||
from argparse import ArgumentDefaultsHelpFormatter as def_form | |||
@@ -1,4 +1,4 @@ | |||
import nilmdb | |||
import nilmdb.client | |||
from nilmdb.utils.printf import * | |||
from nilmdb.utils import human_size | |||
@@ -1,5 +1,4 @@ | |||
from nilmdb.utils.printf import * | |||
import nilmdb | |||
import nilmdb.client | |||
import nilmdb.utils.timestamper as timestamper | |||
import nilmdb.utils.time | |||
@@ -1,5 +1,4 @@ | |||
from nilmdb.utils.printf import * | |||
import nilmdb | |||
import nilmdb.client | |||
def setup(self, sub): | |||
@@ -41,8 +41,8 @@ def main(): | |||
# Create database object. Needs to be serialized before passing | |||
# to the Server. | |||
db = nilmdb.utils.serializer_proxy(nilmdb.NilmDB)(args.database, | |||
sync = not args.nosync) | |||
db = nilmdb.utils.serializer_proxy( | |||
nilmdb.server.NilmDB)(args.database, sync = not args.nosync) | |||
# Configure the server | |||
if args.quiet: | |||
@@ -4,9 +4,9 @@ | |||
# nilmdb.py, but will pull the parent nilmdb module instead. | |||
from __future__ import absolute_import | |||
from __future__ import division | |||
import nilmdb | |||
from nilmdb.utils.printf import * | |||
from nilmdb.utils.time import float_time_to_string as ftts | |||
import nilmdb.utils | |||
import os | |||
import cPickle as pickle | |||
@@ -10,7 +10,7 @@ Manages both the SQL database and the table storage backend. | |||
# Need absolute_import so that "import nilmdb" won't pull in | |||
# nilmdb.py, but will pull the parent nilmdb module instead. | |||
from __future__ import absolute_import | |||
import nilmdb | |||
import nilmdb.utils | |||
from nilmdb.utils.printf import * | |||
from nilmdb.server.interval import (Interval, DBInterval, | |||
IntervalSet, IntervalError) | |||
@@ -5,11 +5,11 @@ | |||
# This is slow! Use the C version instead. | |||
from __future__ import absolute_import | |||
import nilmdb | |||
import struct | |||
import cStringIO | |||
import itertools | |||
from . import layout as _layout | |||
import nilmdb.utils | |||
from nilmdb.utils.time import float_time_to_string as ftts | |||
ERR_UNKNOWN = 0 | |||
@@ -3,7 +3,7 @@ | |||
# Need absolute_import so that "import nilmdb" won't pull in | |||
# nilmdb.py, but will pull the nilmdb module instead. | |||
from __future__ import absolute_import | |||
import nilmdb | |||
import nilmdb.server | |||
from nilmdb.utils.printf import * | |||
from nilmdb.server.errors import NilmDBError | |||
@@ -1,6 +1,8 @@ | |||
# -*- coding: utf-8 -*- | |||
import nilmdb | |||
import nilmdb.server | |||
import nilmdb.client | |||
from nilmdb.utils.printf import * | |||
from nilmdb.utils import timestamper | |||
from nilmdb.client import ClientError, ServerError | |||
@@ -33,11 +35,12 @@ def setup_module(): | |||
recursive_unlink(testdb) | |||
# Start web app on a custom port | |||
test_db = nilmdb.utils.serializer_proxy(nilmdb.NilmDB)(testdb, sync = False) | |||
test_server = nilmdb.Server(test_db, host = "127.0.0.1", | |||
port = 32180, stoppable = False, | |||
fast_shutdown = True, | |||
force_traceback = True) | |||
test_db = nilmdb.utils.serializer_proxy( | |||
nilmdb.server.NilmDB)(testdb, sync = False) | |||
test_server = nilmdb.server.Server(test_db, host = "127.0.0.1", | |||
port = 32180, stoppable = False, | |||
fast_shutdown = True, | |||
force_traceback = True) | |||
test_server.start(blocking = False) | |||
def teardown_module(): | |||
@@ -50,24 +53,24 @@ class TestClient(object): | |||
def test_client_01_basic(self): | |||
# Test a fake host | |||
client = nilmdb.Client(url = "http://localhost:1/") | |||
client = nilmdb.client.Client(url = "http://localhost:1/") | |||
with assert_raises(nilmdb.client.ServerError): | |||
client.version() | |||
client.close() | |||
# Then a fake URL on a real host | |||
client = nilmdb.Client(url = "http://localhost:32180/fake/") | |||
client = nilmdb.client.Client(url = "http://localhost:32180/fake/") | |||
with assert_raises(nilmdb.client.ClientError): | |||
client.version() | |||
client.close() | |||
# Now a real URL with no http:// prefix | |||
client = nilmdb.Client(url = "localhost:32180") | |||
client = nilmdb.client.Client(url = "localhost:32180") | |||
version = client.version() | |||
client.close() | |||
# Now use the real URL | |||
client = nilmdb.Client(url = testurl) | |||
client = nilmdb.client.Client(url = testurl) | |||
version = client.version() | |||
eq_(distutils.version.LooseVersion(version), | |||
distutils.version.LooseVersion(test_server.version)) | |||
@@ -79,7 +82,7 @@ class TestClient(object): | |||
def test_client_02_createlist(self): | |||
# Basic stream tests, like those in test_nilmdb:test_stream | |||
client = nilmdb.Client(url = testurl) | |||
client = nilmdb.client.Client(url = testurl) | |||
# Database starts empty | |||
eq_(client.stream_list(), []) | |||
@@ -100,7 +103,7 @@ class TestClient(object): | |||
for x in range(10): | |||
with assert_raises(ClientError): | |||
client.http.post("/stream/list") | |||
client = nilmdb.Client(url = testurl) | |||
client = nilmdb.client.Client(url = testurl) | |||
# Create three streams | |||
client.stream_create("/newton/prep", "float32_8") | |||
@@ -131,7 +134,7 @@ class TestClient(object): | |||
client.close() | |||
def test_client_03_metadata(self): | |||
client = nilmdb.Client(url = testurl) | |||
client = nilmdb.client.Client(url = testurl) | |||
# Set / get metadata | |||
eq_(client.stream_get_metadata("/newton/prep"), {}) | |||
@@ -175,7 +178,7 @@ class TestClient(object): | |||
client.close() | |||
def test_client_04_insert(self): | |||
client = nilmdb.Client(url = testurl) | |||
client = nilmdb.client.Client(url = testurl) | |||
# Limit _max_data to 1 MB, since our test file is 1.5 MB | |||
old_max_data = nilmdb.client.client.StreamInserter._max_data | |||
@@ -280,7 +283,7 @@ class TestClient(object): | |||
def test_client_05_extractremove(self): | |||
# Misc tests for extract and remove. Most of them are in test_cmdline. | |||
client = nilmdb.Client(url = testurl) | |||
client = nilmdb.client.Client(url = testurl) | |||
for x in client.stream_extract("/newton/prep", 999123, 999124): | |||
raise AssertionError("shouldn't be any data for this request") | |||
@@ -296,7 +299,7 @@ class TestClient(object): | |||
def test_client_06_generators(self): | |||
# A lot of the client functionality is already tested by test_cmdline, | |||
# but this gets a bit more coverage that cmdline misses. | |||
client = nilmdb.Client(url = testurl) | |||
client = nilmdb.client.Client(url = testurl) | |||
# Trigger a client error in generator | |||
start = datetime_tz.datetime_tz.smartparse("20120323T2000") | |||
@@ -332,7 +335,7 @@ class TestClient(object): | |||
# Pokes around in client.http internals a bit to look at the | |||
# response headers. | |||
client = nilmdb.Client(url = testurl) | |||
client = nilmdb.client.Client(url = testurl) | |||
http = client.http | |||
# Use a warning rather than returning a test failure for the | |||
@@ -371,7 +374,7 @@ class TestClient(object): | |||
# Try both with and without posting JSON | |||
for post_json in (False, True): | |||
# Basic Unicode tests | |||
client = nilmdb.Client(url = testurl, post_json = post_json) | |||
client = nilmdb.client.Client(url = testurl, post_json = post_json) | |||
# Delete streams that exist | |||
for stream in client.stream_list(): | |||
@@ -420,20 +423,20 @@ class TestClient(object): | |||
"probably not closing properly.") | |||
if test == 1: | |||
# explicit close | |||
client = nilmdb.Client(url = testurl) | |||
client = nilmdb.client.Client(url = testurl) | |||
with assert_raises(ClientError) as e: | |||
client.stream_remove("/newton/prep", 123, 120) | |||
client.close() # remove this to see the failure | |||
elif test == 2: | |||
# use the context manager | |||
with nilmdb.Client(url = testurl) as c: | |||
with nilmdb.client.Client(url = testurl) as c: | |||
with assert_raises(ClientError) as e: | |||
c.stream_remove("/newton/prep", 123, 120) | |||
def test_client_10_context(self): | |||
# Test using the client's stream insertion context manager to | |||
# insert data. | |||
client = nilmdb.Client(testurl) | |||
client = nilmdb.client.Client(testurl) | |||
client.stream_create("/context/test", "uint16_1") | |||
with client.stream_insert_context("/context/test") as ctx: | |||
@@ -513,7 +516,7 @@ class TestClient(object): | |||
# Empty intervals are ok! If recording detection events | |||
# by inserting rows into the database, we want to be able to | |||
# have an interval where no events occurred. Test them here. | |||
client = nilmdb.Client(testurl) | |||
client = nilmdb.client.Client(testurl) | |||
client.stream_create("/empty/test", "uint16_1") | |||
def info(): | |||
@@ -607,7 +610,7 @@ class TestClient(object): | |||
# Check that connections are persistent when they should be. | |||
# This is pretty hard to test; we have to poke deep into | |||
# the Requests library. | |||
with nilmdb.Client(url = testurl) as c: | |||
with nilmdb.client.Client(url = testurl) as c: | |||
def connections(): | |||
try: | |||
poolmanager = c.http._last_response.connection.poolmanager | |||
@@ -1,6 +1,7 @@ | |||
# -*- coding: utf-8 -*- | |||
import nilmdb | |||
import nilmdb.server | |||
from nilmdb.utils.printf import * | |||
import nilmdb.cmdline | |||
from nilmdb.utils import datetime_tz | |||
@@ -22,14 +23,14 @@ testdb = "tests/cmdline-testdb" | |||
def server_start(max_results = None, bulkdata_args = {}): | |||
global test_server, test_db | |||
# Start web app on a custom port | |||
test_db = nilmdb.utils.serializer_proxy(nilmdb.NilmDB)( | |||
test_db = nilmdb.utils.serializer_proxy(nilmdb.server.NilmDB)( | |||
testdb, sync = False, | |||
max_results = max_results, | |||
bulkdata_args = bulkdata_args) | |||
test_server = nilmdb.Server(test_db, host = "127.0.0.1", | |||
port = 32180, stoppable = False, | |||
fast_shutdown = True, | |||
force_traceback = False) | |||
test_server = nilmdb.server.Server(test_db, host = "127.0.0.1", | |||
port = 32180, stoppable = False, | |||
fast_shutdown = True, | |||
force_traceback = False) | |||
test_server.start(blocking = False) | |||
def server_stop(): | |||
@@ -1,4 +1,4 @@ | |||
import nilmdb | |||
import nilmdb.server | |||
from nose.tools import * | |||
from nose.tools import assert_raises | |||
@@ -29,11 +29,11 @@ class Test00Nilmdb(object): # named 00 so it runs first | |||
recursive_unlink(testdb) | |||
with assert_raises(IOError): | |||
nilmdb.NilmDB("/nonexistant-db/foo") | |||
nilmdb.server.NilmDB("/nonexistant-db/foo") | |||
db = nilmdb.NilmDB(testdb) | |||
db = nilmdb.server.NilmDB(testdb) | |||
db.close() | |||
db = nilmdb.NilmDB(testdb, sync=False) | |||
db = nilmdb.server.NilmDB(testdb, sync=False) | |||
db.close() | |||
# test timer, just to get coverage | |||
@@ -46,7 +46,7 @@ class Test00Nilmdb(object): # named 00 so it runs first | |||
in_("test: ", capture.getvalue()) | |||
def test_stream(self): | |||
db = nilmdb.NilmDB(testdb, sync=False) | |||
db = nilmdb.server.NilmDB(testdb, sync=False) | |||
eq_(db.stream_list(), []) | |||
# Bad path | |||
@@ -104,7 +104,7 @@ class Test00Nilmdb(object): # named 00 so it runs first | |||
class TestBlockingServer(object): | |||
def setUp(self): | |||
self.db = serializer_proxy(nilmdb.NilmDB)(testdb, sync=False) | |||
self.db = serializer_proxy(nilmdb.server.NilmDB)(testdb, sync=False) | |||
def tearDown(self): | |||
self.db.close() | |||
@@ -113,11 +113,11 @@ class TestBlockingServer(object): | |||
# Server should fail if the database doesn't have a "_thread_safe" | |||
# property. | |||
with assert_raises(KeyError): | |||
nilmdb.Server(object()) | |||
nilmdb.server.Server(object()) | |||
# Start web app on a custom port | |||
self.server = nilmdb.Server(self.db, host = "127.0.0.1", | |||
port = 32180, stoppable = True) | |||
self.server = nilmdb.server.Server(self.db, host = "127.0.0.1", | |||
port = 32180, stoppable = True) | |||
# Run it | |||
event = threading.Event() | |||
@@ -145,9 +145,9 @@ class TestServer(object): | |||
def setUp(self): | |||
# Start web app on a custom port | |||
self.db = serializer_proxy(nilmdb.NilmDB)(testdb, sync=False) | |||
self.server = nilmdb.Server(self.db, host = "127.0.0.1", | |||
port = 32180, stoppable = False) | |||
self.db = serializer_proxy(nilmdb.server.NilmDB)(testdb, sync=False) | |||
self.server = nilmdb.server.Server(self.db, host = "127.0.0.1", | |||
port = 32180, stoppable = False) | |||
self.server.start(blocking = False) | |||
def tearDown(self): | |||