Skip to content

Commit

Permalink
More concise input/output driver/compression flags for the main CLI g…
Browse files Browse the repository at this point in the history
…roup. Closes #56.
  • Loading branch information
Kevin Wurster committed May 28, 2015
1 parent 0773d14 commit f65d07a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
20 changes: 10 additions & 10 deletions gpsdio/cli/commands.py
Expand Up @@ -184,8 +184,8 @@ def cat(ctx, infile):
Print messages to stdout as newline JSON.
"""

with gpsdio.open(infile, driver=ctx.obj['i_driver'],
compression=ctx.obj['i_compression']) as src, \
with gpsdio.open(infile, driver=ctx.obj['i_drv'],
compression=ctx.obj['i_cmp']) as src, \
gpsdio.open('-', 'w', driver='NewlineJSON', compression=False) as dst:
for msg in src:
dst.write(msg)
Expand All @@ -201,8 +201,8 @@ def load(ctx, outfile):
"""

with gpsdio.open('-', driver='NewlineJSON', compression=False) as src, \
gpsdio.open(outfile, 'w', driver=ctx.obj['o_driver'],
compression=ctx.obj['o_compression']) as dst:
gpsdio.open(outfile, 'w', driver=ctx.obj['o_drv'],
compression=ctx.obj['o_cmp']) as dst:
for msg in src:
dst.write(msg)

Expand Down Expand Up @@ -237,8 +237,8 @@ def insp(ctx, infile, use_ipython):
"Try `help(stream)` or `next(stream)`."
))

with gpsdio.open(infile, driver=ctx.obj['i_driver'],
compression=ctx.obj['i_compression']) as src:
with gpsdio.open(infile, driver=ctx.obj['i_drv'],
compression=ctx.obj['i_cmp']) as src:

scope = {
'stream': src,
Expand Down Expand Up @@ -335,10 +335,10 @@ def etl(ctx, infile, outfile, filter_expr, sort_field):
--sort timestamp
"""

with gpsdio.open(infile, driver=ctx.obj['i_driver'],
compression=ctx.obj['i_compression']) as src, \
gpsdio.open(outfile, 'w', driver=ctx.obj['o_driver'],
compression=ctx.obj['o_compression']) as dst:
with gpsdio.open(infile, driver=ctx.obj['i_drv'],
compression=ctx.obj['i_cmp']) as src, \
gpsdio.open(outfile, 'w', driver=ctx.obj['o_drv'],
compression=ctx.obj['o_cmp']) as dst:

iterator = gpsdio.filter(src, filter_expr) if filter_expr else src
for msg in gpsdio.sort(iterator, sort_field) if sort_field else iterator:
Expand Down
18 changes: 9 additions & 9 deletions gpsdio/cli/main.py
Expand Up @@ -17,34 +17,34 @@
p for p in itertools.chain(*(iter_entry_points('gpsdio.gpsdio_commands'),
iter_entry_points('gpsdio.gpsdio_plugins')))))
@click.option(
'--input-driver', metavar='NAME', default=None,
'--i-drv', metavar='NAME', default=None,
help='Specify the input driver. Normally auto-detected from file path.',
type=click.Choice(list(gpsdio.drivers.BaseDriver.by_name.keys()))
)
@click.option(
'--output-driver', metavar='NAME', default=None,
'--o-drv', metavar='NAME', default=None,
help='Specify the output driver. Normally auto-detected from file path.',
type=click.Choice(list(gpsdio.drivers.BaseDriver.by_name.keys()))
)
@click.option(
'--input-compression', metavar='NAME', default=None,
'--i-cmp', metavar='NAME', default=None,
help='Input compression format. Normally auto-detected from file path.',
type=click.Choice(list(gpsdio.drivers.BaseCompressionDriver.by_name.keys()))
)
@click.option(
'--output-compression', metavar='NAME', default=None,
'--o-cmp', metavar='NAME', default=None,
help='Output compression format. Normally auto-detected from file path.',
type=click.Choice(list(gpsdio.drivers.BaseCompressionDriver.by_name.keys()))
)
@click.pass_context
def main_group(ctx, input_driver, output_driver, input_compression, output_compression):
def main_group(ctx, i_drv, o_drv, i_cmp, o_cmp):
"""
A collection of tools for working with the GPSD JSON format (or the same format in a msgpack container)
"""

ctx.obj = {
'i_driver': input_driver,
'o_driver': output_driver,
'i_compression': input_compression,
'o_compression': output_compression
'i_drv': i_drv,
'o_drv': o_drv,
'i_cmp': i_cmp,
'o_cmp': o_cmp
}
16 changes: 8 additions & 8 deletions tests/test_cli.py
Expand Up @@ -58,8 +58,8 @@ def test_load():
print(stdin_input)

result = CliRunner().invoke(gpsdio.cli.main_group, [
'--output-driver', 'NewlineJSON',
'--output-compression', 'GZIP',
'--o-drv', 'NewlineJSON',
'--o-cmp', 'GZIP',
'load',
dst.name

Expand All @@ -83,8 +83,8 @@ def test_etl():
# Process everything and sort on timestamp
with tempfile.NamedTemporaryFile('r+') as f:
result = CliRunner().invoke(gpsdio.cli.main_group, [
'--output-driver', driver,
'--output-compression', comp,
'--o-drv', driver,
'--o-cmp', comp,
'etl',
'--sort', 'timestamp',
TYPES_MSG_GZ_FILE,
Expand All @@ -105,8 +105,8 @@ def test_etl():
# Process everything and sort on mmsi
with tempfile.NamedTemporaryFile('r+') as f:
result = CliRunner().invoke(gpsdio.cli.main_group, [
'--output-driver', driver,
'--output-compression', comp,
'--o-drv', driver,
'--o-cmp', comp,
'etl',
'--sort', 'mmsi',
TYPES_MSG_GZ_FILE,
Expand All @@ -127,8 +127,8 @@ def test_etl():
# Filter and process
with tempfile.NamedTemporaryFile('r+') as f:
result = CliRunner().invoke(gpsdio.cli.main_group, [
'--output-driver', driver,
'--output-compression', comp,
'--o-drv', driver,
'--o-cmp', comp,
'etl',
'--filter', "lat and lon",
'--sort', 'lat',
Expand Down

0 comments on commit f65d07a

Please sign in to comment.