Browse Source

Allow arguments to be passed in as a list to main() functions

tags/nilmtools-1.0
Jim Paris 9 years ago
parent
commit
a56dc22030
5 changed files with 15 additions and 15 deletions
  1. +2
    -2
      src/copy_.py
  2. +3
    -2
      src/decimate.py
  3. +4
    -4
      src/filter.py
  4. +4
    -5
      src/insert.py
  5. +2
    -2
      src/sinefit.py

+ 2
- 2
src/copy_.py View File

@@ -5,13 +5,13 @@ import nilmdb.client
import numpy as np
import sys

def main():
def main(argv = None):
f = nilmtools.filter.Filter()
parser = f.setup_parser("Copy a stream")

# Parse arguments
try:
args = f.parse_args()
args = f.parse_args(argv)
except nilmtools.filter.MissingDestination as e:
print "Source is %s (%s)" % (e.src.path, e.src.layout)
print "Destination %s doesn't exist" % (e.dest.path)


+ 3
- 2
src/decimate.py View File

@@ -5,15 +5,16 @@ import nilmdb.client
import numpy as np
import operator

def main():
def main(argv = None):
f = nilmtools.filter.Filter()
parser = f.setup_parser("Decimate a stream")
group = parser.add_argument_group("Decimate options")
group.add_argument('-f', '--factor', action='store', default=4, type=int,
help='Decimation factor (default: %(default)s)')

# Parse arguments
try:
args = f.parse_args()
args = f.parse_args(argv)
except nilmtools.filter.MissingDestination as e:
# If no destination, suggest how to create it by figuring out
# a recommended layout.


+ 4
- 4
src/filter.py View File

@@ -114,8 +114,8 @@ class Filter(object):
timestamp_to_human(interval.start),
timestamp_to_human(interval.end))

def parse_args(self):
args = self._parser.parse_args()
def parse_args(self, argv = None):
args = self._parser.parse_args(argv or sys.argv)

if args.dest_url is None:
args.dest_url = args.url
@@ -372,12 +372,12 @@ class Filter(object):
if old_array.shape[0] != 0:
function(old_array, interval, args, insert_function, True)

def main():
def main(argv = None):
# This is just a dummy function; actual filters can use the other
# functions to prepare stuff, and then do something with the data.
f = Filter()
parser = f.setup_parser()
args = f.parse_args()
args = f.parse_args(argv)
for i in f.intervals():
print "Generic filter: need to handle", f.interval_string(i)



+ 4
- 5
src/insert.py View File

@@ -18,7 +18,7 @@ class ParseError(Exception):
msg = filename + ": " + error
super(ParseError, self).__init__(msg)

def parse_args():
def parse_args(argv = None):
parser = argparse.ArgumentParser(
formatter_class = argparse.RawDescriptionHelpFormatter,
version = nilmtools.__version__,
@@ -44,16 +44,15 @@ def parse_args():
parser.add_argument("infile", type=argparse.FileType('r'), nargs='*',
default=[sys.stdin],
help="Input files (default: stdin)")
args = parser.parse_args()
args = parser.parse_args(argv or sys.argv)

printf("Stream path: %s\n", args.path)
printf(" Data rate: %s Hz\n", repr(args.rate))

return args

def main(args = None):
if args is None:
args = parse_args()
def main(argv = None):
args = parse_args(argv)

client = nilmdb.client.Client(args.url)



+ 2
- 2
src/sinefit.py View File

@@ -9,7 +9,7 @@ from scipy import *
#import pylab as p
import operator

def main():
def main(argv = None):
f = nilmtools.filter.Filter()
parser = f.setup_parser("Sine wave fitting")
group = parser.add_argument_group("Sine fit options")
@@ -21,7 +21,7 @@ def main():

# Parse arguments
try:
args = f.parse_args()
args = f.parse_args(argv)
except nilmtools.filter.MissingDestination as e:
rec = "float32_4"
print "Source is %s (%s)" % (e.src.path, e.src.layout)


Loading…
Cancel
Save