Skip to content

Commit

Permalink
Merge pull request #156 from hautof/dev-3.0.0
Browse files Browse the repository at this point in the history
1, fix bug of nout and llog 2, only mode support for nout and llog
  • Loading branch information
tsbxmw authored Apr 15, 2019
2 parents 85c7de4 + b7134fe commit b06f087
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 16 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ script:
- python -m haf run -rc=1 -case=./testcases/test.xlsx,./testcases/test2.json,./testcases/test3.yml -rh=True -rod=./testcases/report.html -ld=./testcases -debug=true
- python -m haf run -rc=1 -case=./testcases/test2.json -rh=True -rod=./testcases/report.html -ld=./testcases -debug=true
- python -m haf run -rc=1 -case=./testcases/test3.yml -rh=True -rod=./testcases/report.html -ld=./testcases -debug=true
- python -m haf run -rc=2 -case=./testcases/test3.yml -rh=True -rod=./testcases/report.html -ld=./testcases -debug=true
- python -m haf run -rc=2 -case=./testcases/test3.yml -rh=True -rod=./testcases/report.html -ld=./testcases -nout=true
- python -m haf run -rc=1 -case=./testcases/test.xlsx,./testcases/test2.json,./testcases/test3.yml -rh=True -rod=./testcases/report.html -ld=./testcases -debug=true
- python -m haf run -rc=3 -case=./testcases/test.xlsx,./testcases/test2.json,./testcases/test3.yml -rh=True -rod=./testcases/report1.html -ld=./testcases -debug=true
- cat ./testcases/report.html
- cat ./testcases/report1.html
- python -m haf run -rc=3 -case=./testcases/test.xlsx,./testcases/test2.json,./testcases/test3.yml -rh=True -rod=./testcases/report1.html -ld=./testcases -llog=true

2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pipeline {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'haf-sample']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/hautof/haf-sample']]])
sh 'cp -rf ./haf-sample/* ./'
sh 'python3 -m haf run -c=config.json -nout=true'
sh 'python3 -m haf run -c=config.json -llog=true'
sh 'python3 -m haf run -c=config.json -llog=true -nout=true'
sh 'rm -rf .coverage.*'
sh 'coverage run --parallel-mod --source=./haf/ -m haf run -c=config.json'
sh 'coverage combine'
Expand Down
15 changes: 11 additions & 4 deletions haf/common/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def bind_busclient(self, bus_client: BusClient):
def bind_process(self, process_id):
self.process_id = process_id

def set_output(self, local_logger):
def set_output(self, local_logger, nout=True):
self.local_logger = local_logger
self.nout = nout

def debug(self, msg, logger_name=None):
msg = {"process": self.process_id, "logger_name":self.logger_name if not logger_name else logger_name, "level":"debug", "msg": msg}
Expand All @@ -45,18 +46,24 @@ def critical(self, msg, logger_name=None):
def __new__(cls, *args, **kwargs):
return object.__new__(cls)

def write_local_logger(self, msg):
def log_output(self, msg):
if not self.nout:
print(msg)

def write_local_logger(self, msg):
msg = f"{self.now} {msg.get('level')} <{msg.get('process')}> [{msg.get('logger_name')}] {msg.get('msg')}"
self.log_output(msg)
dir = f"./data/log/"
if not os.path.exists(dir):
os.makedirs(dir)
full_name = f"{dir}/log.log"
try:
with open(full_name, 'a+') as f:
f.write(f"{self.now}{msg}\n")
f.write(f"{msg}\n")
f.close()
except Exception as e:
with open(full_name, 'a+', encoding='utf-8') as f:
f.write(f"{self.now}{msg}\n")
f.write(f"{msg}\n")
f.close()

@property
Expand Down
2 changes: 1 addition & 1 deletion haf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

MAIN_VERSION = 2
SUB_VERSION = 8
FIX_VERSION = 2
FIX_VERSION = 3
VERSION_TYPE = "haf"
PLATFORM_VERSION = f"{VERSION_TYPE}-{MAIN_VERSION}.{SUB_VERSION}.{FIX_VERSION}"

Expand Down
2 changes: 1 addition & 1 deletion haf/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def run(self):
logger.bind_process(self.pid)
self.key = f"{self.pid}$%loader$%"
logger.bind_busclient(self.bus_client)
logger.set_output(self.args.local_logger)
logger.set_output(self.args.local_logger, self.args.nout)
logger.info(f"{self.key} start loader", __name__)
self.case_queue = self.bus_client.get_case()
self.case_back_queue = self.bus_client.get_case_back()
Expand Down
5 changes: 3 additions & 2 deletions haf/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,18 @@ def error_handler(self, temp1, msg):
self.write("error", temp1, msg)

def write(self, dir, filename, msg):
msg = f"{self.now}{msg}\n"
dir = f"{self.log_dir}/{self.case_name}/{self.time_str}/{dir}"
if not os.path.exists(dir):
os.makedirs(dir)
full_name = f"{dir}/{filename}.log"
try:
with open(full_name, 'a+') as f:
f.write(f"{self.now}{msg}\n")
f.write(msg)
f.close()
except Exception as e:
with open(full_name, 'a+', encoding='utf-8') as f:
f.write(f"{self.now}{msg}\n")
f.write(msg)
f.close()

@property
Expand Down
5 changes: 3 additions & 2 deletions haf/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def only_bus(self, args):
self._init_system_lock(args)
self._init_system_logger(args.log_dir, self.bus_client)
self._start_recorder(self.bus_client, self.runner_count, self.case_log_dir, self.time_str)
while True:
time.sleep(1)
self.wait_end_signal(args)
sys.exit(0)
else:
logger.info("not only bus mode")

Expand All @@ -187,6 +187,7 @@ def wait_end_signal(self, args):
self.signal = system_signal.get()
if self.signal == SIGNAL_RECORD_END or self.signal == SIGNAL_STOP:
logger.info("main -- stop")
system_signal.put(SIGNAL_RECORD_END)
system_signal.put(SIGNAL_BUS_END)
break
time.sleep(0.1)
Expand Down
2 changes: 1 addition & 1 deletion haf/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def run(self):
self.recorder_key = f"{self.pid}$%recorder$%"
logger.bind_busclient(self.bus_client)
logger.bind_process(self.pid)
logger.set_output(self.args.local_logger)
logger.set_output(self.args.local_logger, self.args.nout)
logger.info(f"{self.recorder_key} start recorder ", __name__)
#self.bus_client = BusClient()
self.results_handler = self.bus_client.get_result()
Expand Down
2 changes: 1 addition & 1 deletion haf/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def run(self):
self.loop = None
logger.bind_busclient(self.bus_client)
logger.bind_process(self.pid)
logger.set_output(self.args.local_logger)
logger.set_output(self.args.local_logger, self.args.nout)
logger.info(f"{self.runner_key} start runner", __name__)

self.web_queue = self.bus_client.get_publish_runner()
Expand Down

0 comments on commit b06f087

Please sign in to comment.