Example #1
0
    def _connect(self):
        try:
            self._pool = redis.ConnectionPool(
                host=get_config(self.config, 'host'),
                port=get_config(self.config, 'port'),
                password=get_config(self.config, 'password'))
            self._redis_tmp = redis.Redis(connection_pool=self._pool)

            self.log_redis.info(
                "[The Redis Connect success] [Config:{}]".format(self.config))

        except Exception as e:
            self.log_redis.error(
                '[The Redis Connect failed] [Config:{}] [ErrorInfo:{}] [Trace:{}]'
                .format(self.config, e, traceback.format_exc()))
Example #2
0
    def _get_connection(self):
        try:
            _lcon = ldap.initialize(get_config(self.config_name, 'path'))
            _lcon.protocol_version = ldap.VERSION3
            _lcon.simple_bind_s(get_config(self.config_name, 'user'),
                                get_config(self.config_name, 'passwd'))

            self.log_ldap.info('[The LDAP Connect success] [Config:{}]'.format(
                self.config_name))

            return _lcon

        except ldap.LDAPError as e:
            self.log_ldap.error(
                '[The LDAP connect failed] [Config:{}] [ErrorInfo:{}] [Trace:{}]'
                .format(self.config_name, e, traceback.format_exc()))
            return False
Example #3
0
 def _get_con(self):
     '''
         配置说明:
             dbapi:数据库接口
             mincached:启动时开启的空连接数量
             maxcached:连接池最大可用连接数量
             maxshared:连接池最大可共享连接数量
             maxconnections:最大允许连接数量
             blocking:达到最大数量时是否阻塞
             maxusage:单个连接最大复用次数
             setsession:用于传递到数据库的准备会话
     '''
     try:
         self._pool = PooledDB(
             creator=mysql.connector,
             mincached=2,
             maxcached=5,
             host=get_config(self.config_name, 'dbhost'),
             port=int(get_config(self.config_name, 'dbport')),
             user=get_config(self.config_name, 'dbuser'),
             passwd=get_config(self.config_name, 'dbpasswd'),
             database=get_config(self.config_name, 'dbname'),
             charset=get_config(self.config_name, 'dbcharset'))
     except mysql.connector.Error as e:
         self.log_sql.error(
             '[The MySQL Connect failed] [Config:{}] [ErrorInfo:{}] [Trace:{}]'
             .format(self.config_name, e, traceback.format_exc()))
     else:
         self.log_sql.info('[The MySQL Connect success] [Config:{}]'.format(
             self.config_name))
Example #4
0
    def manage(self, keyword):
        if get_config('logconfig', 'path') == "":
            project_path = os.path.dirname(os.path.abspath(__file__))
            logs_path = project_path.replace("app/utils", "logs")

        else:
            logs_path = get_config('logconfig', 'path')

        log_file = "%s/%s.log" % (logs_path, keyword)

        tmp = logging.getLogger(log_file)

        handler = logging.handlers.TimedRotatingFileHandler(
            log_file,
            when=get_config('logconfig', 'time_type'),
            interval=int(get_config('logconfig', 'time_count')),
            backupCount=int(get_config('logconfig', 'log_max')),
            encoding='UTF-8')

        handler.suffix = "backup_%Y%m%d_%H-%M-%S.log"

        logging_format = logging.Formatter(
            '[%(levelname)s] [%(asctime)s] [%(message)s]')

        handler.setFormatter(logging_format)

        tmp.setLevel(get_config('logconfig', 'least').upper())
        tmp.addHandler(handler)

        self.logging_tmp = tmp
Example #5
0
    def show(self, name):
        try:
            searchScope = ldap.SCOPE_SUBTREE
            retrieveAttributes = None
            findname = 'cn=' + name
            result_id = self._con.search(
                get_config(self.config_name, 'base_dn'), searchScope, findname,
                retrieveAttributes)
            result_type, result_data = self._con.result(result_id)

            result = result_data if len(result_data) != 0 else False

            self.log_ldap.info(
                "[The LDAP execute get information success] [Config:{}] [Name:{}]"
                .format(self.config_name, name))

            return result

        except ldap.LDAPError as e:
            self.log_ldap.error(
                '[The LDAP execute get information failed] [Config:{}] [Name:{}] [ErrorInfo:{}] [Trace:{}]'
                .format(self.config_name, name, e, traceback.format_exc()))
            return False