84 lines
1.5 KiB
Python
84 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
# coding: utf8
|
|
|
|
import json
|
|
import logging
|
|
import os
|
|
import socket
|
|
|
|
|
|
#### logging ####
|
|
# json decoder for int keys
|
|
import threading
|
|
|
|
|
|
class Decoder(json.JSONDecoder):
|
|
def decode(self, s, **kwargs):
|
|
result = super().decode(s) # result = super(Decoder, self).decode(s) for Python 2.x
|
|
return self._decode(result)
|
|
|
|
def _decode(self, o):
|
|
if isinstance(o, str):
|
|
try:
|
|
return int(o)
|
|
except ValueError:
|
|
return o
|
|
elif isinstance(o, dict):
|
|
return {k: self._decode(v) for k, v in o.items()}
|
|
elif isinstance(o, list):
|
|
return [self._decode(v) for v in o]
|
|
else:
|
|
return o
|
|
|
|
|
|
def setup_logging(default_path='log_config.json', default_level=logging.INFO, env_key='LOG_CFG'):
|
|
"""Setup logging configuration
|
|
"""
|
|
path = default_path
|
|
value = os.getenv(env_key, None)
|
|
if value:
|
|
path = value
|
|
if os.path.exists(path):
|
|
with open(path, 'rt') as f:
|
|
config = json.load(f)
|
|
logging.config.dictConfig(config)
|
|
else:
|
|
logging.basicConfig(level=default_level)
|
|
|
|
|
|
setup_logging()
|
|
|
|
log_server = logging.getLogger('server')
|
|
|
|
debug = log_server.debug
|
|
info = log_server.info
|
|
warning = log_server.warning
|
|
error = log_server.error
|
|
critical = log_server.critical
|
|
|
|
#### Variables ####
|
|
HOST = ''
|
|
PORT = 8888
|
|
BUFFER_SIZE = 16384
|
|
|
|
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
clientSocket.connect((HOST, PORT))
|
|
|
|
# ET ICI ON MET LE CLIENT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|