@@ -1,98 +1,98 | |||
|
1 | 1 | import click |
|
2 | 2 | import schainpy |
|
3 | 3 | import subprocess |
|
4 | 4 | from multiprocessing import cpu_count |
|
5 |
from schaincli |
|
|
5 | from schaincli import templates | |
|
6 | 6 | from schainpy import controller_api |
|
7 | 7 | import os |
|
8 | 8 | import sys |
|
9 | 9 | import glob |
|
10 | 10 | |
|
11 | 11 | def print_version(ctx, param, value): |
|
12 | 12 | if not value or ctx.resilient_parsing: |
|
13 | 13 | return |
|
14 | 14 | click.echo(schainpy.__version__) |
|
15 | 15 | ctx.exit() |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | @click.command() |
|
19 | 19 | @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str) |
|
20 | 20 | @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True)) |
|
21 | 21 | @click.argument('command', default='run', required=True) |
|
22 | 22 | @click.argument('nextcommand', default=None, required=False, type=click.Path(exists=True, resolve_path=True)) |
|
23 | 23 | def main(command, nextcommand, version, xml): |
|
24 | 24 | """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY""" |
|
25 | 25 | if xml is not None: |
|
26 | 26 | runFromXML(xml) |
|
27 | 27 | elif command == 'generate': |
|
28 | 28 | generate() |
|
29 | 29 | elif command == 'test': |
|
30 | 30 | test() |
|
31 | 31 | elif command == 'run': |
|
32 | 32 | if nextcommand is None: |
|
33 | 33 | currentfiles = glob.glob('./*.py') |
|
34 | 34 | numberfiles = len(currentfiles) |
|
35 | 35 | print currentfiles |
|
36 | 36 | if numberfiles > 1: |
|
37 | 37 | click.echo('\x1b[6;37;41m[ERROR] - There is more than one file to run\x1b[0m') |
|
38 | 38 | elif numberfiles == 1: |
|
39 | 39 | subprocess.call(['python ' + currentfiles[0]], shell=True) |
|
40 | 40 | else: |
|
41 | 41 | click.echo('\x1b[6;37;41m[ERROR] - There is no file to run.\x1b[0m') |
|
42 | 42 | else: |
|
43 | 43 | subprocess.call(['python ' + nextcommand], shell=True) |
|
44 | 44 | else: |
|
45 | 45 | click.echo('\x1b[6;37;41m[ERROR] - Command is not defined.\x1b[0m') |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | def basicInputs(): |
|
49 | 49 | inputs = {} |
|
50 | 50 | inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str) |
|
51 | 51 | inputs['name'] = click.prompt('Name of the project', default="project", type=str) |
|
52 | 52 | inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True)) |
|
53 | 53 | inputs['startDate'] = click.prompt('Start date', default='1970/01/01', type=str) |
|
54 | 54 | inputs['endDate'] = click.prompt('End date', default='2017/12/31', type=str) |
|
55 | 55 | inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str) |
|
56 | 56 | inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str) |
|
57 | 57 | inputs['figpath'] = inputs['path'] + '/figs' |
|
58 | 58 | return inputs |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | def generate(): |
|
62 | 62 | inputs = basicInputs() |
|
63 | 63 | inputs['multiprocess'] = click.confirm('Is this a multiprocess script?') |
|
64 | 64 | if inputs['multiprocess']: |
|
65 | 65 | inputs['nProcess'] = click.prompt('How many process?', default=cpu_count(), type=int) |
|
66 | 66 | current = templates.multiprocess.format(**inputs) |
|
67 | 67 | else: |
|
68 | 68 | current = templates.basic.format(**inputs) |
|
69 | 69 | scriptname = inputs['name'] + ".py" |
|
70 | 70 | script = open(scriptname, 'w') |
|
71 | 71 | try: |
|
72 | 72 | script.write(current) |
|
73 | 73 | click.echo('\x1b[6;37;42m[SUCCESS] Script {file} generated\x1b[0m'.format(file=scriptname)) |
|
74 | 74 | except Exception as e: |
|
75 | 75 | click.echo('\x1b[6;37;41m[ERROR] I cannot create the file. Do you have writing permissions?\x1b[0m') |
|
76 | 76 | |
|
77 | 77 | |
|
78 | 78 | def test(): |
|
79 | 79 | print templates.basic.format(name='hola', desc='desc', path='path', startDate='0', endDate='0') |
|
80 | 80 | click.echo('testing') |
|
81 | 81 | |
|
82 | 82 | |
|
83 | 83 | def runFromXML(filename): |
|
84 | 84 | controller = controller_api.ControllerThread() |
|
85 | 85 | if not controller.readXml(filename): |
|
86 | 86 | return |
|
87 | 87 | |
|
88 | 88 | plotterObj = controller.useExternalPlotter() |
|
89 | 89 | |
|
90 | 90 | controller.start() |
|
91 | 91 | plotterObj.start() |
|
92 | 92 | |
|
93 | 93 | print "Finishing all processes ..." |
|
94 | 94 | |
|
95 | 95 | controller.join(5) |
|
96 | 96 | |
|
97 | 97 | print "End of script" |
|
98 | 98 | return |
|
1 | NO CONTENT: file renamed from schaincli/schaincli/templates.py to schaincli/templates.py |
@@ -1,53 +1,54 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 16, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: Miguel Urco |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | from schainpy import __version__ |
|
8 | 8 | from setuptools import setup, Extension |
|
9 | 9 | |
|
10 | 10 | setup(name="schainpy", |
|
11 | 11 | version=__version__, |
|
12 | 12 | description="Python tools to read, write and process Jicamarca data", |
|
13 | 13 | author="Miguel Urco", |
|
14 | 14 | author_email="miguel.urco@jro.igp.gob.pe", |
|
15 | 15 | url="http://jro.igp.gob.pe", |
|
16 | 16 | packages = {'schainpy', |
|
17 | 17 | 'schainpy.model', |
|
18 | 18 | 'schainpy.model.data', |
|
19 | 19 | 'schainpy.model.graphics', |
|
20 | 20 | 'schainpy.model.io', |
|
21 | 21 | 'schainpy.model.proc', |
|
22 | 22 | 'schainpy.model.serializer', |
|
23 | 23 | 'schainpy.model.utils', |
|
24 | 24 | 'schainpy.gui', |
|
25 | 25 | 'schainpy.gui.figures', |
|
26 | 26 | 'schainpy.gui.viewcontroller', |
|
27 | 27 | 'schainpy.gui.viewer', |
|
28 | 28 | 'schainpy.gui.viewer.windows'}, |
|
29 | 29 | ext_package='schainpy', |
|
30 | 30 | py_modules=[''], |
|
31 | 31 | package_data={'': ['schain.conf.template'], |
|
32 | 32 | 'schainpy.gui.figures': ['*.png','*.jpg'], |
|
33 | 33 | }, |
|
34 | 34 | include_package_data=False, |
|
35 | 35 | entry_points={ |
|
36 | 36 | 'console_scripts': [ |
|
37 |
'schain = schaincli. |
|
|
37 | 'schain = schaincli.cli:main', | |
|
38 | 38 | ], |
|
39 | 39 | }, |
|
40 | 40 | scripts =['schainpy/gui/schainGUI'], |
|
41 | 41 | ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"])], |
|
42 | 42 | install_requires=[ |
|
43 | 43 | "scipy >= 0.14.0", |
|
44 | 44 | "h5py >= 2.2.1", |
|
45 | 45 | "matplotlib >= 1.4.2", |
|
46 | 46 | "pyfits >= 3.4", |
|
47 | 47 | "numpy >= 1.11.2", |
|
48 | 48 | "paramiko >= 2.1.2", |
|
49 | 49 | "paho-mqtt >= 1.2", |
|
50 | 50 | "zmq", |
|
51 | "fuzzywuzzy" | |
|
51 | "fuzzywuzzy", | |
|
52 | "click" | |
|
52 | 53 | ], |
|
53 | 54 | ) |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now