Piping information through dataset -i works. Added names of planned features
to the dataset script.
This commit is contained in:
parent
7272eb63d2
commit
1ab558248c
73
bin/dataset
73
bin/dataset
|
@ -3,10 +3,48 @@
|
|||
import os,sys
|
||||
from fluents import dataset
|
||||
import cfgparse, optparse
|
||||
import re
|
||||
|
||||
PROGRAM_NAME = 'dataset'
|
||||
VERSION = '0.1.0'
|
||||
|
||||
def show_info(input):
|
||||
name = "N/A"
|
||||
type = "N/A"
|
||||
dimensions = []
|
||||
|
||||
kv_re = re.compile('^\s*#\s*(\w+)\s*:(.*)$')
|
||||
|
||||
lines = []
|
||||
line = input.readline()
|
||||
while line.startswith('#'):
|
||||
lines.append(line)
|
||||
line = input.readline()
|
||||
|
||||
for line in lines:
|
||||
match = kv_re.match(line)
|
||||
if not match:
|
||||
continue
|
||||
k, v = match.groups()
|
||||
k = k.strip()
|
||||
|
||||
if k == 'name':
|
||||
name = v
|
||||
elif k == 'type':
|
||||
type = v
|
||||
elif k == 'dimension':
|
||||
values = v.split()
|
||||
dimensions.append((values[0], len(values) - 1))
|
||||
|
||||
print "Name: %s" % name
|
||||
print "Type: %s" % type
|
||||
print "Dimensions:",
|
||||
for i, dim in enumerate(dimensions):
|
||||
print "%s(%i)" % dim,
|
||||
if i < len(dimensions)-1:
|
||||
print "x",
|
||||
|
||||
|
||||
def parse_options():
|
||||
conf_files = ['/etc/fluentsrc',
|
||||
os.path.join(os.environ['HOME'], '.fluents')]
|
||||
|
@ -14,12 +52,34 @@ def parse_options():
|
|||
cp = cfgparse.ConfigParser()
|
||||
op = optparse.OptionParser()
|
||||
|
||||
op.add_option('-c', '--csv',
|
||||
action='store_true', default=False,
|
||||
help='Export as CSV file.')
|
||||
|
||||
op.add_option('-d', '--dimension',
|
||||
action='store_true', default=False,
|
||||
help='Get all identifiers along a dimension.')
|
||||
|
||||
op.add_option('-i', '--info',
|
||||
action='store_true',
|
||||
default=False,
|
||||
action='store_true', default=False,
|
||||
help='Show dataset information.')
|
||||
|
||||
# op.add_option('-
|
||||
op.add_option('-l', '--longinfo',
|
||||
action='store_true', default=False,
|
||||
help='Display more information than -i.')
|
||||
|
||||
op.add_option('-o', '--output-file',
|
||||
action='store_true', default=False,
|
||||
help='Send output to file instead of stdout.')
|
||||
|
||||
op.add_option('-t', '--transpose',
|
||||
action='store_true', default=False,
|
||||
help='Transpose dataset.')
|
||||
|
||||
op.add_option('-y', '--change-type',
|
||||
action='store_true', default=False,
|
||||
help='Set new dataset type.')
|
||||
|
||||
|
||||
for cf in conf_files:
|
||||
if os.path.isfile(cf):
|
||||
|
@ -29,9 +89,10 @@ def parse_options():
|
|||
|
||||
if __name__ == '__main__':
|
||||
options, params = parse_options()
|
||||
input = sys.stdin
|
||||
output = sys.stdout
|
||||
|
||||
if options.help:
|
||||
print_help()
|
||||
if options.info:
|
||||
show_info(input)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
|
Reference in New Issue