检查并从修改的配置信息获取必要信息 @author baozi <202-03-08> @param: changes ( dict ): 改变的项和值 config_file ( string ): 需要改变的文件 @return
(self, config_file, conf)
| 1939 | return res |
| 1940 | |
| 1941 | def __get_uwsgi_config_from_file(self, config_file, conf): |
| 1942 | """检查并从修改的配置信息获取必要信息 |
| 1943 | @author baozi <202-03-08> |
| 1944 | @param: |
| 1945 | changes ( dict ): 改变的项和值 |
| 1946 | config_file ( string ): 需要改变的文件 |
| 1947 | @return |
| 1948 | """ |
| 1949 | # 检查必要项目 |
| 1950 | check_reps = [ |
| 1951 | (r"\n\s?chdir\s{0,3}=\s{0,3}" + self.__prevent_re(conf["path"]) + r"[^\n]*\n", "不能修改项目路径"), |
| 1952 | (r"\n\s?pidfile\s{0,3}=\s{0,3}" + self.__prevent_re(conf["path"] + "/uwsgi.pid") + r"[^\n]*\n", |
| 1953 | "不能修改项目的pidfile文件位置"), |
| 1954 | (r"\n\s?master\s{0,3}=\s{0,3}true[^\n]*\n", "不能修改主进程相关配置"), |
| 1955 | ] |
| 1956 | for rep, msg in check_reps: |
| 1957 | if not re.search(rep, config_file): |
| 1958 | return False, msg |
| 1959 | |
| 1960 | get_reps = { |
| 1961 | "rfile": (r'\n\s?wsgi-file\s{0,3}=\s{0,3}(?P<target>[^#\n]*)\n', None), |
| 1962 | "module": (r'\n\s?module\s{0,3}=\s{0,3}(?P<target>[^\n/:])*:[^\n]*\n', None), |
| 1963 | "processes": (r'\n\s?processes\s{0,3}=\s{0,3}(?P<target>[\d]*)\n', None), |
| 1964 | "threads": (r'\n\s?threads\s{0,3}=\s{0,3}(?P<target>[\d]*)\n', None), |
| 1965 | "logpath": ( |
| 1966 | r'\n\s?daemonize\s{0,3}=\s{0,3}(?P<target>[^\n]*)\n', "没有检查到。配置项:日志路径,请注意您的修改") |
| 1967 | } |
| 1968 | changes = {} |
| 1969 | for k, (rep, msg) in get_reps.items(): |
| 1970 | res = re.search(rep, config_file) |
| 1971 | if not res and msg: |
| 1972 | return False, msg |
| 1973 | elif res: |
| 1974 | changes[k] = res.group("target").strip() |
| 1975 | if "module" in changes: |
| 1976 | _rfile = conf["path"] + changes["module"].replace(".", "/") + ".py" |
| 1977 | if os.path.isfile(_rfile): |
| 1978 | changes["rfile"] = _rfile |
| 1979 | changes.pop("module") |
| 1980 | |
| 1981 | if "logpath" in changes: |
| 1982 | if not os.path.exists(changes['logpath']): |
| 1983 | os.makedirs(changes['logpath'], mode=0o777) |
| 1984 | if "/" in changes["logpath"]: |
| 1985 | _path, filename = changes["logpath"].rsplit("/", 1) |
| 1986 | if filename != "uwsgi.log": |
| 1987 | return False, "为方便日志管理,日志文件名称请使用 uwsgi.log " |
| 1988 | else: |
| 1989 | changes["logpath"] = _path |
| 1990 | else: |
| 1991 | if changes["logpath"] != "uwsgi.log": |
| 1992 | return False, "为方便日志管理,日志文件名称请使用 uwsgi.log" |
| 1993 | else: |
| 1994 | changes["logpath"] = conf["path"] |
| 1995 | |
| 1996 | # port 相关查询 |
| 1997 | rep_h = r'\n\s{0,3}http\s{0,3}=\s{0,3}((\d{0,3}\.){3}\d{0,3})?:(?P<target>\d{2,5})[^\n]*\n' |
| 1998 | rep_s = r'\n\s{0,3}socket\s{0,3}=\s{0,3}((\d{0,3}\.){3}\d{0,3})?:(?P<target>\d{2,5})[^\n]*\n' |
no test coverage detected