示例#1
0
def send(message='ping 1234', port=lyipc.PORT):
    ''' Sends a raw message

        Trick here is that PyQt5 does not do automatic str<->byte encoding, but pya does. Also something weird with the addresses
    '''
    payload = message + '\r\n'
    psock = QTcpSocket()
    if not isGSI():
        payload = payload.encode()
    psock.connectToHost(get_target_hostname(incl_user=False), port)
    if psock.waitForConnected():
        psock.write(payload)
        if psock.waitForReadyRead(3000):
            ret = psock.readLine()
            if not isGSI():
                ret = bytes(ret).decode('utf-8')
            handle_query(ret)
        else:
            raise Exception('Not acknowledged')
    else:
        print('Connection Fail! (tried {}:{})'.format(
            get_target_hostname(incl_user=False), port))
示例#2
0
''' Server is designed to run from klayout GSI, usually in GUI mode

    Current state: only way to stop serving is close the application.
'''
from __future__ import print_function

import socket
import lyipc
from lygadgets import message, isGSI

if not isGSI():
    raise RuntimeError('Non-klayout serving does not make sense')
import pya

# As of now, port is hard coded and there is no way to stop it besided closing the app
# We have to make sure that a second server doesn't come along and clash
__active_server = None


def run_server():
    global __active_server
    if __active_server is None:
        __active_server = KlayoutServer()
    return __active_server


class KlayoutServer(pya.QTcpServer):
    def new_connection(self):
        from lyipc.interpreter import parse_message
        # Handle incoming connection
        connection = self.nextPendingConnection()
示例#3
0
def get_technologies():
    if isGSI() and True:
        return pya.Technology.technology_names()
    else:
        raise RuntimeError('Not in GSI')