示例#1
0
    def get_connection_info(self, id):
        """get_connection_info(id: int) -> dict
        Returns info of ExtConnection """
        conn = self.__list.get_connection(id)
        if conn != None:
            succeeded = False
            key = str(conn.id) + "." + conn.name + "." + conn.host
            passwd = DBLocator.keyChain.get_key(key)
            config = {
                'host': conn.host,
                'port': conn.port,
                'user': conn.user,
                'passwd': passwd
            }
            try:
                test_db_connection(config)
                succeeded = True
            except VistrailsDBException:
                succeeded = False

            config['id'] = conn.id
            config['name'] = conn.name
            config['db'] = conn.database
            config['succeeded'] = succeeded
        else:
            config = None
        return config
 def get_connection_info(self, id):
     """get_connection_info(id: int) -> dict
     Returns info of ExtConnection """
     conn = self.__list.get_connection(id)
     if conn != None:
         succeeded = False
         key = str(conn.id) + "." + conn.name + "." + conn.host
         passwd = DBLocator.keyChain.get_key(key)
         config = {'host': conn.host,
                   'port': conn.port,
                   'user': conn.user,
                   'passwd': passwd}
         try:
             test_db_connection(config)
             succeeded = True
         except VistrailsDBException:
             succeeded = False
             
         config['id'] = conn.id
         config['name'] = conn.name
         config['db'] = conn.database
         config['succeeded'] = succeeded
     else:
         config = None
     return config
示例#3
0
    def update_from_console(self):
        config = self.find_connection_info(self._host, self._port, self._db)

        if config is None:
            # the problem here is if VisTrails is being run through command
            # line from LaTex, stdout is being redirected to a log file, so
            # the user does not see the prompt in raw_input. getpass uses the
            # controlling terminal so it works fine. Just to make sure he sees
            # the first message prompt we will the controlling terminal
            try:
                f = open('/dev/tty', 'w')
                f.write("\nConnect to db with username [%s]: " % self._user)
                f.close()
                user = raw_input()
            except:
                debug.warning("Couldn't write to terminal. Will try stdout")
                user = raw_input("Connecting to db with username[%s]: " %
                                 self._user)
            try:
                if user != '':
                    self._user = user
                passwd = getpass.getpass("password:")
                self._passwd = passwd
                config = {
                    'host': self._host,
                    'port': int(self._port),
                    'user': self._user,
                    'passwd': self._passwd,
                    'db': self._db
                }
                test_db_connection(config)
                config['succeeded'] = True
                config['name'] = '%s@%s' % (self._user, self._host)
                config['id'] = -1
            except VistrailsDBException, e:
                debug.critical('VisTrails DB Exception', str(e))
                config['succeeded'] = False
            except Exception, e2:
                debug.critical('VisTrails Exception', str(e2))
                config['succeeded'] = False
def checkConnection(connectionList):
    """checkConnection() -> None
    It will try if the connection works or if a password is necessary

    """
    conn_id = connectionList.getCurrentItemId()
    if conn_id != -1:
        conn = connectionList.get_connection(conn_id)
        config = getConnectionInfo(connectionList, conn_id)
        if config != None:
            try:
                config_name = config['name']
                del config['name']
                config_id = config['id']
                del config['id']
                test_db_connection(config)
            except VistrailsDBException:
                # assume connection is wrong
                config['name'] = config_name
                config['id'] = config_id
                config["create"] = False
                showConnConfig(connectionList, **config)
示例#5
0
def checkConnection(connectionList):
    """checkConnection() -> None
    It will try if the connection works or if a password is necessary

    """
    conn_id = connectionList.getCurrentItemId()
    if conn_id != -1:
        conn = connectionList.get_connection(conn_id)
        config = getConnectionInfo(connectionList, conn_id)
        if config != None:
            try:
                config_name = config['name']
                del config['name']
                config_id = config['id']
                del config['id']
                test_db_connection(config)
            except VistrailsDBException:
                # assume connection is wrong
                config['name'] = config_name
                config['id'] = config_id
                config["create"] = False
                showConnConfig(connectionList, **config)
 def update_from_console(self):
     config = self.find_connection_info(self._host, self._port, self._db)
     
     if config is None:
         # the problem here is if VisTrails is being run through command
         # line from LaTex, stdout is being redirected to a log file, so
         # the user does not see the prompt in raw_input. getpass uses the 
         # controlling terminal so it works fine. Just to make sure he sees 
         # the first message prompt we will the controlling terminal
         try:
             f= open('/dev/tty', 'w')
             f.write("\nConnect to db with username [%s]: "%self._user)
             f.close()
             user = raw_input()
         except:
             debug.warning("Couldn't write to terminal. Will try stdout")
             user = raw_input("Connecting to db with username[%s]: "%self._user)
         try:
             if user != '':
                 self._user = user
             passwd = getpass.getpass("password:")
             self._passwd = passwd
             config = {'host': self._host,
                       'port': int(self._port),
                       'user': self._user,
                       'passwd': self._passwd,
                       'db': self._db
                       }
             test_db_connection(config)
             config['succeeded'] = True
             config['name'] = '%s@%s'%(self._user,self._host)
             config['id'] = -1
         except VistrailsDBException, e:
             debug.critical('VisTrails DB Exception',  str(e))
             config['succeeded'] = False
         except Exception, e2:
             debug.critical('VisTrails Exception', str(e2))
             config['succeeded'] = False
示例#7
0
                config['succeeded'] = False
        if config is not None:
            if config['succeeded'] == False:
                passwd = getpass.getpass(
                    "\nVisTrails DB password for user %s:" % config['user'])
                self._user = config['user']
                self._passwd = passwd
                dbconfig = {
                    'host': self._host,
                    'port': int(self._port),
                    'user': self._user,
                    'passwd': self._passwd,
                    'db': self._db
                }
                try:
                    test_db_connection(dbconfig)
                    config['succeeded'] = True
                    config['passwd'] = self._passwd
                except VistrailsDBException, e:
                    debug.critical('VisTrails DB Exception', str(e))
                    config['succeeded'] = False

            if config['succeeded'] == True:
                self._host = config['host']
                self._port = config['port']
                self._db = config['db']
                self._user = config['user']
                self._passwd = config['passwd']
                self.ext_connection_id = self.set_connection_info(**config)
                return True
            return False
     except Exception, e2:
         debug.critical('VisTrails Exception', str(e2))
         config['succeeded'] = False
 if config is not None:
     if config['succeeded'] == False:
         passwd = getpass.getpass("\nVisTrails DB password for user %s:"%config['user'])
         self._user = config['user']
         self._passwd = passwd
         dbconfig = {'host': self._host,
                   'port': int(self._port),
                   'user': self._user,
                   'passwd': self._passwd,
                   'db': self._db
                   }
         try:
             test_db_connection(dbconfig)
             config['succeeded'] = True
             config['passwd'] = self._passwd
         except VistrailsDBException, e:
             debug.critical('VisTrails DB Exception',  str(e))
             config['succeeded'] = False
     
     if config['succeeded'] == True:
         self._host = config['host']
         self._port = config['port']
         self._db = config['db']
         self._user = config['user']
         self._passwd = config['passwd']
         self.ext_connection_id = self.set_connection_info(**config)
         return True
     return False