Exemplo n.º 1
0
    def __init__(
        self, server_addr, server_bin, unity_log_file, product_key, auth_token=None, public_key="", secret_key=""
    ):
        """
        Constructs a new LocalServer

        @param server_bin string The path to the graphlab unity_server binary.

        @param server_addr string The address that the server is listening on. Server address must starts with 'ipc://' or 'tcp://'.

        @param unity_log_file string The path to the server logfile.

        @param public_key string The server's public encryption key.

        @param private_key string The server's private encryption key.
        """
        self.server_addr = server_addr
        self.server_bin = server_bin
        self.unity_log = unity_log_file
        self.product_key = product_key
        self.auth_token = auth_token
        self.logger = logging.getLogger(__name__)
        self.proc = None
        self.public_key = public_key
        self.secret_key = secret_key

        # Either both or neither encryption keys must be set.
        assert bool(public_key) == bool(secret_key)

        if not self.server_addr:
            # by default we use '/tmp/graphlab_server-$pid'
            # where the pid is the server process id
            self.server_addr = "default"

        if not self.server_bin:
            if not default_local_conf.server_bin:
                raise RuntimeError("Unable to start local server. Please set the GRAPHLAB_UNITY environment variable.")
            else:
                self.server_bin = default_local_conf.server_bin

        if not self.unity_log:
            self.unity_log = default_local_conf.get_unity_log()

        self._validate_protocol_and_address()
        # check server binary
        if not os.path.exists(self.server_bin):
            raise ValueError('Invalid server binary "%s" does not exist.' % self.server_bin)
        if not os.access(self.server_bin, os.X_OK):
            raise ValueError(
                'Invalid server binary "%s" is not executable. Please check your file permission.' % self.server_bin
            )