Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.3.1: 优化命令行和JmOption的配置方式,简化使用 #139

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
v2.3.1: 优化命令行和JmOption的配置方式,简化使用
  • Loading branch information
hect0x7 committed Sep 21, 2023
commit 6797e4fbb803a1618982621c4f0bb7d9d9245079
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
entry_points={
'console_scripts': [
'jmcomic = jmcomic:main'
'jmcomic = jmcomic.cl:main'
]
}
)
3 changes: 1 addition & 2 deletions src/jmcomic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# 被依赖方 <--- 使用方
# config <--- entity <--- toolkit <--- client <--- option <--- downloader

__version__ = '2.3.0'
__version__ = '2.3.1'

from .api import *
from .jm_plugin import *
from .cl import main
8 changes: 5 additions & 3 deletions src/jmcomic/cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ def parse_arg(self):
parser.add_argument(
'--option',
help='path to the option file, you can also specify it by env `JM_OPTION_PATH`',
type=str,
default=get_env('JM_OPTION_PATH', ''),
)

args = parser.parse_args()
if len(args.option) != 0:
self.option_path = os.path.abspath(args.option)
else:
option = args.option
if len(option) == 0 or option == "''":
self.option_path = None
else:
self.option_path = os.path.abspath(option)

self.raw_id_list = args.id_list
self.parse_raw_id()
Expand Down
36 changes: 27 additions & 9 deletions src/jmcomic/jm_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,29 @@ def decide_image_filepath(self, image: JmImageDetail) -> str:
下面是创建对象相关方法
"""

@classmethod
def default_dict(cls) -> Dict:
return JmModuleConfig.option_default_dict()

@classmethod
def default(cls, proxies=None, domain=None) -> 'JmOption':
"""
使用默认的 JmOption
proxies, domain 为常用配置项,为了方便起见直接支持参数配置。
其他配置项建议还是使用配置文件
@param proxies: clash; 127.0.0.1:7890; v2ray
@param domain: 18comic.vip; ["18comic.vip"]
"""
if proxies is not None or domain is not None:
return cls.construct({
'client': {
'domain': [domain] if isinstance(domain, str) else domain,
'postman': {'meta_data': {'proxies': ProxyBuilder.build_by_str(proxies)}},
},
})

return cls.construct({})

@classmethod
def construct(cls, dic: Dict, cover_default=True) -> 'JmOption':
if cover_default:
Expand Down Expand Up @@ -286,7 +309,10 @@ def new_jm_client(self, domain_list=None, impl=None, **kwargs) -> JmcomicClient:
postman = Postmans.create(data=postman_conf)

# domain_list
domain_list: List[str] = domain_list or self.client.domain
if domain_list is None:
domain_list = self.client.domain

domain_list: List[str]
if len(domain_list) == 0:
domain_list = [JmModuleConfig.domain()]

Expand All @@ -303,14 +329,6 @@ def new_jm_client(self, domain_list=None, impl=None, **kwargs) -> JmcomicClient:

return client

@classmethod
def default_dict(cls) -> Dict:
return JmModuleConfig.option_default_dict()

@classmethod
def default(cls):
return cls.construct({})

@classmethod
def merge_default_dict(cls, user_dict, default_dict=None):
"""
Expand Down