Merge pull request 'refactor: Avoid manually templating toml file entries' (#6) from toml-dump into develop
Reviewed-on: gcrkrause/mastodon-blocklist-deploy#6
This commit is contained in:
commit
5376af3e7e
1 changed files with 3 additions and 19 deletions
|
@ -19,23 +19,6 @@ def load_blocklist_file(filename: str) -> [Instance]:
|
|||
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) -> [Instance]:
|
||||
instances = []
|
||||
for i in blocklist_json:
|
||||
|
@ -105,9 +88,10 @@ def cli():
|
|||
Instance.apply_blocks_from_diff(diffs, args.server, token, args.no_delete)
|
||||
elif args.action == "export":
|
||||
if not args.output:
|
||||
print("Export currently requires to pass --output as well")
|
||||
print(toml.dumps({"instances": [b.__dict__ for b in remote_blocklist]}))
|
||||
else:
|
||||
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__":
|
||||
|
|
Loading…
Reference in a new issue