From f1ab0facd5a2473a2af1f3ca299886fc232aa73c 2017-05-10 20:17:35 From: José Chávez Date: 2017-05-10 20:17:35 Subject: [PATCH] primer generate basic --- diff --git a/schain-cli/.gitignore b/schain-cli/.gitignore new file mode 100644 index 0000000..cc4af0d --- /dev/null +++ b/schain-cli/.gitignore @@ -0,0 +1,10 @@ +*.pyc + +dist/ +build/ +*.egg-info/ + +.tox/ +.coverage + +project.py diff --git a/schain-cli/README.md b/schain-cli/README.md new file mode 100644 index 0000000..17aec8a --- /dev/null +++ b/schain-cli/README.md @@ -0,0 +1,21 @@ +# schaing-cli + +Command Line Interface for SIGNAL CHAIN - jro + + +# Installation + +If you don't use `pipsi`, you're missing out. +Here are [installation instructions](https://github.com/mitsuhiko/pipsi#readme). + +Simply run: + + $ pipsi install . + + +# Usage + +To use it: + + $ schain-cli --help + diff --git a/schain-cli/schaincli/__init__.py b/schain-cli/schaincli/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/schain-cli/schaincli/__init__.py diff --git a/schain-cli/schaincli/cli.py b/schain-cli/schaincli/cli.py new file mode 100644 index 0000000..4ea0c2a --- /dev/null +++ b/schain-cli/schaincli/cli.py @@ -0,0 +1,43 @@ +import click +import schainpy +from schaincli import templates +import os, sys + +def print_version(ctx, param, value): + if not value or ctx.resilient_parsing: + return + click.echo(schainpy.__version__) + ctx.exit() + + +@click.command() +@click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str) +@click.argument('command', default='run', required=True) +def main(command, version): + """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY""" + if command == 'generate': + generate() + pass + elif command == 'run': + pass + elif command == 'test': + test() + pass + else: + click.echo('[ERROR] - Command not defined.') + +def generate(): + inputs = {} + inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str) + inputs['name'] = click.prompt('Name of the project', default="project", type=str) + inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True)) + inputs['startDate'] = click.prompt('Start date', default='01/01/1970', type=str) + inputs['endDate'] = click.prompt('End date', default='31/12/2017', type=str) + inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str) + inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str) + script = open(inputs['name'] + ".py", 'w') + script.write(templates.basic.format(**inputs)) + +def test(): + print templates.basic.format(name='hola', desc= 'desc', path='path', startDate='0', endDate='0') + click.echo('testing') diff --git a/schain-cli/schaincli/templates.py b/schain-cli/schaincli/templates.py new file mode 100644 index 0000000..555b0ee --- /dev/null +++ b/schain-cli/schaincli/templates.py @@ -0,0 +1,21 @@ +basic = +'''import argparse +from schainpy.controller import Project, multiSchain + +desc = "{desc}" + +controller = Project() +controller.setup(id='191', name="{name}", description=desc) + +readUnitConf = controller.addReadUnit(datatype='SpectraReader', + path="{path}", + startDate="{startDate}", + endDate="{endDate}", + startTime="{startHour}", + endTime="{endHour}", + online=0, + walk=1, + ) + +procUnitConf2 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) +''' diff --git a/schain-cli/setup.cfg b/schain-cli/setup.cfg new file mode 100644 index 0000000..5e40900 --- /dev/null +++ b/schain-cli/setup.cfg @@ -0,0 +1,2 @@ +[wheel] +universal = 1 diff --git a/schain-cli/setup.py b/schain-cli/setup.py new file mode 100644 index 0000000..898cb96 --- /dev/null +++ b/schain-cli/setup.py @@ -0,0 +1,48 @@ +""" +Command Line Interface for SIGNAL CHAIN - jro +""" +from setuptools import find_packages, setup + +dependencies = ['click'] + +setup( + name='schaincli', + version='0.1.0', + url='http://jro-dev.igp.gob.pe/rhodecode/schain', + license='BSD', + author='Jose Chavez', + author_email='jose.chavez@jro.igp.gob.pe', + description='Command Line Interface for SIGNAL CHAIN - jro', + long_description=__doc__, + packages=find_packages(exclude=['tests']), + include_package_data=True, + zip_safe=False, + platforms='any', + install_requires=dependencies, + entry_points={ + 'console_scripts': [ + 'schain-cli = schaincli.cli:main', + ], + }, + classifiers=[ + # As from http://pypi.python.org/pypi?%3Aaction=list_classifiers + # 'Development Status :: 1 - Planning', + # 'Development Status :: 2 - Pre-Alpha', + # 'Development Status :: 3 - Alpha', + 'Development Status :: 4 - Beta', + # 'Development Status :: 5 - Production/Stable', + # 'Development Status :: 6 - Mature', + # 'Development Status :: 7 - Inactive', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: POSIX', + 'Operating System :: MacOS', + 'Operating System :: Unix', + 'Operating System :: Microsoft :: Windows', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', + 'Topic :: Software Development :: Libraries :: Python Modules', + ] +) diff --git a/schain-cli/tests/__init__.py b/schain-cli/tests/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/schain-cli/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/schain-cli/tests/test_cli.py b/schain-cli/tests/test_cli.py new file mode 100644 index 0000000..62e4f30 --- /dev/null +++ b/schain-cli/tests/test_cli.py @@ -0,0 +1,29 @@ +import pytest +from click.testing import CliRunner +from schaincli import cli + + +@pytest.fixture +def runner(): + return CliRunner() + + +def test_cli(runner): + result = runner.invoke(cli.main) + assert result.exit_code == 0 + assert not result.exception + assert result.output.strip() == 'Hello, world.' + + +def test_cli_with_option(runner): + result = runner.invoke(cli.main, ['--as-cowboy']) + assert not result.exception + assert result.exit_code == 0 + assert result.output.strip() == 'Howdy, world.' + + +def test_cli_with_arg(runner): + result = runner.invoke(cli.main, ['Jicamarca']) + assert result.exit_code == 0 + assert not result.exception + assert result.output.strip() == 'Hello, Jicamarca.' diff --git a/schain-cli/tox.ini b/schain-cli/tox.ini new file mode 100644 index 0000000..c707b1f --- /dev/null +++ b/schain-cli/tox.ini @@ -0,0 +1,15 @@ +[tox] +envlist=py26, py27, py33, py34, pypy, flake8 + +[testenv] +commands=py.test --cov schain-cli {posargs} +deps= + pytest + pytest-cov + +[testenv:flake8] +basepython = python2.7 +deps = + flake8 +commands = + flake8 schain-cli tests --max-line-length=120