浏览代码

config opt

liqian 3 年之前
父节点
当前提交
9009a9bc17
共有 3 个文件被更改,包括 14 次插入7 次删除
  1. 0 3
      .gitignore
  2. 14 3
      config.py
  3. 0 1
      env.conf

+ 0 - 3
.gitignore

@@ -59,6 +59,3 @@ docs/_build/
 target/
 
 .idea/
-
-env.conf
-

+ 14 - 3
config.py

@@ -1,3 +1,8 @@
+import os
+from log import Log
+log_ = Log()
+
+
 class BaseConfig(object):
     # 产品标识
     APP_TYPE = {
@@ -259,10 +264,13 @@ class ProductionConfig(BaseConfig):
 
 
 def set_config():
-    with open('env.conf', 'r') as env_f:
-        line = env_f.read()
-        env = line.split('=')[1].strip()
+    # 获取环境变量 ROV_SERVER_ENV
+    env = os.environ.get('ROV_SERVER_ENV')
+    if env is None:
+        log_.error('ENV ERROR: is None!')
+        return
     if env == 'dev':
+        print(1)
         return DevelopmentConfig()
     elif env == 'test':
         return TestConfig()
@@ -270,3 +278,6 @@ def set_config():
         return PreProductionConfig()
     elif env == 'pro':
         return ProductionConfig()
+    else:
+        log_.error('ENV ERROR: is {}'.format(env))
+        return

+ 0 - 1
env.conf

@@ -1 +0,0 @@
-ENV=dev