Skip to content

Commit

Permalink
feat: order formater
Browse files Browse the repository at this point in the history
  • Loading branch information
JinnLynn committed Jun 12, 2024
1 parent 6dd1d17 commit 3f6eb20
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/genpac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ def __init__(self, config_file=None):
self.extra_jobs = []

@classmethod
def add_formater(cls, name, fmt_cls, **options):
def add_formater(cls, name, fmt_cls, **kwargs):
fmt_cls._name = name.lower()
if fmt_cls._name in cls._formaters:
raise RuntimeError(f'输出格式{fmt_cls._name}重复')
fmt_cls._desc = options.pop('desc', None)
fmt_cls._desc = kwargs.pop('desc', None)
order = kwargs.pop('order', 0)
cls._formaters[name] = {'cls': fmt_cls,
'options': options}
'order': order,
'options': kwargs}
cls._formaters = OrderedDict(sorted(cls._formaters.items(), key=lambda v: v[1].get('order')))

@classmethod
def walk_formaters(cls, attr, *args, **kwargs):
Expand Down Expand Up @@ -246,7 +249,6 @@ def generate_all(self):
logger.debug(f'Job done: {job.format} => {job.output}')

def generate(self, job):
pprint(job)
if not job.format:
raise FatalError('生成的格式不能为空, 检查命令参数--format或配置项format')
if job.format not in self._formaters:
Expand Down
4 changes: 2 additions & 2 deletions src/genpac/format/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'''


@formater('wingy', desc='Wingy是iOS下基于NEKit的代理App, 无可用参数\n* 注意: 即将废弃 *')
@formater('wingy', desc='Wingy是iOS下基于NEKit的代理App, 无可用参数\n* 注意: 即将废弃 *', order=100)
class FmtWingy(FmtBase):
_default_tpl = _TPL_WINGY

Expand Down Expand Up @@ -125,7 +125,7 @@ def ss_uri(aid, uri):
'''


@formater('potatso', desc='Potatso2是iOS下基于NEKit的代理App, 无可用参数 \n* 注意: 即将废弃 *')
@formater('potatso', desc='Potatso2是iOS下基于NEKit的代理App, 无可用参数 \n* 注意: 即将废弃 *', order=100)
class FmtPotatso(FmtBase):
_default_tpl = _TPL_POTATSO

Expand Down
2 changes: 1 addition & 1 deletion src/genpac/format/dnsmasq.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
_DEF_DNS = '127.0.0.1#53'


@formater('dnsmasq', desc='Dnsmasq配合iptables/ipset、nftables/nftset可实现基于域名的透明代理')
@formater('dnsmasq', desc='Dnsmasq配合iptables/ipset、nftables/nftset可实现基于域名的透明代理', order=-90)
class FmtDnsmasq(FmtBase):
_default_tpl = _TPL

Expand Down
2 changes: 1 addition & 1 deletion src/genpac/format/pac.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
_TPL_PAC_PRECISE_MIN = TemplateFile('res/tpl-pac-precise.min.js', True)


@formater('pac', desc='通过代理自动配置文件(PAC)系统或浏览器可自动选择合适的代理服务器')
@formater('pac', desc='通过代理自动配置文件(PAC)系统或浏览器可自动选择合适的代理服务器', order=-100)
class FmtPAC(FmtBase):
_default_tpl = _TPL_PAC

Expand Down
2 changes: 1 addition & 1 deletion src/genpac/format/surge.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'''


@formater('surge', desc=_DESC)
@formater('surge', desc=_DESC, order=100)
class FmtSurge(FmtBase):
_default_tpl = _TPL

Expand Down
2 changes: 1 addition & 1 deletion src/genpac/format/v2ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def increase_indent(self, flow=False, indentless=False):
_DEF_FORMAT = list(V2RAY_DUMPER.keys())[0]


@formater('v2ray', desc='V2Ray的路由规则')
@formater('v2ray', desc='V2Ray的路由规则', order=-80)
class FmtV2Ray(FmtBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down

0 comments on commit 3f6eb20

Please sign in to comment.