コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
ファイル: omerologin.py プロジェクト: Bambirez/CellProfiler
    def __init__(self, *args, **kwargs):
        super(self.__class__, self).__init__(*args, **kwargs)
        
        self.server = cpprefs.get_omero_server() or ""
        self.port = cpprefs.get_omero_port()
        self.user = cpprefs.get_omero_user() or ""
        self.session_id = None
        self.SetSizer(wx.BoxSizer(wx.VERTICAL))
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.Sizer.Add(sizer, 1, wx.EXPAND | wx.ALL, 6)
        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(sub_sizer, 0, wx.EXPAND)
        
        max_width = 0
        max_height = 0
        for label in (self.SERVER_LABEL, self.PORT_LABEL, 
                      self.USER_LABEL, self.PASSWORD_LABEL):
            w, h = self.GetTextExtent(label)
            max_width = max(w, max_width)
            max_height = max(h, max_height)
        
        lsize = wx.Size(max_width, max_height)
        sub_sizer.Add(wx.StaticText(self, label = "Server:", size = lsize), 0, 
                      wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
        sub_sizer.AddSpacer(2)
        self.omero_server_ctrl = wx.TextCtrl(self, value = self.server)
        sub_sizer.Add(self.omero_server_ctrl, 1, wx.EXPAND)
        
        sizer.AddSpacer(2)
        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(sub_sizer, 0, wx.EXPAND)
        sub_sizer.Add(wx.StaticText(self, label= "Port:", size = lsize), 0, 
                      wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
        self.omero_port_ctrl = wx.TextCtrl(self, value = str(self.port))
        sub_sizer.Add(self.omero_port_ctrl, 1, wx.EXPAND)

        sizer.AddSpacer(5)
        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(sub_sizer, 0, wx.EXPAND)
        sub_sizer.Add(wx.StaticText(self, label= "User:"******"Password:"******"", 
                                               style = wx.TE_PASSWORD)
        sub_sizer.Add(self.omero_password_ctrl, 1, wx.EXPAND)

        
        sizer.AddSpacer(5)
        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(sub_sizer, 0, wx.EXPAND)
        connect_button = wx.Button(self, label = "Connect")
        connect_button.Bind(wx.EVT_BUTTON, self.on_connect_pressed)
        sub_sizer.Add(connect_button, 0, wx.EXPAND)
        sub_sizer.AddSpacer(5)
        
        self.message_ctrl = wx.StaticText(self, label = "Not connected")
        sub_sizer.Add(self.message_ctrl, 1, wx.EXPAND)
        
        button_sizer = wx.StdDialogButtonSizer()
        self.Sizer.Add(button_sizer, 0, wx.EXPAND)
        
        cancel_button = wx.Button(self, wx.ID_CANCEL)
        button_sizer.AddButton(cancel_button)
        cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
        
        self.ok_button = wx.Button(self, wx.ID_OK)
        button_sizer.AddButton(self.ok_button)
        self.ok_button.Bind(wx.EVT_BUTTON, self.on_ok)
        self.ok_button.Enable(False)
        button_sizer.Realize()
        
        self.omero_password_ctrl.Bind(wx.EVT_TEXT, self.mark_dirty)
        self.omero_port_ctrl.Bind(wx.EVT_TEXT, self.mark_dirty)
        self.omero_server_ctrl.Bind(wx.EVT_TEXT, self.mark_dirty)
        self.omero_user_ctrl.Bind(wx.EVT_TEXT, self.mark_dirty)
        self.Layout()
コード例 #4
0
    def __init__(self, *args, **kwargs):
        super(self.__class__, self).__init__(*args, **kwargs)
        
        self.server = cpprefs.get_omero_server() or ""
        self.port = cpprefs.get_omero_port()
        self.user = cpprefs.get_omero_user() or ""
        self.session_id = None
        self.SetSizer(wx.BoxSizer(wx.VERTICAL))
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.Sizer.Add(sizer, 1, wx.EXPAND | wx.ALL, 6)
        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(sub_sizer, 0, wx.EXPAND)
        
        max_width = 0
        max_height = 0
        for label in (self.SERVER_LABEL, self.PORT_LABEL, 
                      self.USER_LABEL, self.PASSWORD_LABEL):
            w, h = self.GetTextExtent(label)
            max_width = max(w, max_width)
            max_height = max(h, max_height)
        
        lsize = wx.Size(max_width, max_height)
        sub_sizer.Add(wx.StaticText(self, label = "Server:", size = lsize), 0, 
                      wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
        sub_sizer.AddSpacer(2)
        self.omero_server_ctrl = wx.TextCtrl(self, value = self.server)
        sub_sizer.Add(self.omero_server_ctrl, 1, wx.EXPAND)
        
        sizer.AddSpacer(2)
        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(sub_sizer, 0, wx.EXPAND)
        sub_sizer.Add(wx.StaticText(self, label= "Port:", size = lsize), 0, 
                      wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
        self.omero_port_ctrl = wx.TextCtrl(self, value = str(self.port))
        sub_sizer.Add(self.omero_port_ctrl, 1, wx.EXPAND)

        sizer.AddSpacer(5)
        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(sub_sizer, 0, wx.EXPAND)
        sub_sizer.Add(wx.StaticText(self, label= "User:"******"Password:"******"", 
                                               style = wx.TE_PASSWORD)
        sub_sizer.Add(self.omero_password_ctrl, 1, wx.EXPAND)

        
        sizer.AddSpacer(5)
        sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(sub_sizer, 0, wx.EXPAND)
        connect_button = wx.Button(self, label = "Connect")
        connect_button.Bind(wx.EVT_BUTTON, self.on_connect_pressed)
        sub_sizer.Add(connect_button, 0, wx.EXPAND)
        sub_sizer.AddSpacer(5)
        
        self.message_ctrl = wx.StaticText(self, label = "Not connected")
        sub_sizer.Add(self.message_ctrl, 1, wx.EXPAND)
        
        button_sizer = wx.StdDialogButtonSizer()
        self.Sizer.Add(button_sizer, 0, wx.EXPAND)
        
        cancel_button = wx.Button(self, wx.ID_CANCEL)
        button_sizer.AddButton(cancel_button)
        cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
        
        self.ok_button = wx.Button(self, wx.ID_OK)
        button_sizer.AddButton(self.ok_button)
        self.ok_button.Bind(wx.EVT_BUTTON, self.on_ok)
        self.ok_button.Enable(False)
        button_sizer.Realize()
        
        self.omero_password_ctrl.Bind(wx.EVT_TEXT, self.mark_dirty)
        self.omero_port_ctrl.Bind(wx.EVT_TEXT, self.mark_dirty)
        self.omero_server_ctrl.Bind(wx.EVT_TEXT, self.mark_dirty)
        self.omero_user_ctrl.Bind(wx.EVT_TEXT, self.mark_dirty)
        self.Layout()