diff --git a/schaincli/cli.py b/schaincli/cli.py index a9610b1..5040ae8 100644 --- a/schaincli/cli.py +++ b/schaincli/cli.py @@ -1,12 +1,13 @@ import click import schainpy import subprocess -from multiprocessing import cpu_count -from schaincli import templates -from schainpy import controller_api import os import sys import glob +from multiprocessing import cpu_count +from schaincli import templates +from schainpy import controller_api +from schainpy.utils import log def print_version(ctx, param, value): if not value or ctx.resilient_parsing: @@ -14,6 +15,7 @@ def print_version(ctx, param, value): click.echo(schainpy.__version__) ctx.exit() +cliLogger = log.makelogger('schain cli') @click.command() @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str) @@ -34,15 +36,15 @@ def main(command, nextcommand, version, xml): numberfiles = len(currentfiles) print currentfiles if numberfiles > 1: - click.echo('\x1b[6;37;41m[ERROR] - There is more than one file to run\x1b[0m') + log.error('There is more than one file to run') elif numberfiles == 1: subprocess.call(['python ' + currentfiles[0]], shell=True) else: - click.echo('\x1b[6;37;41m[ERROR] - There is no file to run.\x1b[0m') + log.error('There is no file to run.') else: subprocess.call(['python ' + nextcommand], shell=True) else: - click.echo('\x1b[6;37;41m[ERROR] - Command is not defined.\x1b[0m') + log.error('Command is not defined.') def basicInputs(): @@ -70,14 +72,13 @@ def generate(): script = open(scriptname, 'w') try: script.write(current) - click.echo('\x1b[6;37;42m[SUCCESS] Script {file} generated\x1b[0m'.format(file=scriptname)) + log.success('Script {file} generated'.format(file=scriptname)) except Exception as e: - click.echo('\x1b[6;37;41m[ERROR] I cannot create the file. Do you have writing permissions?\x1b[0m') + log.error('I cannot create the file. Do you have writing permissions?') def test(): - print templates.basic.format(name='hola', desc='desc', path='path', startDate='0', endDate='0') - click.echo('testing') + log.warning('testing') def runFromXML(filename): @@ -90,9 +91,9 @@ def runFromXML(filename): controller.start() plotterObj.start() - print "Finishing all processes ..." + cliLogger("Finishing all processes ...") controller.join(5) - print "End of script" + cliLogger("End of script") return diff --git a/schainpy/utils/colors.py b/schainpy/utils/colors.py deleted file mode 100644 index 42d4dbe..0000000 --- a/schainpy/utils/colors.py +++ /dev/null @@ -1,2 +0,0 @@ -def log(): - pass diff --git a/schainpy/utils/log.py b/schainpy/utils/log.py new file mode 100644 index 0000000..2544f8c --- /dev/null +++ b/schainpy/utils/log.py @@ -0,0 +1,46 @@ +""". + +SCHAINPY - LOG + Simple helper for log standarization + Usage: + from schainpy.utils import log + log.error('A kitten died beacuse of you') + log.warning('You are doing it wrong but what the heck, I'll allow it) + log.succes('YOU ROCK!') + To create your own logger inside your class do it like this: + from schainpy.utils import log + awesomeLogger = log.makelogger("never gonna", bg="red", fg="white") + awesomeLogger('give you up') + which will look like this: + [NEVER GONNA] - give you up + with color red as background and white as foreground. +""" + +import click + + +def warning(message): + click.echo(click.style('[WARNING] - ' + message, fg='yellow')) + pass + + +def error(message): + click.echo(click.style('[ERROR] - ' + message, bg='red', fg='white')) + pass + + +def success(message): + click.echo(click.style('[SUCESS] - ' + message, bg='green', fg='white')) + pass + + +def log(message): + click.echo('[LOG] - ' + message) + pass + + +def makelogger(topic, bg='reset', fg='reset'): + def func(message): + click.echo(click.style('[{}] - '.format(topic.upper()) + message, + bg=bg, fg=fg)) + return func diff --git a/setup.py b/setup.py index 733a287..4dc60b8 100644 --- a/setup.py +++ b/setup.py @@ -1,54 +1,56 @@ -''' +""". + Created on Jul 16, 2014 @author: Miguel Urco -''' +""" from schainpy import __version__ from setuptools import setup, Extension setup(name="schainpy", - version=__version__, - description="Python tools to read, write and process Jicamarca data", - author="Miguel Urco", - author_email="miguel.urco@jro.igp.gob.pe", - url="http://jro.igp.gob.pe", - packages = {'schainpy', - 'schainpy.model', - 'schainpy.model.data', - 'schainpy.model.graphics', - 'schainpy.model.io', - 'schainpy.model.proc', - 'schainpy.model.serializer', - 'schainpy.model.utils', - 'schainpy.gui', - 'schainpy.gui.figures', - 'schainpy.gui.viewcontroller', - 'schainpy.gui.viewer', - 'schainpy.gui.viewer.windows'}, - ext_package='schainpy', - py_modules=[''], - package_data={'': ['schain.conf.template'], - 'schainpy.gui.figures': ['*.png','*.jpg'], - }, - include_package_data=False, - entry_points={ - 'console_scripts': [ - 'schain = schaincli.cli:main', - ], - }, - scripts =['schainpy/gui/schainGUI'], - ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"])], - install_requires=[ - "scipy >= 0.14.0", - "h5py >= 2.2.1", - "matplotlib >= 1.4.2", - "pyfits >= 3.4", - "numpy >= 1.11.2", - "paramiko >= 2.1.2", - "paho-mqtt >= 1.2", - "zmq", - "fuzzywuzzy", - "click" - ], + version=__version__, + description="Python tools to read, write and process Jicamarca data", + author="Miguel Urco", + author_email="miguel.urco@jro.igp.gob.pe", + url="http://jro.igp.gob.pe", + packages={'schainpy', + 'schainpy.model', + 'schainpy.model.data', + 'schainpy.model.graphics', + 'schainpy.model.io', + 'schainpy.model.proc', + 'schainpy.model.serializer', + 'schainpy.model.utils', + 'schainpy.gui', + 'schainpy.gui.figures', + 'schainpy.gui.viewcontroller', + 'schainpy.gui.viewer', + 'schainpy.gui.viewer.windows'}, + ext_package='schainpy', + py_modules=[''], + package_data={'': ['schain.conf.template'], + 'schainpy.gui.figures': ['*.png', '*.jpg'], + }, + include_package_data=False, + entry_points={ + 'console_scripts': [ + 'schain = schaincli.cli:main', + ], + }, + scripts=['schainpy/gui/schainGUI'], + ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"])], + install_requires=[ + "scipy >= 0.14.0", + "h5py >= 2.2.1", + "matplotlib >= 1.4.2", + "pyfits >= 3.4", + "numpy >= 1.11.2", + "paramiko >= 2.1.2", + "paho-mqtt >= 1.2", + "zmq", + "fuzzywuzzy", + "click", + "colorama" + ], )