Added -d option to get all identifiers along a single dimension.
This commit is contained in:
parent
c7bfefe358
commit
7bdfdea23b
32
bin/dataset
32
bin/dataset
@ -8,9 +8,9 @@ import re
|
||||
PROGRAM_NAME = 'dataset'
|
||||
VERSION = '0.1.0'
|
||||
|
||||
def show_info(input):
|
||||
name = "N/A"
|
||||
type = "N/A"
|
||||
def read_dataset_header(input):
|
||||
name = ""
|
||||
type = ""
|
||||
dimensions = []
|
||||
|
||||
kv_re = re.compile('^\s*#\s*(\w+)\s*:(.*)$')
|
||||
@ -34,17 +34,32 @@ def show_info(input):
|
||||
type = v
|
||||
elif k == 'dimension':
|
||||
values = v.split()
|
||||
dimensions.append((values[0], len(values) - 1))
|
||||
dimensions.append((values[0], values[1:]))
|
||||
|
||||
return (name, type, dimensions)
|
||||
|
||||
def show_info(input):
|
||||
name, type, dimensions = read_dataset_header(input)
|
||||
|
||||
print "Name: %s" % name
|
||||
print "Type: %s" % type
|
||||
print "Dimensions:",
|
||||
for i, dim in enumerate(dimensions):
|
||||
print "%s(%i)" % dim,
|
||||
dimname = dim[0]
|
||||
length = len(dim[1])
|
||||
print "%s(%i)" % (dimname, length),
|
||||
if i < len(dimensions)-1:
|
||||
print "x",
|
||||
|
||||
print
|
||||
|
||||
def list_dimension_ids(input, dimname):
|
||||
name, type, dimensions = read_dataset_header(input)
|
||||
for i, dim in enumerate(dimensions):
|
||||
name, ids = dim
|
||||
if name == dimname:
|
||||
for id in ids:
|
||||
print id
|
||||
|
||||
def parse_options():
|
||||
conf_files = ['/etc/fluentsrc',
|
||||
os.path.join(os.environ['HOME'], '.fluents')]
|
||||
@ -57,7 +72,7 @@ def parse_options():
|
||||
help='Export as CSV file.')
|
||||
|
||||
op.add_option('-d', '--dimension',
|
||||
action='store_true', default=False,
|
||||
action='store', default=None,
|
||||
help='Get all identifiers along a dimension.')
|
||||
|
||||
op.add_option('-i', '--info',
|
||||
@ -96,3 +111,6 @@ if __name__ == '__main__':
|
||||
show_info(input)
|
||||
sys.exit(0)
|
||||
|
||||
elif options.dimension != None:
|
||||
list_dimension_ids(input, options.dimension)
|
||||
|
||||
|
Reference in New Issue
Block a user