def set_omero_credentials_from_string(credentials_string): '''Set the OMERO server / port / session ID credentials_string: a comma-separated key/value pair string (key=value) that gives the credentials. Keys are host - the DNS name or IP address of the OMERO server port - the TCP port to use to connect user - the user name session-id - the session ID used for authentication ''' import cellprofiler.preferences as cpprefs from bioformats.formatreader import use_omero_credentials from bioformats.formatreader import \ K_OMERO_SERVER, K_OMERO_PORT, K_OMERO_USER, K_OMERO_SESSION_ID, \ K_OMERO_PASSWORD, K_OMERO_CONFIG_FILE if re.match("([^=^,]+=[^=^,]+,)*([^=^,]+=[^=^,]+)", credentials_string) is None: logging.root.error( 'The OMERO credentials string, "%s", is badly-formatted.' % credentials_string) logging.root.error( 'It should have the form: ' '"host=hostname.org,port=####,user=<user>,session-id=<session-id>\n' ) raise ValueError("Invalid format for --omero-credentials") for k, v in [kv.split("=", 1) for kv in credentials_string.split(",")]: k = k.lower() credentials = { K_OMERO_SERVER: cpprefs.get_omero_server(), K_OMERO_PORT: cpprefs.get_omero_port(), K_OMERO_USER: cpprefs.get_omero_user(), K_OMERO_SESSION_ID: cpprefs.get_omero_session_id() } if k == OMERO_CK_HOST: cpprefs.set_omero_server(v, globally=False) credentials[K_OMERO_SERVER] = v elif k == OMERO_CK_PORT: cpprefs.set_omero_port(v, globally=False) credentials[K_OMERO_PORT] = v elif k == OMERO_CK_SESSION_ID: credentials[K_OMERO_SESSION_ID] = v elif k == OMERO_CK_USER: cpprefs.set_omero_user(v, globally=False) credentials[K_OMERO_USER] = v elif k == OMERO_CK_PASSWORD: credentials[K_OMERO_PASSWORD] = v elif k == OMERO_CK_CONFIG_FILE: credentials[K_OMERO_CONFIG_FILE] = v if not os.path.isfile(v): msg = "Cannot find OMERO config file, %s" % v logging.root.error(msg) raise ValueError(msg) else: logging.root.error('Unknown --omero-credentials keyword: "%s"' % k) logging.root.error('Acceptable keywords are: "%s"' % '","'.join( [OMERO_CK_HOST, OMERO_CK_PORT, OMERO_CK_SESSION_ID])) raise ValueError("Invalid format for --omero-credentials") use_omero_credentials(credentials)
def connect(self): try: server = self.omero_server_ctrl.Value port = int(self.omero_port_ctrl.Value) user = self.omero_user_ctrl.Value except: self.message_ctrl.Label = "The port number must be an integer between 0 and 65535 (try 4064)" self.message_ctrl.ForegroundColour = "red" self.message_ctrl.Refresh() return False try: self.session_id = set_omero_credentials( server, port, user, self.omero_password_ctrl.Value) self.message_ctrl.Label = "Connected" self.message_ctrl.ForegroundColour = "green" self.message_ctrl.Refresh() self.server = server self.port = port self.user = user cpprefs.set_omero_server(server) cpprefs.set_omero_port(port) cpprefs.set_omero_user(user) self.ok_button.Enable(True) return True except: self.message_ctrl.Label = "Failed to log onto server" self.message_ctrl.ForegroundColour = "red" self.message_ctrl.Refresh() return False
def set_omero_credentials_from_string(credentials_string): '''Set the OMERO server / port / session ID credentials_string: a comma-separated key/value pair string (key=value) that gives the credentials. Keys are host - the DNS name or IP address of the OMERO server port - the TCP port to use to connect user - the user name session-id - the session ID used for authentication ''' import cellprofiler.preferences as cpprefs from bioformats.formatreader import use_omero_credentials from bioformats.formatreader import \ K_OMERO_SERVER, K_OMERO_PORT, K_OMERO_USER, K_OMERO_SESSION_ID,\ K_OMERO_PASSWORD, K_OMERO_CONFIG_FILE if re.match("([^=^,]+=[^=^,]+,)*([^=^,]+=[^=^,]+)", credentials_string) is None: logging.root.error( 'The OMERO credentials string, "%s", is badly-formatted.' % credentials_string) logging.root.error( 'It should have the form: ' '"host=hostname.org,port=####,user=<user>,session-id=<session-id>\n') raise ValueError("Invalid format for --omero-credentials") for k, v in [kv.split("=", 1) for kv in credentials_string.split(",")]: k = k.lower() credentials = { K_OMERO_SERVER: cpprefs.get_omero_server(), K_OMERO_PORT: cpprefs.get_omero_port(), K_OMERO_USER: cpprefs.get_omero_user(), K_OMERO_SESSION_ID: cpprefs.get_omero_session_id() } if k == OMERO_CK_HOST: cpprefs.set_omero_server(v) credentials[K_OMERO_SERVER] = v elif k == OMERO_CK_PORT: cpprefs.set_omero_port(v) credentials[K_OMERO_PORT] = v elif k == OMERO_CK_SESSION_ID: credentials[K_OMERO_SESSION_ID] = v elif k == OMERO_CK_USER: cpprefs.set_omero_user(v) credentials[K_OMERO_USER] = v elif k == OMERO_CK_PASSWORD: credentials[K_OMERO_PASSWORD] = v elif k == OMERO_CK_CONFIG_FILE: credentials[K_OMERO_CONFIG_FILE] = v if not os.path.isfile(v): msg = "Cannot find OMERO config file, %s" % v logging.root.error(msg) raise ValueError(msg) else: logging.root.error( 'Unknown --omero-credentials keyword: "%s"' % k) logging.root.error( 'Acceptable keywords are: "%s"' % '","'.join([OMERO_CK_HOST, OMERO_CK_PORT, OMERO_CK_SESSION_ID])) raise ValueError("Invalid format for --omero-credentials") use_omero_credentials(credentials)