def __init__(self, pname, runner, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): """ Deamon Constructor :param pname: process name :param runner: Runner instance :param stdin: redirection stdin to :param stdout: redirection stdout to :param stderr: redirection stderr to """ self.stdin = stdin self.stdout = stdout self.stderr = stderr self.pidfile = "/var/run/" + pname + ".pid" self.runner = runner self.isdaemon = False self.pname = pname signal.signal(signal.SIGINT, self.terminate) signal.signal(signal.SIGTERM, self.terminate) self._logger = util.getdefaultlogger() self.runner.setlogger(self._logger)
def __init__(self, option, logger): self._option = option if logger is None: self._logger = util.getdefaultlogger() else: self._logger = logger self._rbuf = "" self._wbuf = "" if "BBB" in option and option["BBB"] is True: import Adafruit_BBIO.UART as UART UART.setup("UART1")
def __init__(self, option, devinfo, coupleid, logger=None): """ Mate 의 Constructor. option과 devinfo를 주요 입력으로 함. :param option: 작동을 위한 설정을 딕셔너리로 전달함 :param devinfo: 처리하는 장비의 아이디를 딕셔너리 형식으로 전달함. 다음과 같은 형식임. id 는 장비의 아이디, dk 는 장비를 확인하기 위한 키값, dt는 장비의 타입, children은 하위 장비가 있는 경우에 하위 장비를 표현하기 위한 용도임. devinfo : [ {"id" : "3", "dk" : "1", "dt": "nd", "children" : [ {"id" : "4", "dk" : "0", "dt": "sen"}, {"id" : "5", "dk" : "1", "dt": "sen"}, {"id" : "6", "dk" : "2", "dt": "act"}, {"id" : "7", "dk" : "3", "dt": "act/retractable/level0"} ]} ] :param coupleid: 커플아이디. :param logger: 로깅을 위한 로거. 없다면 내부적으로 만듬. """ self._option = option print("mate initialized. ", option) self._coupleid = coupleid self._sleep = { "time": 3, "obs": 19, "noti": 19 } if "sleep" not in option else option["sleep"] self._devinfo = DevInfo(devinfo) self._writecb = None self._executing = False self._connected = False self._msgq = None if "backup" in option and "prefix" in option["backup"]: self._backup = True else: self._backup = False if logger is None: self._logger = util.getdefaultlogger() else: self._logger = logger self._calibrator = Calibrator(option, self._logger)
def __init__(self, option, logger): """ Calibrator 의 Constructor. :param option: 작동을 위한 설정을 딕셔너리로 전달함 :param logger: 로깅을 위한 로거. """ if logger is None: self._logger = util.getdefaultlogger() else: self._logger = logger if "calibration" not in option: self._option = None self._logger.info("There is no information of calibration") else: self._option = option["calibration"] if "buffer" not in option: # 있다고 하더라도 최소한 3은 넘어야 함 self._buffer = None self._buflen = 0 else: self._buffer = {} self._buflen = option["buffer"]
self.stopold() self._couples = newcouples i = 1 else: i = i + 1 time.sleep(self._option['sleep']) self.stopold() if __name__ == '__main__': # if len(sys.argv) != 2: # print("Usage : python couplemanager.py [start|stop|restart|run]") # sys.exit(2) # mode = sys.argv[1] runner = CoupleManager('../conf/cpmng.conf', util.getdefaultlogger()) runner.initialize() runner.run() runner.finalize() # adaemon = Daemon('cpmng', runner) # if 'start' == mode: # adaemon.start() # elif 'stop' == mode: # adaemon.stop() # elif 'restart' == mode: # adaemon.restart() # elif 'run' == mode: # adaemon.run() # else: # print "Unknown command"
print("time left", tmp, self._option["sleep"]) if tmp > 0: time.sleep(tmp) if debug: break self.close() if __name__ == '__main__': if len(sys.argv) != 2: print("Usage : python fcore.py [start|stop|restart|run|debug]") sys.exit(2) mode = sys.argv[1] runner = FCore('../conf/fcore.json', util.getdefaultlogger()) runner.initialize() runner.run() runner.finalize() # adaemon = Daemon('fcore', runner) # if 'start' == mode: # adaemon.start() # elif 'stop' == mode: # adaemon.stop() # elif 'restart' == mode: # adaemon.restart() # elif 'run' == mode: # adaemon.run() # elif 'debug' == mode: # adaemon.run(True)
args.append(data[key].getvalue()) else: args.append(key) return args def evaluate(self, rule, proc, dbcur): lines = subprocess32.check_output(self._makeargs(proc, rule["inputs"]), timeout=self._TIMEOUT, universal_newlines=True) values = map(float, lines.split("\n")) return ProcResult(RetCode.OK, proc, values) if __name__ == '__main__': eqproc = EquationProcessor(util.getdefaultlogger()) print eqproc.evaluate( { "field_id": 1, "inputs": { "#bottomtemp0": { "nvalue": 0 }, "#middletemp0": { "nvalue": 0 }, "#uptemp0": { "nvalue": 0 }, "#alc0": { "nvalue": 0
except Exception as ex: self._logger.warn(rule["name"] + " (" + str(idx) + ") is failed to execute. " + str(ex)) self._logger.warn(str(traceback.format_exc())) tmp = ProcResult(RetCode.PROCESSOR_EXCEPTION) ret.append(tmp) # make output newret = self.rearrangeresult(ret) print ret, newret self.processdata(rule, ret, newret) reqs = self.processrequest(rule, ret, newret) return reqs if __name__ == '__main__': ts = TimeSpanManager({}, util.getdefaultlogger()) ts.addtimespan(1, 1, [{"to": 10000}]) assert ts.getcurrentts((0, 0)) == 0, "timespan is not matched #1" now = datetime.now() nsec = (now - now.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds() ans = 0 if nsec < 10000 else -1 assert ts.getcurrentts((1, 1)) == ans, "timespan is not matched #2" rulemng = RuleManager({}, util.getdefaultlogger())