@@ -8,7 +8,7 save_stdout = sys.stdout | |||
|
8 | 8 | sys.stdout = open('trash', 'w') |
|
9 | 9 | from multiprocessing import cpu_count |
|
10 | 10 | from schaincli import templates |
|
11 |
from schainpy import |
|
|
11 | from schainpy.controller import Project | |
|
12 | 12 | from schainpy.model import Operation, ProcessingUnit |
|
13 | 13 | from schainpy.utils import log |
|
14 | 14 | from importlib import import_module |
@@ -150,18 +150,8 def test(): | |||
|
150 | 150 | |
|
151 | 151 | |
|
152 | 152 | def runFromXML(filename): |
|
153 |
controller = |
|
|
153 | controller = Project() | |
|
154 | 154 | if not controller.readXml(filename): |
|
155 | 155 | return |
|
156 | ||
|
157 | plotterObj = controller.useExternalPlotter() | |
|
158 | ||
|
159 | 156 | controller.start() |
|
160 | plotterObj.start() | |
|
161 | ||
|
162 | cliLogger("Finishing all processes") | |
|
163 | ||
|
164 | controller.join(5) | |
|
165 | ||
|
166 | cliLogger("End of script") | |
|
167 | 157 | return |
@@ -4,6 +4,12 Created on September , 2012 | |||
|
4 | 4 | ''' |
|
5 | 5 | |
|
6 | 6 | import sys |
|
7 | ||
|
8 | # save_stdout = sys.stdout | |
|
9 | # logToFile = newLogger() | |
|
10 | # sys.stdout = logToFile | |
|
11 | # sys.stderr = logToFile | |
|
12 | ||
|
7 | 13 | import ast |
|
8 | 14 | import datetime |
|
9 | 15 | import traceback |
@@ -13,6 +19,7 from multiprocessing import Process, Queue, cpu_count | |||
|
13 | 19 | |
|
14 | 20 | import schainpy |
|
15 | 21 | import schainpy.admin |
|
22 | from schainpy.utils.log import logToFile | |
|
16 | 23 | |
|
17 | 24 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring |
|
18 | 25 | from xml.dom import minidom |
@@ -904,7 +911,6 class ReadUnitConf(ProcUnitConf): | |||
|
904 | 911 | self.endTime = opConfObj.getParameterValue('endTime') |
|
905 | 912 | |
|
906 | 913 | class Project(Process): |
|
907 | ||
|
908 | 914 | id = None |
|
909 | 915 | name = None |
|
910 | 916 | description = None |
@@ -916,16 +922,17 class Project(Process): | |||
|
916 | 922 | |
|
917 | 923 | plotterQueue = None |
|
918 | 924 | |
|
919 | def __init__(self, plotter_queue=None): | |
|
925 | def __init__(self, plotter_queue=None, logfile=None): | |
|
920 | 926 | Process.__init__(self) |
|
921 | 927 | self.id = None |
|
922 | 928 | self.name = None |
|
923 | 929 | self.description = None |
|
924 | ||
|
930 | if logfile is not None: | |
|
931 | logToFile(logfile) | |
|
925 | 932 | self.plotterQueue = plotter_queue |
|
926 | 933 | |
|
927 | 934 | self.procUnitConfObjDict = {} |
|
928 | ||
|
935 | ||
|
929 | 936 | def __getNewId(self): |
|
930 | 937 | |
|
931 | 938 | idList = self.procUnitConfObjDict.keys() |
@@ -1321,5 +1328,3 class Project(Process): | |||
|
1321 | 1328 | for procKey in keyList: |
|
1322 | 1329 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1323 | 1330 | procUnitConfObj.close() |
|
1324 | ||
|
1325 | print "Process finished" |
@@ -1,4 +1,4 | |||
|
1 |
""" |
|
|
1 | """ | |
|
2 | 2 | SCHAINPY - LOG |
|
3 | 3 | Simple helper for log standarization |
|
4 | 4 | Usage: |
@@ -14,7 +14,8 SCHAINPY - LOG | |||
|
14 | 14 | [NEVER GONNA] - give you up |
|
15 | 15 | with color red as background and white as foreground. |
|
16 | 16 | """ |
|
17 | ||
|
17 | import os | |
|
18 | import sys | |
|
18 | 19 | import click |
|
19 | 20 | |
|
20 | 21 | def warning(message): |
@@ -37,3 +38,22 def makelogger(topic, bg='reset', fg='reset'): | |||
|
37 | 38 | click.echo(click.style('[{}] - '.format(topic.upper()) + message, |
|
38 | 39 | bg=bg, fg=fg)) |
|
39 | 40 | return func |
|
41 | ||
|
42 | class LoggerForFile(): | |
|
43 | def __init__(self, filename): | |
|
44 | self.old_stdout=sys.stdout | |
|
45 | cwd = os.getcwd() | |
|
46 | self.log_file = open(os.path.join(cwd, filename), 'w+') | |
|
47 | def write(self, text): | |
|
48 | text = text.rstrip() | |
|
49 | if not text: | |
|
50 | return | |
|
51 | self.log_file.write(text + '\n') | |
|
52 | self.old_stdout.write(text + '\n') | |
|
53 | def flush(self): | |
|
54 | self.old_stdout.flush() | |
|
55 | ||
|
56 | def logToFile(filename='log.log'): | |
|
57 | logger = LoggerForFile(filename) | |
|
58 | sys.stdout = logger | |
|
59 |
General Comments 0
You need to be logged in to leave comments.
Login now