Browse Source

remove support: command line, client

tags/nilmdb-0.1
Jim Paris 11 years ago
parent
commit
4a47b1d04a
3 changed files with 57 additions and 1 deletions
  1. +11
    -0
      nilmdb/client.py
  2. +1
    -1
      nilmdb/cmdline/cmdline.py
  3. +45
    -0
      nilmdb/cmdline/remove.py

+ 11
- 0
nilmdb/client.py View File

@@ -96,6 +96,17 @@ class Client(object):
params = { "path": path }
return self.http.get("stream/destroy", params)

def stream_remove(self, path, start = None, end = None):
"""Remove data from the specified time range"""
params = {
"path": path
}
if start is not None:
params["start"] = float_to_string(start)
if end is not None:
params["end"] = float_to_string(end)
return self.http.get("stream/remove", params)

def stream_insert(self, path, data, start = None, end = None):
"""Insert data into a stream. data should be a file-like object
that provides ASCII data that matches the database layout for path.


+ 1
- 1
nilmdb/cmdline/cmdline.py View File

@@ -16,7 +16,7 @@ version = "0.1"
# Valid subcommands. Defined in separate files just to break
# things up -- they're still called with Cmdline as self.
subcommands = [ "info", "create", "list", "metadata", "insert", "extract",
"destroy" ]
"remove", "destroy" ]

# Import the subcommand modules. Equivalent way of doing this would be
# from . import info as cmd_info


+ 45
- 0
nilmdb/cmdline/remove.py View File

@@ -0,0 +1,45 @@
from __future__ import absolute_import
from __future__ import print_function
from nilmdb.utils.printf import *
import nilmdb.client
import sys

def setup(self, sub):
cmd = sub.add_parser("remove", help="Remove data",
description="""
Remove all data from a specified time range within a
stream.
""")
cmd.set_defaults(verify = cmd_remove_verify,
handler = cmd_remove)

group = cmd.add_argument_group("Data selection")
group.add_argument("path",
help="Path of stream, e.g. /foo/bar")
group.add_argument("-s", "--start", required=True,
metavar="TIME", type=self.arg_time,
help="Starting timestamp (free-form)")
group.add_argument("-e", "--end", required=True,
metavar="TIME", type=self.arg_time,
help="Ending timestamp (free-form)")

group = cmd.add_argument_group("Output format")
group.add_argument("-c", "--count", action="store_true",
help="Output number of data points removed")

def cmd_remove_verify(self):
if self.args.start is not None and self.args.end is not None:
if self.args.start > self.args.end:
self.parser.error("start is after end")

def cmd_remove(self):
try:
count = self.client.stream_remove(self.args.path,
self.args.start, self.args.end)
except nilmdb.client.ClientError as e:
self.die("Error removing data: %s", str(e))

if self.args.count:
printf("%d\n", count)

return 0

Loading…
Cancel
Save