def accept_once(sock, options): logging.debug("Waiting for connection...") while True: rlist, wlist, xlist = select.select([sock], [], [], 0.5) if not rlist: continue client, addr = sock.accept() logging.info("Received connection from {}".format(addr)) data_size = struct.unpack("!I", sockutil.recvall(client, 4))[0] logging.debug("Expecting {} bytes of data from client" .format(data_size)) data = sockutil.recvall(client, data_size) logging.info("Received {} bytes of data from client" .format(len(data))) pack_location = None try: pack_location = local.unpack_archive("swig-bot", data) logging.debug("Successfully unpacked archive...") logging.info("Sending {} byte response".format(len(data))) client.sendall(struct.pack("!I", len(data))) client.sendall(data) finally: if pack_location is not None: logging.debug("Removing temporary folder {}" .format(pack_location)) shutil.rmtree(pack_location)
def accept_once(sock, options): logging.debug("Waiting for connection...") while True: rlist, wlist, xlist = select.select([sock], [], [], 0.5) if not rlist: continue client, addr = sock.accept() logging.info("Received connection from {}".format(addr)) data_size = struct.unpack("!I", sockutil.recvall(client, 4))[0] logging.debug( "Expecting {} bytes of data from client".format(data_size)) data = sockutil.recvall(client, data_size) logging.info("Received {} bytes of data from client".format(len(data))) pack_location = None try: pack_location = local.unpack_archive("swig-bot", data) logging.debug("Successfully unpacked archive...") logging.info("Sending {} byte response".format(len(data))) client.sendall(struct.pack("!I", len(data))) client.sendall(data) finally: if pack_location is not None: logging.debug( "Removing temporary folder {}".format(pack_location)) shutil.rmtree(pack_location)
def accept_once(sock, options): logging.debug("Waiting for connection...") while True: rlist, wlist, xlist = select.select([sock], [], [], 0.5) if not rlist: continue client, addr = sock.accept() logging.info("Received connection from {0}".format(addr)) data_size = struct.unpack("!I", sockutil.recvall(client, 4))[0] logging.debug("Expecting {0} bytes of data from client".format(data_size)) data = sockutil.recvall(client, data_size) logging.info("Received {0} bytes of data from client".format(len(data))) pack_location = None try: tempfolder = os.path.join(tempfile.gettempdir(), "swig-bot") os.makedirs(tempfolder, exist_ok=True) pack_location = tempfile.mkdtemp(dir=tempfolder) logging.debug("Extracting archive to {0}".format(pack_location)) local.unpack_archive(pack_location, data) logging.debug("Successfully unpacked archive...") config_file = os.path.normpath(os.path.join(pack_location, "config.json")) parsed_config = remote.parse_config(io.open(config_file)) config = local.LocalConfig() config.languages = parsed_config["languages"] config.swig_executable = options.swig_executable config.src_root = pack_location config.target_dir = os.path.normpath(os.path.join(config.src_root, "output")) logging.info( "Running swig. languages={0}, swig={1}, src_root={2}, target={3}".format( config.languages, config.swig_executable, config.src_root, config.target_dir ) ) status = local.generate(config) logging.debug("Finished running swig. Packaging up files {0}".format(os.listdir(config.target_dir))) zip_data = io.BytesIO() zip_file = local.pack_archive(zip_data, config.target_dir, None) response_status = remote.serialize_response_status(status) logging.debug("Sending response status {0}".format(response_status)) logging.info("(swig output) -> swig_output.json") zip_file.writestr("swig_output.json", response_status) zip_file.close() response_data = zip_data.getvalue() logging.info("Sending {0} byte response".format(len(response_data))) client.sendall(struct.pack("!I", len(response_data))) client.sendall(response_data) finally: if pack_location is not None: logging.debug("Removing temporary folder {0}".format(pack_location)) shutil.rmtree(pack_location)
def transmit_request(connection, packed_input): logging.info("Sending {} bytes of compressed data." .format(len(packed_input))) connection.sendall(struct.pack("!I", len(packed_input))) connection.sendall(packed_input) logging.info("Awaiting response.") response_len = struct.unpack("!I", sockutil.recvall(connection, 4))[0] logging.debug("Expecting {} byte response".format(response_len)) response = sockutil.recvall(connection, response_len) return response
def transmit_request(connection, packed_input): logging.info("Sending {} bytes of compressed data.".format( len(packed_input))) connection.sendall(struct.pack("!I", len(packed_input))) connection.sendall(packed_input) logging.info("Awaiting response.") response_len = struct.unpack("!I", sockutil.recvall(connection, 4))[0] logging.debug("Expecting {} byte response".format(response_len)) response = sockutil.recvall(connection, response_len) return response
def accept_once(sock, options): logging.debug("Waiting for connection...") while True: rlist, wlist, xlist = select.select([sock], [], [], 0.5) if not rlist: continue client, addr = sock.accept() logging.info("Received connection from {}".format(addr)) data_size = struct.unpack("!I", sockutil.recvall(client, 4))[0] logging.debug( "Expecting {} bytes of data from client".format(data_size)) data = sockutil.recvall(client, data_size) logging.info("Received {} bytes of data from client".format(len(data))) pack_location = None try: tempfolder = os.path.join(tempfile.gettempdir(), "swig-bot") os.makedirs(tempfolder, exist_ok=True) pack_location = tempfile.mkdtemp(dir=tempfolder) logging.debug("Extracting archive to {}".format(pack_location)) local.unpack_archive(pack_location, data) logging.debug("Successfully unpacked archive...") config_file = os.path.normpath( os.path.join(pack_location, "config.json")) parsed_config = remote.parse_config(io.open(config_file)) config = local.LocalConfig() config.languages = parsed_config["languages"] config.swig_executable = options.swig_executable config.src_root = pack_location config.target_dir = os.path.normpath( os.path.join(config.src_root, "output")) logging.info( "Running swig. languages={}, swig={}, src_root={}, target={}". format(config.languages, config.swig_executable, config.src_root, config.target_dir)) status = local.generate(config) logging.debug( "Finished running swig. Packaging up files {}".format( os.listdir(config.target_dir))) zip_data = io.BytesIO() zip_file = local.pack_archive(zip_data, config.target_dir, None) response_status = remote.serialize_response_status(status) logging.debug("Sending response status {}".format(response_status)) logging.info("(swig output) -> swig_output.json") zip_file.writestr("swig_output.json", response_status) zip_file.close() response_data = zip_data.getvalue() logging.info("Sending {} byte response".format(len(response_data))) client.sendall(struct.pack("!I", len(response_data))) client.sendall(response_data) finally: if pack_location is not None: logging.debug( "Removing temporary folder {}".format(pack_location)) shutil.rmtree(pack_location)