From 80714b4be9c16de35fa290409da804f7001cffef Mon Sep 17 00:00:00 2001 From: JinnLynn Date: Fri, 28 Jun 2024 11:48:48 +0800 Subject: [PATCH] fix: initialization fail --- example/config.ini | 4 ++-- src/genpac/core.py | 10 +++++++--- src/genpac/res/tpl-config.ini | 13 ++++++------- src/genpac/res/tpl-user-rules.txt | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/example/config.ini b/example/config.ini index 72a2790f..e6efc73c 100644 --- a/example/config.ini +++ b/example/config.ini @@ -18,9 +18,9 @@ # gfwlist文件网址,留空使用默认,值为`-`则表示不在线获取 gfwlist-url = https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt -# 获取gfwlist时的代理 +# 获取在线文件时使用的代理 # 默认: 空 -# gfwlist-proxy = SOCKS5://127.0.0.1:9527 +# proxy = SOCKS5://127.0.0.1:9527 # gfwlist本地文件,在线地址获取失败时读取本地 # 默认: - diff --git a/src/genpac/core.py b/src/genpac/core.py index 8fefea42..ebfb4be0 100644 --- a/src/genpac/core.py +++ b/src/genpac/core.py @@ -200,7 +200,11 @@ def update_opt(self, args, cfgs, key, def parse_options(self, cli=True): parser, opts = self.init_options() args = parser.parse_args() if cli else Namespace() + self.init_dest = args.init if hasattr(args, 'init') else None + if self.init_dest: + return + config_file = args.config if hasattr(args, 'config') else \ self.config_file @@ -267,20 +271,20 @@ def run(self, cli=True): def init(self, dest, force=False): try: - path = abspath(dest) + path = os.getcwd() if dest is True else abspath(dest) if not os.path.isdir(path): os.makedirs(path) config_dst = os.path.join(path, 'config.ini') user_rule_dst = os.path.join(path, 'user-rules.txt') exist = os.path.exists(config_dst) or os.path.exists(user_rule_dst) if not force and exist: - raise FatalIOError('config file already exists.') + raise FatalIOError('配置文件已经存在') with open_file(config_dst, 'w') as fp: fp.write(get_resource_data('res/tpl-config.ini')) with open_file(user_rule_dst, 'w') as fp: fp.write(get_resource_data('res/tpl-user-rules.txt')) except Exception as e: - raise FatalError(f'初始化失败: {e}') + exit_error(f'初始化失败: {e}') class Generator(object): diff --git a/src/genpac/res/tpl-config.ini b/src/genpac/res/tpl-config.ini index d261137e..c360fce5 100644 --- a/src/genpac/res/tpl-config.ini +++ b/src/genpac/res/tpl-config.ini @@ -1,7 +1,7 @@ ; 配置示例 ; 注: 命令中直接输入的选项优先级高于配置文件 ; 布尔型的设置仅当为true时才为真 -; 参考: https://github.com/JinnLynn/genpac/blob/master/sample/config.ini +; 参考: https://github.com/JinnLynn/genpac/blob/master/example/config.ini [config] ; gfwlist获取相关设置 @@ -11,9 +11,6 @@ ; gfwlist文件网址,留空使用默认,值为`-`则表示不在线获取 ; gfwlist-url = https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt -; 获取gfwlist时的代理 -; gfwlist-proxy = SOCKS5 127.0.0.1:9527 - ; gfwlist本地文件,在线地址获取失败时读取本地 ; gfwlist-local = /PATH/TO/GFWLIST/LOCAL @@ -21,6 +18,9 @@ ; 当成功获取在线的gfwlist文件并且gfwlist-local存在,是否更新gfwlist-local ; gfwlist-update-local = false +; 获取在线文件时的代理 +; proxy = SOCKS5://127.0.0.1:1080 + ; 用户自定义规则相关 ; 规则,支持使用`,`或换行分割多个规则 @@ -39,6 +39,5 @@ ; 生成一个PAC文件 [job:pac] -pac-proxy = SOCKS5 127.0.0.1:9527 -pac-compress = true -pac-precise = false +pac-proxy = "SOCKS5 127.0.0.1:1080; DIRECT" +output = /tmp/proxy.pac diff --git a/src/genpac/res/tpl-user-rules.txt b/src/genpac/res/tpl-user-rules.txt index 8611f6d0..673b9651 100644 --- a/src/genpac/res/tpl-user-rules.txt +++ b/src/genpac/res/tpl-user-rules.txt @@ -1,5 +1,5 @@ ! 用户规则自定义文件 -! 参考: https://github.com/JinnLynn/genpac/blob/master/sample/user-rules.txt +! 参考: https://github.com/JinnLynn/genpac/blob/master/example/user-rules.txt @@sina.com @@163.com