\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5982\u4f55\u57fa\u4e8epython\u5b9e\u73b0\u811a\u672c\u52a0\u5bc6,\u6587\u4e2d\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u8005\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u5b66\u4e60\u4ef7\u503c,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\r\nfrom pathlib import Path\r\nimport python_minifier\r\nimport compileall\r\nimport sys\r\n \r\ndef get_save_path(from_dir, to_dir, p):\r\n ori_dir = str(from_dir.resolve())\r\n _p = str(p.resolve())\r\n return to_dir.joinpath(_p.split(ori_dir)[-1][1:])\r\ndef mix_pyminifier(from_dir, to_dir):\r\n for _p in from_dir.rglob('*.py'):\r\n with _p.open(encoding='utf-8') as read_fp:\r\n res = python_minifier.minify(read_fp.read())\r\n \r\n _to_p = get_save_path(from_dir, to_dir, _p)\r\n Path(_to_p.parent).mkdir(exist_ok=True, parents=True)\r\n with _to_p.open('w', encoding='utf-8') as write_fp:\r\n write_fp.write(res)\r\n \r\n \r\ndef py2pyc(from_dir, to_dir):\r\n compileall.compile_dir(str(from_dir.resolve()), maxlevels=20, force=True)\r\ndef pyc2py(from_dir, to_dir):\r\n pass\r\nif __name__ == '__main__':\r\n origin_dir = Path(sys.argv[1])\r\n target_dir = Path(sys.argv[2])\r\n pymini_dir = target_dir.joinpath('pymini')\r\n pyc_dir = target_dir.joinpath('pyc_dir')\r\n py_dir = target_dir.joinpath('py_dir')\r\n mix_pyminifier(origin_dir, target_dir)\r\n # py2pyc(origin_dir, pyc_dir)\r\n # pyc2py(pyc_dir, pyc_dir)<\/pre>\n\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
from pathlib import Path import python_minifier import […]<\/p>\n","protected":false},"author":1482,"featured_media":113018,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-168628","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/168628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=168628"}],"version-history":[{"count":4,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/168628\/revisions"}],"predecessor-version":[{"id":168632,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/168628\/revisions\/168632"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/113018"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=168628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=168628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=168628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}