Permalink
Browse files

New command line structure.

  • Loading branch information...
castelao committed Nov 13, 2016
1 parent f6db784 commit 6c8ca8f74eda7f9d2f73d89fb34dd308c43024f2
Showing with 57 additions and 1 deletion.
  1. +2 −1 requirements.txt
  2. +55 −0 seabird/cli.py
View
@@ -1 +1,2 @@
numpy==1.11.1
numpy>=1.11.1
Click==6.6
View
@@ -0,0 +1,55 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Command line utilities for package Seabird
"""
import click
from seabird.exceptions import CNVError
from .cnv import fCNV
from .netcdf import cnv2nc
@click.group()
def cli():
""" Utilities for seabird files
"""
pass
@cli.command(name='cnvdump')
@click.argument('inputfilename', type=click.Path(exists=True))
def dump(inputfilename):
""" Dump the contents of a CNV file
"""
try:
data = fCNV(inputfilename)
except CNVError as e:
print("\033[91m%s\033[0m" % e.msg)
import sys; sys.exit()
except:
raise
print("file: %s" % inputfilename)
print("Global attributes")
for a in sorted(data.attributes.keys()):
print("\t\033[93m%s\033[0m: %s" % (a, data.attributes[a]))
print("\nVariabes")
for k in data.keys():
print("\033[91m%s\033[0m" % k)
for a in data[k].attributes.keys():
print("\t\033[93m%s\033[0m: %s" % (a, data[k].attributes[a]))
@cli.command(name='cnv2nc')
@click.option('--outputfilename', default=None,
help='The output netCDF filename.')
@click.argument('inputfilename', type=click.Path(exists=True))
def nc(inputfilename, outputfilename):
""" Export a CNV file as a netCDF
"""
if outputfilename is None:
outputfilename = inputfilename.replace('.cnv','.nc')
click.echo('Saving on %s' % outputfilename)
data = fCNV(inputfilename)
cnv2nc(data, outputfilename)

0 comments on commit 6c8ca8f

Please sign in to comment.