Commit 25299860 authored by MERCIER Michael's avatar MERCIER Michael

[batsim] make the verbose and debug option works

parent 76db70a0
......@@ -27,10 +27,7 @@ class Batsim(object):
validatingmachine=None):
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(format=FORMAT)
self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.DEBUG)
self.running_simulation = False
if network_handler is None:
......
......@@ -8,6 +8,7 @@ Options:
--version Print the version of pybatsim and exit
-h --help Show this help message and exit.
-v --verbose Be verbose.
-d --debug Be more verbose.
-p --protect Protect the scheduler using a validating machine.
-s --socket-endpoint=<endpoint> Batsim socket endpoint to use [default: tcp://*:28000]
-e --event-socket-endpoint=<endpoint> Socket endpoint to use to publish scheduler events [default: tcp://*:29000]
......@@ -18,6 +19,7 @@ Options:
import sys
import json
import logging
from docopt import docopt
......@@ -27,10 +29,14 @@ from batsim import __version__
def main():
arguments = docopt(__doc__, version=__version__)
loglevel = logging.WARNING
if arguments['--verbose']:
verbose = 999
else:
verbose = 0
loglevel = logging.INFO
if arguments['--debug']:
loglevel = logging.DEBUG
FORMAT = '[pybatsim - %(asctime)s - %(name)s - %(levelname)s] %(message)s'
logging.basicConfig(format=FORMAT, level=loglevel)
timeout = int(arguments['--timeout'] or float("inf"))
......@@ -55,8 +61,7 @@ def main():
event_socket_endpoint,
options,
timeout,
protect,
verbose)
protect)
if __name__ == "__main__":
......
......@@ -6,6 +6,7 @@
"""
import zmq
import json
import logging
class NetworkHandler:
......@@ -13,23 +14,22 @@ class NetworkHandler:
def __init__(
self,
socket_endpoint,
verbose=0,
timeout=2000,
type=zmq.REP):
self.socket_endpoint = socket_endpoint
self.verbose = verbose
self.timeout = timeout
self.context = zmq.Context()
self.connection = None
self.type = type
self.logger = logging.getLogger(__name__)
def send(self, msg):
self.send_string(json.dumps(msg))
def send_string(self, msg):
assert self.connection, "Connection not open"
if self.verbose > 0:
print("[PYBATSIM]: SEND_MSG\n {}".format(msg))
self.logger.debug("[PYBATSIM]: SEND_MSG\n {}".format(msg))
self.connection.send_string(msg)
def recv(self, blocking=False):
......@@ -49,8 +49,7 @@ class NetworkHandler:
except zmq.error.Again:
return None
if self.verbose > 0:
print('[PYBATSIM]: RECEIVED_MSG\n {}'.format(msg))
self.logger.debug('[PYBATSIM]: RECEIVED_MSG\n {}'.format(msg))
return msg
......@@ -58,8 +57,7 @@ class NetworkHandler:
assert not self.connection, "Connection already open"
self.connection = self.context.socket(self.type)
if self.verbose > 0:
print("[PYBATSIM]: binding to {addr}"
self.logger.debug("[PYBATSIM]: binding to {addr}"
.format(addr=self.socket_endpoint))
self.connection.bind(self.socket_endpoint)
......@@ -67,8 +65,7 @@ class NetworkHandler:
assert not self.connection, "Connection already open"
self.connection = self.context.socket(self.type)
if self.verbose > 0:
print("[PYBATSIM]: connecting to {addr}"
self.logger.debug("[PYBATSIM]: connecting to {addr}"
.format(addr=self.socket_endpoint))
self.connection.connect(self.socket_endpoint)
......
......@@ -104,8 +104,7 @@ def launch_scheduler(scheduler,
event_socket_endpoint="tcp://*:28001",
options={},
timeout=2000,
protect=True,
verbose=0):
protect=True):
if protect:
vm = ValidatingMachine
......@@ -117,7 +116,7 @@ def launch_scheduler(scheduler,
#try:
bs = Batsim(scheduler,
NetworkHandler(socket_endpoint, verbose, timeout),
NetworkHandler(socket_endpoint, timeout),
NetworkHandler(event_socket_endpoint, type=zmq.PUB),
validatingmachine=vm)
aborted = False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment