Ejemplo n.º 1
0
    def __init__(self, base_url, script_name, api_key, convert_datetimes_to_utc=True,
        http_proxy=None, ensure_ascii=True, connect=True, host=None, port=None):
        '''
        We will initialize the Shotgun object, but will not connect right away.
        Instead it will will attempt to create a socket connection using the
        Shotgun object and the host and port data provided or generated. If we do
        not have a host and port specified, or do not find a connection, we will
        fall back and connect to the actual Shotgun server instead.
        '''
        Shotgun.__init__(self, base_url, script_name, api_key,
            convert_datetimes_to_utc=convert_datetimes_to_utc,
            http_proxy=http_proxy, ensure_ascii=ensure_ascii,
            connect=False)

        # If a host is not specified, attempt using the local machine.
        if not host:
            host = socket.gethostname()

        # If a port is not specified, generate a port from the app key.
        if not port:
            port = common.appKeyToPort(self.config.api_key)

        self._sgclient = None
        self._host = host
        self._port = port

        if connect:
            self.connect()
Ejemplo n.º 2
0
    def __init__(self, base_url, script_name, api_key, convert_datetimes_to_utc=True,
        http_proxy=None, ensure_ascii=True, connect=True, host=None, port=None):

        self._configureLogger(script_name)

        Thread.__init__(self)

        # Create the Shotgun object that will be used throughout the server.
        sg = Shotgun(base_url, script_name, api_key, convert_datetimes_to_utc, http_proxy, ensure_ascii, connect)

        host = host or socket.gethostname()
        port = port or common.appKeyToPort(sg.config.api_key)

        if not isinstance(host, str):
            logMsg = "host must be a string"
            self.logger().critical(logMsg)
            raise ValueError(logMsg)

        minPort = 2000
        if not isinstance(port, int) or port < minPort:
            logMsg = "port must be an integer larger than %i" % minPort
            self.logger().critical(logMsg)
            raise ValueError(logMsg)

        self._sg = sg
        self._host = host
        self._port = port

        self.setMaxThreads(25)

        self._socket = socket.socket()
        self._socket.bind((host, port))
        self._socket.listen(5)

        self._clients = [self._socket]

        self._isRunning = False
        self._hasErrored = False
        self._needsReInit = False