2007-05-09 19:41:50 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import os,sys
|
|
|
|
from fluents import dataset
|
|
|
|
import cfgparse, optparse
|
2007-05-09 23:52:59 +02:00
|
|
|
import re
|
2007-05-09 19:41:50 +02:00
|
|
|
|
|
|
|
PROGRAM_NAME = 'dataset'
|
|
|
|
VERSION = '0.1.0'
|
|
|
|
|
2007-05-09 23:52:59 +02:00
|
|
|
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",
|
|
|
|
|
|
|
|
|
2007-05-09 19:41:50 +02:00
|
|
|
def parse_options():
|
|
|
|
conf_files = ['/etc/fluentsrc',
|
|
|
|
os.path.join(os.environ['HOME'], '.fluents')]
|
|
|
|
|
|
|
|
cp = cfgparse.ConfigParser()
|
|
|
|
op = optparse.OptionParser()
|
|
|
|
|
2007-05-09 23:52:59 +02:00
|
|
|
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.')
|
|
|
|
|
2007-05-09 19:41:50 +02:00
|
|
|
op.add_option('-i', '--info',
|
2007-05-09 23:52:59 +02:00
|
|
|
action='store_true', default=False,
|
2007-05-09 19:41:50 +02:00
|
|
|
help='Show dataset information.')
|
|
|
|
|
2007-05-09 23:52:59 +02:00
|
|
|
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.')
|
|
|
|
|
2007-05-09 19:41:50 +02:00
|
|
|
|
|
|
|
for cf in conf_files:
|
|
|
|
if os.path.isfile(cf):
|
|
|
|
cp.add_file(cf)
|
|
|
|
|
|
|
|
return cp.parse(op)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
options, params = parse_options()
|
2007-05-09 23:52:59 +02:00
|
|
|
input = sys.stdin
|
|
|
|
output = sys.stdout
|
2007-05-09 19:41:50 +02:00
|
|
|
|
2007-05-09 23:52:59 +02:00
|
|
|
if options.info:
|
|
|
|
show_info(input)
|
2007-05-09 19:41:50 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|