##// 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 1 import click
2 2 import schainpy
3 3 import subprocess
4 from multiprocessing import cpu_count
5 from schaincli import templates
6 from schainpy import controller_api
7 4 import os
8 5 import sys
9 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 12 def print_version(ctx, param, value):
12 13 if not value or ctx.resilient_parsing:
@@ -14,6 +15,7 def print_version(ctx, param, value):
14 15 click.echo(schainpy.__version__)
15 16 ctx.exit()
16 17
18 cliLogger = log.makelogger('schain cli')
17 19
18 20 @click.command()
19 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 36 numberfiles = len(currentfiles)
35 37 print currentfiles
36 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 40 elif numberfiles == 1:
39 41 subprocess.call(['python ' + currentfiles[0]], shell=True)
40 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 44 else:
43 45 subprocess.call(['python ' + nextcommand], shell=True)
44 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 50 def basicInputs():
@@ -70,14 +72,13 def generate():
70 72 script = open(scriptname, 'w')
71 73 try:
72 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 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 80 def test():
79 print templates.basic.format(name='hola', desc='desc', path='path', startDate='0', endDate='0')
80 click.echo('testing')
81 log.warning('testing')
81 82
82 83
83 84 def runFromXML(filename):
@@ -90,9 +91,9 def runFromXML(filename):
90 91 controller.start()
91 92 plotterObj.start()
92 93
93 print "Finishing all processes ..."
94 cliLogger("Finishing all processes ...")
94 95
95 96 controller.join(5)
96 97
97 print "End of script"
98 cliLogger("End of script")
98 99 return
@@ -1,8 +1,9
1 '''
1 """.
2
2 3 Created on Jul 16, 2014
3 4
4 5 @author: Miguel Urco
5 '''
6 """
6 7
7 8 from schainpy import __version__
8 9 from setuptools import setup, Extension
@@ -49,6 +50,7 setup(name="schainpy",
49 50 "paho-mqtt >= 1.2",
50 51 "zmq",
51 52 "fuzzywuzzy",
52 "click"
53 "click",
54 "colorama"
53 55 ],
54 56 )
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now