Browse Source

Support wildcards for destroy

tags/nilmdb-1.5.2
Jim Paris 10 years ago
parent
commit
416a499866
2 changed files with 32 additions and 15 deletions
  1. +27
    -9
      nilmdb/cmdline/destroy.py
  2. +5
    -6
      tests/test_cmdline.py

+ 27
- 9
nilmdb/cmdline/destroy.py View File

@@ -1,5 +1,6 @@
from nilmdb.utils.printf import *
import nilmdb.client
import fnmatch

from argparse import ArgumentDefaultsHelpFormatter as def_form

@@ -10,25 +11,42 @@ def setup(self, sub):
Destroy the stream at the specified path.
The stream must be empty. All metadata
related to the stream is permanently deleted.

Wildcards and multiple paths are supported.
""")
cmd.set_defaults(handler = cmd_destroy)
group = cmd.add_argument_group("Options")
group.add_argument("-R", "--remove", action="store_true",
help="Remove all data before destroying stream")
group.add_argument("-q", "--quiet", action="store_true",
help="Don't display names when destroying "
"multiple paths")
group = cmd.add_argument_group("Required arguments")
group.add_argument("path",
help="Path of the stream to delete, e.g. /foo/bar",
group.add_argument("path", nargs='+',
help="Path of the stream to delete, e.g. /foo/bar/*",
).completer = self.complete.path
return cmd

def cmd_destroy(self):
"""Destroy stream"""
if self.args.remove:
streams = [ s[0] for s in self.client.stream_list() ]
paths = []
for path in self.args.path:
new = fnmatch.filter(streams, path)
if not new:
self.die("error: no stream matched path: %s", path)
paths.extend(new)

for path in paths:
if not self.args.quiet and len(paths) > 1:
printf("Destroying %s\n", path)

if self.args.remove:
try:
count = self.client.stream_remove(path)
except nilmdb.client.ClientError as e:
self.die("error removing data: %s", str(e))
try:
count = self.client.stream_remove(self.args.path)
self.client.stream_destroy(path)
except nilmdb.client.ClientError as e:
self.die("error removing data: %s", str(e))
try:
self.client.stream_destroy(self.args.path)
except nilmdb.client.ClientError as e:
self.die("error destroying stream: %s", str(e))
self.die("error destroying stream: %s", str(e))

+ 5
- 6
tests/test_cmdline.py View File

@@ -722,13 +722,13 @@ class TestCmdline(object):
self.contain("too few arguments")

self.fail("destroy /no/such/stream")
self.contain("No stream at path")
self.contain("no stream matched path")

self.fail("destroy -R /no/such/stream")
self.contain("No stream at path")
self.contain("no stream matched path")

self.fail("destroy asdfasdf")
self.contain("No stream at path")
self.contain("no stream matched path")

# From previous tests, we have:
self.ok("list -l")
@@ -747,7 +747,7 @@ class TestCmdline(object):
lines_(self.captured, 7)

# Destroy for real
self.ok("destroy -R /newton/prep")
self.ok("destroy -R /n*/prep")
self.ok("list -l")
self.match("/newton/raw uint16_6\n"
"/newton/zzz/rawnotch uint16_9\n")
@@ -778,8 +778,7 @@ class TestCmdline(object):
def test_12_unicode(self):
# Unicode paths.
self.ok("destroy /newton/asdf/qwer")
self.ok("destroy /newton/prep")
self.ok("destroy /newton/raw")
self.ok("destroy /newton/prep /newton/raw")
self.ok("destroy /newton/zzz")

self.ok(u"create /düsseldorf/raw uint16_6")


Loading…
Cancel
Save