从配置文件中获取用户指定的server url 如果获取不到,默认从settings中获取 :param config_file: 本地配置文件路径 :return:
(config_file=None)
| 23 | """ |
| 24 | @staticmethod |
| 25 | def get_server_url(config_file=None): |
| 26 | """ |
| 27 | 从配置文件中获取用户指定的server url |
| 28 | 如果获取不到,默认从settings中获取 |
| 29 | :param config_file: 本地配置文件路径 |
| 30 | :return: |
| 31 | """ |
| 32 | # 1.从配置文件获取 |
| 33 | if not config_file: |
| 34 | cur_working_dir = os.path.abspath(os.curdir) |
| 35 | config_file = os.path.join(cur_working_dir, 'codedog.ini') |
| 36 | if os.path.exists(config_file): |
| 37 | config_dict = ConfigReader(cfg_file=config_file).read("config") |
| 38 | codedog_env = config_dict.get("codedog_env") |
| 39 | if codedog_env: |
| 40 | codedog_env = codedog_env.strip() |
| 41 | if codedog_env not in ["dev", "test", "tiyan", "prod"]: |
| 42 | # 补充http头 |
| 43 | if not codedog_env.startswith("http"): |
| 44 | codedog_env = "http://%s" % codedog_env |
| 45 | # 修正settings中的server url,不使用默认的 |
| 46 | settings.SERVER_URL["URL"] = codedog_env |
| 47 | # 设置到环境变量中,供task中使用(因为task进程的工作目录不在codedog根目录,无法获取到ini文件的codedog_env配置) |
| 48 | os.environ["CODEDOG_SERVER"] = codedog_env |
| 49 | return codedog_env |
| 50 | # 2.如果配置文件没有指定,从环境变量获取 |
| 51 | codedog_server_url = os.environ.get("CODEDOG_SERVER", None) |
| 52 | if codedog_server_url: |
| 53 | return codedog_server_url |
| 54 | # 3.默认使用setting默认对应的url地址 |
| 55 | return settings.SERVER_URL["URL"] |
no test coverage detected