##// END OF EJS Templates
added log helper
José Chávez -
r943:0a4a147186e4
parent child
Show More
@@ -0,0 +1,46
1 """.
2
3 SCHAINPY - LOG
4 Simple helper for log standarization
5 Usage:
6 from schainpy.utils import log
7 log.error('A kitten died beacuse of you')
8 log.warning('You are doing it wrong but what the heck, I'll allow it)
9 log.succes('YOU ROCK!')
10 To create your own logger inside your class do it like this:
11 from schainpy.utils import log
12 awesomeLogger = log.makelogger("never gonna", bg="red", fg="white")
13 awesomeLogger('give you up')
14 which will look like this:
15 [NEVER GONNA] - give you up
16 with color red as background and white as foreground.
17 """
18
19 import click
20
21
22 def warning(message):
23 click.echo(click.style('[WARNING] - ' + message, fg='yellow'))
24 pass
25
26
27 def error(message):
28 click.echo(click.style('[ERROR] - ' + message, bg='red', fg='white'))
29 pass
30
31
32 def success(message):
33 click.echo(click.style('[SUCESS] - ' + message, bg='green', fg='white'))
34 pass
35
36
37 def log(message):
38 click.echo('[LOG] - ' + message)
39 pass
40
41
42 def makelogger(topic, bg='reset', fg='reset'):
43 def func(message):
44 click.echo(click.style('[{}] - '.format(topic.upper()) + message,
45 bg=bg, fg=fg))
46 return func
@@ -1,12 +1,13
1 import click
1 import click
2 import schainpy
2 import schainpy
3 import subprocess
3 import subprocess
4 from multiprocessing import cpu_count
5 from schaincli import templates
6 from schainpy import controller_api
7 import os
4 import os
8 import sys
5 import sys
9 import glob
6 import glob
7 from multiprocessing import cpu_count
8 from schaincli import templates
9 from schainpy import controller_api
10 from schainpy.utils import log
10
11
11 def print_version(ctx, param, value):
12 def print_version(ctx, param, value):
12 if not value or ctx.resilient_parsing:
13 if not value or ctx.resilient_parsing:
@@ -14,6 +15,7 def print_version(ctx, param, value):
14 click.echo(schainpy.__version__)
15 click.echo(schainpy.__version__)
15 ctx.exit()
16 ctx.exit()
16
17
18 cliLogger = log.makelogger('schain cli')
17
19
18 @click.command()
20 @click.command()
19 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
21 @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):
34 numberfiles = len(currentfiles)
36 numberfiles = len(currentfiles)
35 print currentfiles
37 print currentfiles
36 if numberfiles > 1:
38 if numberfiles > 1:
37 click.echo('\x1b[6;37;41m[ERROR] - There is more than one file to run\x1b[0m')
39 log.error('There is more than one file to run')
38 elif numberfiles == 1:
40 elif numberfiles == 1:
39 subprocess.call(['python ' + currentfiles[0]], shell=True)
41 subprocess.call(['python ' + currentfiles[0]], shell=True)
40 else:
42 else:
41 click.echo('\x1b[6;37;41m[ERROR] - There is no file to run.\x1b[0m')
43 log.error('There is no file to run.')
42 else:
44 else:
43 subprocess.call(['python ' + nextcommand], shell=True)
45 subprocess.call(['python ' + nextcommand], shell=True)
44 else:
46 else:
45 click.echo('\x1b[6;37;41m[ERROR] - Command is not defined.\x1b[0m')
47 log.error('Command is not defined.')
46
48
47
49
48 def basicInputs():
50 def basicInputs():
@@ -70,14 +72,13 def generate():
70 script = open(scriptname, 'w')
72 script = open(scriptname, 'w')
71 try:
73 try:
72 script.write(current)
74 script.write(current)
73 click.echo('\x1b[6;37;42m[SUCCESS] Script {file} generated\x1b[0m'.format(file=scriptname))
75 log.success('Script {file} generated'.format(file=scriptname))
74 except Exception as e:
76 except Exception as e:
75 click.echo('\x1b[6;37;41m[ERROR] I cannot create the file. Do you have writing permissions?\x1b[0m')
77 log.error('I cannot create the file. Do you have writing permissions?')
76
78
77
79
78 def test():
80 def test():
79 print templates.basic.format(name='hola', desc='desc', path='path', startDate='0', endDate='0')
81 log.warning('testing')
80 click.echo('testing')
81
82
82
83
83 def runFromXML(filename):
84 def runFromXML(filename):
@@ -90,9 +91,9 def runFromXML(filename):
90 controller.start()
91 controller.start()
91 plotterObj.start()
92 plotterObj.start()
92
93
93 print "Finishing all processes ..."
94 cliLogger("Finishing all processes ...")
94
95
95 controller.join(5)
96 controller.join(5)
96
97
97 print "End of script"
98 cliLogger("End of script")
98 return
99 return
@@ -1,54 +1,56
1 '''
1 """.
2
2 Created on Jul 16, 2014
3 Created on Jul 16, 2014
3
4
4 @author: Miguel Urco
5 @author: Miguel Urco
5 '''
6 """
6
7
7 from schainpy import __version__
8 from schainpy import __version__
8 from setuptools import setup, Extension
9 from setuptools import setup, Extension
9
10
10 setup(name="schainpy",
11 setup(name="schainpy",
11 version=__version__,
12 version=__version__,
12 description="Python tools to read, write and process Jicamarca data",
13 description="Python tools to read, write and process Jicamarca data",
13 author="Miguel Urco",
14 author="Miguel Urco",
14 author_email="miguel.urco@jro.igp.gob.pe",
15 author_email="miguel.urco@jro.igp.gob.pe",
15 url="http://jro.igp.gob.pe",
16 url="http://jro.igp.gob.pe",
16 packages = {'schainpy',
17 packages={'schainpy',
17 'schainpy.model',
18 'schainpy.model',
18 'schainpy.model.data',
19 'schainpy.model.data',
19 'schainpy.model.graphics',
20 'schainpy.model.graphics',
20 'schainpy.model.io',
21 'schainpy.model.io',
21 'schainpy.model.proc',
22 'schainpy.model.proc',
22 'schainpy.model.serializer',
23 'schainpy.model.serializer',
23 'schainpy.model.utils',
24 'schainpy.model.utils',
24 'schainpy.gui',
25 'schainpy.gui',
25 'schainpy.gui.figures',
26 'schainpy.gui.figures',
26 'schainpy.gui.viewcontroller',
27 'schainpy.gui.viewcontroller',
27 'schainpy.gui.viewer',
28 'schainpy.gui.viewer',
28 'schainpy.gui.viewer.windows'},
29 'schainpy.gui.viewer.windows'},
29 ext_package='schainpy',
30 ext_package='schainpy',
30 py_modules=[''],
31 py_modules=[''],
31 package_data={'': ['schain.conf.template'],
32 package_data={'': ['schain.conf.template'],
32 'schainpy.gui.figures': ['*.png','*.jpg'],
33 'schainpy.gui.figures': ['*.png', '*.jpg'],
33 },
34 },
34 include_package_data=False,
35 include_package_data=False,
35 entry_points={
36 entry_points={
36 'console_scripts': [
37 'console_scripts': [
37 'schain = schaincli.cli:main',
38 'schain = schaincli.cli:main',
38 ],
39 ],
39 },
40 },
40 scripts =['schainpy/gui/schainGUI'],
41 scripts=['schainpy/gui/schainGUI'],
41 ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"])],
42 ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"])],
42 install_requires=[
43 install_requires=[
43 "scipy >= 0.14.0",
44 "scipy >= 0.14.0",
44 "h5py >= 2.2.1",
45 "h5py >= 2.2.1",
45 "matplotlib >= 1.4.2",
46 "matplotlib >= 1.4.2",
46 "pyfits >= 3.4",
47 "pyfits >= 3.4",
47 "numpy >= 1.11.2",
48 "numpy >= 1.11.2",
48 "paramiko >= 2.1.2",
49 "paramiko >= 2.1.2",
49 "paho-mqtt >= 1.2",
50 "paho-mqtt >= 1.2",
50 "zmq",
51 "zmq",
51 "fuzzywuzzy",
52 "fuzzywuzzy",
52 "click"
53 "click",
53 ],
54 "colorama"
55 ],
54 )
56 )
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now