Skip to content

Commit

Permalink
fix: initialization fail
Browse files Browse the repository at this point in the history
  • Loading branch information
JinnLynn committed Jun 28, 2024
1 parent 763ac50 commit 80714b4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions example/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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本地文件,在线地址获取失败时读取本地
# 默认: -
Expand Down
10 changes: 7 additions & 3 deletions src/genpac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
13 changes: 6 additions & 7 deletions src/genpac/res/tpl-config.ini
Original file line number Diff line number Diff line change
@@ -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获取相关设置

Expand All @@ -11,16 +11,16 @@
; 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

; 更新本地gfwlist文件 默认 false
; 当成功获取在线的gfwlist文件并且gfwlist-local存在,是否更新gfwlist-local
; gfwlist-update-local = false

; 获取在线文件时的代理
; proxy = SOCKS5://127.0.0.1:1080

; 用户自定义规则相关

; 规则,支持使用`,`或换行分割多个规则
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/genpac/res/tpl-user-rules.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 80714b4

Please sign in to comment.