refactor: Avoid manually templating toml file entries
parent
c54beb76d3
commit
b39a2c4b4e
|
@ -19,23 +19,6 @@ def load_local_blocklist(filename: str) -> [Instance]:
|
||||||
return instances
|
return instances
|
||||||
|
|
||||||
|
|
||||||
def export_blocklist_toml(blocklist: [Instance], filname: str):
|
|
||||||
toml_str = ""
|
|
||||||
for instance in blocklist:
|
|
||||||
toml_str += f'''
|
|
||||||
[[instances]]
|
|
||||||
name = "{instance.domain}"
|
|
||||||
domain = "{instance.domain}"
|
|
||||||
severity = "{instance.severity}"
|
|
||||||
reject_media = {str(instance.reject_media).lower()}
|
|
||||||
reject_reports = {str(instance.reject_reports).lower()}
|
|
||||||
public_comment = "{instance.public_comment}"
|
|
||||||
private_comment = "{instance.private_comment}"
|
|
||||||
'''
|
|
||||||
with open(filname, "w") as f:
|
|
||||||
f.write(toml_str)
|
|
||||||
|
|
||||||
|
|
||||||
def blocklist_json_to_instances(blocklist_json: str):
|
def blocklist_json_to_instances(blocklist_json: str):
|
||||||
instances = []
|
instances = []
|
||||||
for i in blocklist_json:
|
for i in blocklist_json:
|
||||||
|
@ -97,7 +80,8 @@ def cli():
|
||||||
diffs = Instance.list_diffs(local_blocklist, remote_blocklist)
|
diffs = Instance.list_diffs(local_blocklist, remote_blocklist)
|
||||||
Instance.apply_blocks_from_diff(diffs, args.server, args.token, args.no_delete)
|
Instance.apply_blocks_from_diff(diffs, args.server, args.token, args.no_delete)
|
||||||
elif args.action == "export":
|
elif args.action == "export":
|
||||||
export_blocklist_toml(remote_blocklist, args.output)
|
with open(args.output, "w") as f:
|
||||||
|
toml.dump({"instances": [b.__dict__ for b in remote_blocklist]}, f)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue