From b5bb6f8480b163b1786bcbb805c94f3fe55c2b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Thu, 13 Jul 2023 11:33:55 +0200 Subject: [PATCH 1/4] Show nicer diff when merging --- mastodon_blocklist_deploy/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mastodon_blocklist_deploy/cli.py b/mastodon_blocklist_deploy/cli.py index 6c87248..c0e9053 100644 --- a/mastodon_blocklist_deploy/cli.py +++ b/mastodon_blocklist_deploy/cli.py @@ -65,6 +65,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: @@ -78,7 +81,7 @@ def merge(input_file, merge_target, format: str = "toml", private: bool = False, 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) -- 2.40.1 From 3d0854ac4c24f3da5a620c1ab359dc8e584f2447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Thu, 13 Jul 2023 11:34:42 +0200 Subject: [PATCH 2/4] Use correct var --- mastodon_blocklist_deploy/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mastodon_blocklist_deploy/cli.py b/mastodon_blocklist_deploy/cli.py index c0e9053..07ad346 100644 --- a/mastodon_blocklist_deploy/cli.py +++ b/mastodon_blocklist_deploy/cli.py @@ -76,7 +76,7 @@ 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"): -- 2.40.1 From 626516e98c8c1d0d45fc2c60ce3603c9b99ecf23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Thu, 13 Jul 2023 11:35:32 +0200 Subject: [PATCH 3/4] Don't fetch remote blocklist when merging files --- mastodon_blocklist_deploy/cli.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mastodon_blocklist_deploy/cli.py b/mastodon_blocklist_deploy/cli.py index 07ad346..c75d598 100644 --- a/mastodon_blocklist_deploy/cli.py +++ b/mastodon_blocklist_deploy/cli.py @@ -120,12 +120,14 @@ 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"]: + """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) """Load local blocklist only when needed""" if args.action in ["diff", "deploy", "merge"]: -- 2.40.1 From 5340e18c22dd7063a5b5bb1fd4de319752213b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Wed, 26 Jul 2023 11:32:59 +0200 Subject: [PATCH 4/4] Add showdiff --- mastodon_blocklist_deploy/models.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mastodon_blocklist_deploy/models.py b/mastodon_blocklist_deploy/models.py index b33e00d..1b87c9e 100644 --- a/mastodon_blocklist_deploy/models.py +++ b/mastodon_blocklist_deploy/models.py @@ -138,3 +138,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) -- 2.40.1