text: """
  Django settings for open-cmdb project.
  
  Generated by 'django-admin startproject' using Django 2.0.8.
  
  For more information on this file, see
  https://docs.djangoproject.com/en/2.0/topics/settings/
  
  For the full list of settings and their values, see
  https://docs.djangoproject.com/en/2.0/ref/settings/
  """
  import datetime
  import os
  
  import pymysql
  
  pymysql.install_as_MySQLdb()
  
  # 本机的ssh免密用户
  LOCAL_SSH_USER = 'usera'
  KEY_FILE = '/home/{}/.ssh/id_rsa'.format(LOCAL_SSH_USER)
  if not os.path.isfile(KEY_FILE):
      print('用户{}的秘钥不存在，请提前生成'.format(LOCAL_SSH_USER))
      os._exit(1)
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
  # swagger login/out
  LOGIN_URL = 'rest_framework:login'
  LOGOUT_URL = 'rest_framework:logout'
  
  # Extend User
  AUTH_USER_MODEL = 'account.User'
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = 'by#cphl_dh+7e(eeg#cd52@5k=6*@lwy^u4*5qmi+nof_$wl&^'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = True
  
  ALLOWED_HOSTS = ['*']
  
  # restful framework paganation
  REST_FRAMEWORK = {
      'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated', ),
      'DEFAULT_AUTHENTICATION_CLASSES': (  # 支持验证方式 token，session，basic
          'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
          'rest_framework.authentication.SessionAuthentication',
          'rest_framework.authentication.BasicAuthentication',
      )
  }
  
  # 认证后端列表
  AUTHENTICATION_BACKENDS = (
      'rest_framework.authentication.TokenAuthentication',
      'django.contrib.auth.backends.ModelBackend',
      'guardian.backends.ObjectPermissionBackend',
  )
  
  # jwt setting
  JWT_AUTH = {
      'JWT_ENCODE_HANDLER':
      'rest_framework_jwt.utils.jwt_encode_handler',
  
      'JWT_DECODE_HANDLER':
      'rest_framework_jwt.utils.jwt_decode_handler',
  
      'JWT_PAYLOAD_HANDLER':
      'rest_framework_jwt.utils.jwt_payload_handler',
  
      'JWT_PAYLOAD_GET_USER_ID_HANDLER':
      'rest_framework_jwt.utils.jwt_get_user_id_from_payload_handler',
  
      'JWT_RESPONSE_PAYLOAD_HANDLER':
      'rest_framework_jwt.utils.jwt_response_payload_handler',
  
      'JWT_SECRET_KEY': SECRET_KEY,
      'JWT_GET_USER_SECRET_KEY': None,
      'JWT_PUBLIC_KEY': None,
      'JWT_PRIVATE_KEY': None,
      'JWT_ALGORITHM': 'HS256',
      'JWT_VERIFY': True,
      'JWT_VERIFY_EXPIRATION': True,
      'JWT_LEEWAY': 0,
      'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=12000),
      'JWT_AUDIENCE': None,
      'JWT_ISSUER': None,
  
      'JWT_ALLOW_REFRESH': False,
      'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
  
      'JWT_AUTH_HEADER_PREFIX': 'JWT',
      'JWT_AUTH_COOKIE': None,
  
  }
  
  # Application definition
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'corsheaders',
      'channels',
      'rest_framework',
      'rest_framework_swagger',
      'account',
      'category',
      'history'
  ]
  
  ASGI_APPLICATION = 'category.routing.application'
  
  MIDDLEWARE = [
      'corsheaders.middleware.CorsMiddleware',
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      #'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  ]
  
  ROOT_URLCONF = 'open-cmdb.urls'
  
  # 跨域设置
  CORS_ALLOW_CREDENTIALS = True
  CORS_ORIGIN_ALLOW_ALL = True
  CORS_ORIGIN_WHITELIST = (
      '*'
  )
  
  CORS_ALLOW_METHODS = (
      'DELETE',
      'GET',
      'OPTIONS',
      'PATCH',
      'POST',
      'PUT',
      'VIEW',
  )
  
  CORS_ALLOW_HEADERS = (
      'XMLHttpRequest',
      'X_FILENAME',
      'accept-encoding',
      'authorization',
      'content-type',
      'dnt',
      'origin',
      'user-agent',
      'x-csrftoken',
      'x-requested-with',
      'Pragma',
  )
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [],
          'APP_DIRS': True,
          'OPTIONS': {
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
      },
  ]
  
  WSGI_APPLICATION = 'open-cmdb.wsgi.application'
  
  # Database
  # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.sqlite3',
          'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
      }
  }
  
  '''
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.mysql',
          'NAME': 'cmdb',
          'USER': 'root',
          'PASSWORD': '123456',
          'HOST':'127.0.0.1',
          'PORT':'3306',
          'OPTIONS': {'charset':'utf8mb4'},
      },
  }
  '''
  
  # Password validation
  # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
  
  AUTH_PASSWORD_VALIDATORS = [
      {
          'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
      },
  ]
  
  # Internationalization
  # https://docs.djangoproject.com/en/2.0/topics/i18n/
  
  LANGUAGE_CODE = 'en-us'
  
  TIME_ZONE = 'Asia/Shanghai'
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = False
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/2.0/howto/static-files/
  
  STATIC_URL = '/static/'
  
  # LDAP
  LDAP = {
      'host': "127.0.0.1",  # LDAP服务器地址
      'port': 389  # LDAP端口
  }
  
  
  TMP_DIR = os.path.join(BASE_DIR, 'tmp')
  
  if not os.path.isdir(TMP_DIR):
      os.makedirs(TMP_DIR)
  
  # LOG
  BASE_LOG_DIR = os.path.join(BASE_DIR, "logs")
  
  LOGGING = {
      'version': 1,  # 保留字
      'disable_existing_loggers': False,  # 禁用已经存在的logger实例
      # 日志文件的格式
      'formatters': {
          # 详细的日志格式
          'standard': {
              'format': '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]'
                        '[%(levelname)s][%(message)s]'
          },
          # 简单的日志格式
          'simple': {
              'format': '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
          },
          # 定义一个特殊的日志格式
          'collect': {
              'format': '%(message)s'
          }
      },
      # 过滤器
      'filters': {
          'require_debug_true': {
              '()': 'django.utils.log.RequireDebugTrue',
          },
      },
      # 处理器
      'handlers': {
          # 在终端打印
          'console': {
              'level': 'DEBUG',
              'filters': ['require_debug_true'],  # 只有在Django debug为True时才在屏幕打印日志
              'class': 'logging.StreamHandler',  #
              'formatter': 'simple'
          },
          # 默认的
          'default': {
              'level': 'INFO',
              'class': 'logging.handlers.RotatingFileHandler',  # 保存到文件，自动切
              'filename': os.path.join(BASE_LOG_DIR, "info.log"),  # 日志文件
              'maxBytes': 1024 * 1024 * 50,  # 日志大小 50M
              'backupCount': 3,  # 最多备份几个
              'formatter': 'standard',
              'encoding': 'utf-8',
          },
          # 专门用来记错误日志
          'error': {
              'level': 'ERROR',
              'class': 'logging.handlers.RotatingFileHandler',  # 保存到文件，自动切
              'filename': os.path.join(BASE_LOG_DIR, "error.log"),  # 日志文件
              'maxBytes': 1024 * 1024 * 50,  # 日志大小 50M
              'backupCount': 5,
              'formatter': 'standard',
              'encoding': 'utf-8',
          },
          # 专门定义一个收集特定信息的日志
          'collect': {
              'level': 'INFO',
              'class': 'logging.handlers.RotatingFileHandler',  # 保存到文件，自动切
              'filename': os.path.join(BASE_LOG_DIR, "collect.log"),
              'maxBytes': 1024 * 1024 * 50,  # 日志大小 50M
              'backupCount': 5,
              'formatter': 'collect',
              'encoding': "utf-8"
          }
      },
      'loggers': {
         # 默认的logger应用如下配置
          '': {
              'handlers': ['default', 'console', 'error'],  # 上线之后可以把'console'移除
              'level': 'DEBUG',
              'propagate': True,  # 向不向更高级别的logger传递
          },
          # 名为 'collect'的logger还单独处理
          'collect': {
              'handlers': ['console', 'collect'],
              'level': 'INFO',
          }
      },
  }
  