##// 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,98 +1,99
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:
13 14 return
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)
20 22 @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True))
21 23 @click.argument('command', default='run', required=True)
22 24 @click.argument('nextcommand', default=None, required=False, type=click.Path(exists=True, resolve_path=True))
23 25 def main(command, nextcommand, version, xml):
24 26 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY"""
25 27 if xml is not None:
26 28 runFromXML(xml)
27 29 elif command == 'generate':
28 30 generate()
29 31 elif command == 'test':
30 32 test()
31 33 elif command == 'run':
32 34 if nextcommand is None:
33 35 currentfiles = glob.glob('./*.py')
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():
49 51 inputs = {}
50 52 inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str)
51 53 inputs['name'] = click.prompt('Name of the project', default="project", type=str)
52 54 inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True))
53 55 inputs['startDate'] = click.prompt('Start date', default='1970/01/01', type=str)
54 56 inputs['endDate'] = click.prompt('End date', default='2017/12/31', type=str)
55 57 inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str)
56 58 inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str)
57 59 inputs['figpath'] = inputs['path'] + '/figs'
58 60 return inputs
59 61
60 62
61 63 def generate():
62 64 inputs = basicInputs()
63 65 inputs['multiprocess'] = click.confirm('Is this a multiprocess script?')
64 66 if inputs['multiprocess']:
65 67 inputs['nProcess'] = click.prompt('How many process?', default=cpu_count(), type=int)
66 68 current = templates.multiprocess.format(**inputs)
67 69 else:
68 70 current = templates.basic.format(**inputs)
69 71 scriptname = inputs['name'] + ".py"
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):
84 85 controller = controller_api.ControllerThread()
85 86 if not controller.readXml(filename):
86 87 return
87 88
88 89 plotterObj = controller.useExternalPlotter()
89 90
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,54 +1,56
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
9 10
10 11 setup(name="schainpy",
11 version=__version__,
12 description="Python tools to read, write and process Jicamarca data",
13 author="Miguel Urco",
14 author_email="miguel.urco@jro.igp.gob.pe",
15 url="http://jro.igp.gob.pe",
16 packages = {'schainpy',
17 'schainpy.model',
18 'schainpy.model.data',
19 'schainpy.model.graphics',
20 'schainpy.model.io',
21 'schainpy.model.proc',
22 'schainpy.model.serializer',
23 'schainpy.model.utils',
24 'schainpy.gui',
25 'schainpy.gui.figures',
26 'schainpy.gui.viewcontroller',
27 'schainpy.gui.viewer',
28 'schainpy.gui.viewer.windows'},
29 ext_package='schainpy',
30 py_modules=[''],
31 package_data={'': ['schain.conf.template'],
32 'schainpy.gui.figures': ['*.png','*.jpg'],
33 },
34 include_package_data=False,
35 entry_points={
36 'console_scripts': [
37 'schain = schaincli.cli:main',
38 ],
39 },
40 scripts =['schainpy/gui/schainGUI'],
41 ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"])],
42 install_requires=[
43 "scipy >= 0.14.0",
44 "h5py >= 2.2.1",
45 "matplotlib >= 1.4.2",
46 "pyfits >= 3.4",
47 "numpy >= 1.11.2",
48 "paramiko >= 2.1.2",
49 "paho-mqtt >= 1.2",
50 "zmq",
51 "fuzzywuzzy",
52 "click"
53 ],
12 version=__version__,
13 description="Python tools to read, write and process Jicamarca data",
14 author="Miguel Urco",
15 author_email="miguel.urco@jro.igp.gob.pe",
16 url="http://jro.igp.gob.pe",
17 packages={'schainpy',
18 'schainpy.model',
19 'schainpy.model.data',
20 'schainpy.model.graphics',
21 'schainpy.model.io',
22 'schainpy.model.proc',
23 'schainpy.model.serializer',
24 'schainpy.model.utils',
25 'schainpy.gui',
26 'schainpy.gui.figures',
27 'schainpy.gui.viewcontroller',
28 'schainpy.gui.viewer',
29 'schainpy.gui.viewer.windows'},
30 ext_package='schainpy',
31 py_modules=[''],
32 package_data={'': ['schain.conf.template'],
33 'schainpy.gui.figures': ['*.png', '*.jpg'],
34 },
35 include_package_data=False,
36 entry_points={
37 'console_scripts': [
38 'schain = schaincli.cli:main',
39 ],
40 },
41 scripts=['schainpy/gui/schainGUI'],
42 ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"])],
43 install_requires=[
44 "scipy >= 0.14.0",
45 "h5py >= 2.2.1",
46 "matplotlib >= 1.4.2",
47 "pyfits >= 3.4",
48 "numpy >= 1.11.2",
49 "paramiko >= 2.1.2",
50 "paho-mqtt >= 1.2",
51 "zmq",
52 "fuzzywuzzy",
53 "click",
54 "colorama"
55 ],
54 56 )
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now