Browse Source

Test binary extract; fix bugs

tags/nilmdb-1.6.0
Jim Paris 11 years ago
parent
commit
f2a48bdb2a
2 changed files with 17 additions and 2 deletions
  1. +9
    -2
      nilmdb/cmdline/extract.py
  2. +8
    -0
      tests/test_cmdline.py

+ 9
- 2
nilmdb/cmdline/extract.py View File

@@ -1,6 +1,7 @@
from __future__ import print_function
from nilmdb.utils.printf import *
import nilmdb.client
import sys

def setup(self, sub):
cmd = sub.add_parser("extract", help="Extract data",
@@ -67,17 +68,23 @@ def cmd_extract(self):
printf("# end: %s\n", time_string(self.args.end))

printed = False
if self.args.binary:
printer = sys.stdout.write
else:
printer = print
bare = self.args.bare
count = self.args.count
for dataline in self.client.stream_extract(self.args.path,
self.args.start,
self.args.end,
self.args.count,
self.args.markup,
self.args.binary):
if self.args.bare and not self.args.count:
if bare and not count:
# Strip timestamp (first element). Doesn't make sense
# if we are only returning a count.
dataline = ' '.join(dataline.split(' ')[1:])
print(dataline)
printer(dataline)
printed = True
if not printed:
if self.args.annotate:


+ 8
- 0
tests/test_cmdline.py View File

@@ -601,6 +601,14 @@ class TestCmdline(object):
self.ok("extract -c /newton/prep --start 2000-01-01 --end 2020-01-01")
self.match("43200\n")

# test binary mode
self.fail("extract -c -B /newton/prep -s min -e max")
self.contain("binary cannot be combined")
self.fail("extract -m -B /newton/prep -s min -e max")
self.contain("binary cannot be combined")
self.ok("extract -B /newton/prep -s min -e max")
eq_(len(self.captured), 43200 * (8 + 8*4))

# markup for 3 intervals, plus extra markup lines whenever we had
# a "restart" from the nilmdb.stream_extract function
self.ok("extract -m /newton/prep --start 2000-01-01 --end 2020-01-01")


Loading…
Cancel
Save