Beispiel #1
0
        results = {}
        if len(sql_list) != 0:
            for sql in sql_list:
                try:
                    # Only print select statment
                    # if sql.strip().lower().startswith('select'):
                    logger.debug('Execute SQL: %s' % sql)
                    cursor.execute(sql)
                    results[sql] = cursor.fetchall()
                except Exception, e:
                    logger.error('Execute SQL "%s" failed! The rease is:\n%s' % (sql, str(e)))
                    results[sql] = []
                finally:
                    cursor.close()
        else:
            logger.error('The SQL statment is None!')

        return results

    def mexec_sql(self, sql_list):
        '''Batch execute sql, which is none returns.

    Arguments:
        sql_list {list} -- The list of sql statments which will be executed

    '''

        cursor = self.connection.cursor()

        if len(sql_list) != 0:
            for sql in sql_list:
Beispiel #2
0
    target = '20190810.tar.gz'

    client = FtpClient(ip, port, user, passwd)
    while True:
        try:
            logger.info('Try to login ftp: {}:{} with {} / {}'.format(
                ip, port, user, passwd))
            client.login()
            client.set_debug()
            logger.info('Ftp login success.')
            # client.list_files('*')
            client.set_pasv(True)
            logger.info(
                'Starting download file: {} using pasv mode.'.format(target))
            client.download(target, os.path.join(os.getcwd(), target))
            logger.info(
                'Downloading file {} success using pasv mode.'.format(target))

            client.set_pasv(False)
            logger.info(
                'Starting download file: {} using port mode.'.format(target))
            client.download(target, os.path.join(os.getcwd(), target))
            logger.info(
                'Downloading file {} success using port mode.'.format(target))
        except Exception, e:
            logger.error('Error occourded: {}'.format(e))
        finally:
            client.close()

        time.sleep(300)