Compare commits
8 Commits
testing
...
1c2f65b433
Author | SHA1 | Date | |
---|---|---|---|
1c2f65b433 | |||
0b37e7a10c | |||
2b6d0dd808 | |||
c2c2c23337 | |||
5340e18c22 | |||
626516e98c | |||
3d0854ac4c | |||
b5bb6f8480 |
1
fediverse_blocklist_deploy/__init__.py
Normal file
1
fediverse_blocklist_deploy/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
version = "0.1.0"
|
@@ -12,12 +12,16 @@ from fediverse_blocklist_deploy.helpers import blocklist_to_markdown, blocklist_
|
||||
|
||||
|
||||
def load_blocklist_file(filename: str) -> [Instance]:
|
||||
with open(filename, "r") as f:
|
||||
data = toml.load(f)
|
||||
instances = []
|
||||
for instance_dict in data["instances"]:
|
||||
instance = Instance(instance_dict)
|
||||
instances.append(instance)
|
||||
if filename.endswith("json"):
|
||||
with open(filename) as f:
|
||||
instances = blocklist_json_to_instances(json.load(f))
|
||||
else:
|
||||
with open(filename, "r") as f:
|
||||
data = toml.load(f)
|
||||
instances = []
|
||||
for instance_dict in data["instances"]:
|
||||
instance = Instance(instance_dict)
|
||||
instances.append(instance)
|
||||
return instances
|
||||
|
||||
|
||||
@@ -65,6 +69,9 @@ def exporter(blocklist, output=None, format: str = "toml", private: bool = False
|
||||
|
||||
|
||||
def merge(input_file, merge_target, format: str = "toml", private: bool = False, overwrite=False):
|
||||
"""Shows a table in the CLI comparing the local and remote blocklist"""
|
||||
from rich.table import Table
|
||||
from rich.console import Console
|
||||
input_blocklist = load_blocklist_file(input_file)
|
||||
merge_target_blocklist = load_blocklist_file(merge_target)
|
||||
for input_instance in input_blocklist:
|
||||
@@ -73,12 +80,12 @@ def merge(input_file, merge_target, format: str = "toml", private: bool = False,
|
||||
continue
|
||||
# Check if there is a domain in the merge target where the input domain is similar
|
||||
try:
|
||||
merge_target_instance = [merge_target_instance for merge_target_instance in merge_target if input_instance.domain == merge_target_instance.domain][0]
|
||||
merge_target_instance = [merge_target_instance for merge_target_instance in merge_target_blocklist if input_instance.domain == merge_target_instance.domain][0]
|
||||
if not overwrite:
|
||||
key_input = ""
|
||||
while key_input not in ("i", "O"):
|
||||
print(f"Different settings for {input_instance.domain} detected.")
|
||||
print(f"In the input blocklist the setting is\n{input_instance} whereas it's {merge_target_instance} in the merge target")
|
||||
Instance.show_diff(input_instance, merge_target_instance)
|
||||
key_input = input("Keep input (i) or original (o) [i/O]")
|
||||
elif key_input == "i":
|
||||
merge_target_blocklist.append(merge_target_instance)
|
||||
@@ -117,12 +124,13 @@ def cli():
|
||||
else:
|
||||
token = os.getenv('MBD_TOKEN')
|
||||
|
||||
"""if there is a remote blocklist provided load this instead of fetching it from a server (for debugging reasons)"""
|
||||
if args.remote_blocklist:
|
||||
with open(args.remote_blocklist) as f:
|
||||
remote_blocklist = blocklist_json_to_instances(json.load(f))
|
||||
else:
|
||||
remote_blocklist = load_blocklist_from_instance(server=args.server, token=token)
|
||||
"""Get a remote blocklist only when necessary"""
|
||||
if args.action in ["diff", "deploy", "export"]:
|
||||
"""if there is a remote blocklist provided load this instead of fetching it from a server (for debugging reasons)"""
|
||||
if args.remote_blocklist:
|
||||
remote_blocklist = load_blocklist_file(args.remote_blocklist)
|
||||
else:
|
||||
remote_blocklist = load_blocklist_from_instance(server=args.server, token=token)
|
||||
|
||||
"""Load local blocklist only when needed"""
|
||||
if args.action in ["diff", "deploy", "merge"]:
|
||||
|
@@ -145,3 +145,18 @@ class Instance:
|
||||
table.add_row(diff["local"].domain, diff["local"].status_str(), diff["remote"].status_str())
|
||||
console = Console()
|
||||
console.print(table)
|
||||
|
||||
@staticmethod
|
||||
def show_diff(instanceA, instanceB, column_names=('Input', 'Original')):
|
||||
from rich.table import Table
|
||||
from rich.console import Console
|
||||
table = Table(title="Differences", expand=True, show_lines=True)
|
||||
|
||||
table.add_column("Attribute", style="cyan")
|
||||
table.add_column(column_names[0], style="green")
|
||||
table.add_column(column_names[1], style="magenta")
|
||||
compare_attributes = ["domain", "severity", "obfuscate", "private_comment", "public_comment", "reject_media", "reject_reports"]
|
||||
for attr in compare_attributes:
|
||||
table.add_row(attr, str(getattr(instanceA, attr)), str(getattr(instanceB, attr)))
|
||||
console = Console()
|
||||
console.print(table)
|
||||
|
@@ -1,12 +1,12 @@
|
||||
[tool.poetry]
|
||||
name = "fediverse-blocklist-deploy"
|
||||
version = "0.1.0"
|
||||
description = "A small tool to deploy blocklist updates to a fediverse server using its API."
|
||||
description = "A small tool to export, compareof merge and deploy blocklists of a fediverse server"
|
||||
authors = ["Georg Krause <mail@georg-krause.net>", "Julian-Samuel Gebühr <julian-samuel@gebuehr.net>"]
|
||||
readme = "README.md"
|
||||
packages = [{include = "fediverse_blocklist_deploy"}]
|
||||
license = "MIT"
|
||||
keywords = ["fediverse", "blocklist", "fediverse"]
|
||||
keywords = ["fediverse", "blocklist", "mastodon", "gotosocial", "safety"]
|
||||
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
|
Reference in New Issue
Block a user