Browse Source

More work on nilmtool

git-svn-id: https://bucket.mit.edu/svn/nilm/nilmdb@10674 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/bxinterval-last
Jim Paris 10 years ago
parent
commit
f29d38d9d9
4 changed files with 42 additions and 25 deletions
  1. +2
    -1
      Makefile
  2. +4
    -0
      nilmdb/client.py
  3. +35
    -23
      nilmdb/cmdline.py
  4. +1
    -1
      nilmtool.py

+ 2
- 1
Makefile View File

@@ -1,7 +1,8 @@
all: tool

tool:
python nilmtool.py --help
python nilmtool.py --help
python nilmtool.py

lint:
pylint -f parseable nilmdb


+ 4
- 0
nilmdb/client.py View File

@@ -113,6 +113,9 @@ class MyCurl(object):

class Client(object):
"""Main client interface to the Nilm database."""

client_version = "1.0"
def __init__(self, url):
self.curl = MyCurl(url)

@@ -121,6 +124,7 @@ class Client(object):
return json.dumps(data, separators=(',',':'))

def version(self):
"""Return server version"""
return self.curl.getjson("version")

def stream_list(self, path = None, layout = None):


+ 35
- 23
nilmdb/cmdline.py View File

@@ -10,35 +10,47 @@ import sys
import re
import os
import urlparse
from optparse import OptionParser, OptionGroup, OptionValueError
import argparse

version = "0.1"
version_string = sprintf("nilmtool %s, client library %s",
version, nilmdb.Client.client_version)

def parse_opts(args):
parser = OptionParser(usage="usage: %prog [options]",
version="nilmdb client script %prog " + version)
parser.add_option("-q", "--quiet", action="store_true", default=False,
dest="quiet", help="suppress unnecessary console output")
def parse_opts(argv):
parser = argparse.ArgumentParser(add_help = False)

group = OptionGroup(parser, "Server")
group.add_option("-u", "--url", action="store", dest="url",
default="http://localhost:12380/",
help="NilmDB server URL (default: %default)")
parser.add_option_group(group)
group = parser.add_argument_group("General options")
group.add_argument("-h", "--help", action='help',
help='show this help message and exit')
group.add_argument("-V", "--version", action="version",
version=version_string)
group.add_argument("-q", "--quiet", action="store_true",
help="suppress unnecessary console output")

group = OptionGroup(parser, "Stream Operations")
group.add_option("-l", "--list", action="store_true", default=False,
action="store", dest="url",
default="http://localhost:12380/",
help="NilmDB server URL (default: %default)")
parser.add_option_group(group)
group = parser.add_argument_group("Server options")
group.add_argument("-u", "--url", action="store",
default="http://localhost:12380/",
help="NilmDB server URL (default: %(default)s)")

(opt, rest) = parser.parse_args(args)

return (opt, rest)
# group.add_argument(
# parser.add_argument_group(group)

def run(args):
(opt, rest) = parse_opts(args)
# group = OptionGroup(parser, "Stream Operations")
# group.add_argument("-l", "--list", action="store_true", default=False,
# action="store", dest="url",
# default="http://localhost:12380/",
# help="NilmDB server URL (default: %default)")
# parser.add_argument_group(group)

if not opt.quiet:
printf("Server URL: %s\n", opt.url)
args = parser.parse_args(argv)

return args

def run(argv):
args = parse_opts(argv)

print args
# if not opt.quiet:
# printf("Server URL: %s\n", opt.url)

+ 1
- 1
nilmtool.py View File

@@ -3,4 +3,4 @@
import nilmdb
import sys

nilmdb.cmdline.run(args = sys.argv[1:])
nilmdb.cmdline.run(sys.argv[1:])

Loading…
Cancel
Save