6 Commits

Author SHA1 Message Date
5340e18c22 Add showdiff 2023-07-26 11:32:59 +02:00
626516e98c Don't fetch remote blocklist when merging files 2023-07-13 11:35:32 +02:00
3d0854ac4c Use correct var 2023-07-13 11:34:42 +02:00
b5bb6f8480 Show nicer diff when merging 2023-07-13 11:33:55 +02:00
Georg Krause
d47a63e331 ci: Don't push built docker image on PRs 2023-07-13 09:52:26 +02:00
Georg Krause
3cdf24a5f3 fix(exporter): Default to toml as default format 2023-07-13 09:51:54 +02:00
3 changed files with 35 additions and 9 deletions

View File

@@ -21,3 +21,9 @@ steps:
- docker login -u $USERNAME -p $PASSWORD
- docker push gcrkrause/mastodon-blocklist-deploy
- docker image prune -a -f
when:
event:
exclude:
- pull_request
branch:
- main

View File

@@ -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:
@@ -73,12 +76,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)
@@ -103,7 +106,7 @@ def cli():
parser.add_argument('-o', '--output', help="Filename where to export the blocklist")
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-n', '--no-delete', action='store_true', help="Do not delete existing blocks")
parser.add_argument('--format', help="Export format: toml|markdown|csv|json")
parser.add_argument('--format', default="toml", type=str, help="Export format: toml|markdown|csv|json")
parser.add_argument('--private', action='store_true', help="When the flag is set, private comment will also be "
"exported.")
args = parser.parse_args()
@@ -117,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"]:

View File

@@ -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)