Compare commits
18 Commits
toml-dump
...
markdown_e
Author | SHA1 | Date | |
---|---|---|---|
8762112e37 | |||
![]() |
d4c754c103 | ||
8a8a725002 | |||
58998e1c17 | |||
a484a41b45 | |||
![]() |
7ad318bc48 | ||
![]() |
8d5676d0b2 | ||
6d2a4d82b4 | |||
![]() |
d9d3f02fda | ||
0fca58810a | |||
181ac45bbf | |||
6a2a13bd74 | |||
0dd6930c0f | |||
33fee03059 | |||
2066c0332d | |||
![]() |
5376af3e7e | ||
![]() |
1565f17778 | ||
![]() |
ddc2ba1b43 |
23
.drone.yml
Normal file
23
.drone.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: exec
|
||||
name: build
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm64
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
commands:
|
||||
- docker build -t gcrkrause/mastodon-blocklist-deploy .
|
||||
- name: push
|
||||
environment:
|
||||
USERNAME:
|
||||
from_secret: docker-hub-user
|
||||
PASSWORD:
|
||||
from_secret: docker-hub-pw
|
||||
commands:
|
||||
- docker login -u $USERNAME -p $PASSWORD
|
||||
- docker push gcrkrause/mastodon-blocklist-deploy
|
||||
- docker image prune -a -f
|
17
DEVELOPMENT.md
Normal file
17
DEVELOPMENT.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Development Guide
|
||||
|
||||
## Docker
|
||||
|
||||
In order to have a common development environment, its nice to use docker. Its quite easy. To build a new image, simply run
|
||||
|
||||
`docker build . -t mastodon_blocklist_deploy`
|
||||
|
||||
Now you can execute any commands using
|
||||
|
||||
`docker run --rm mastodon_blocklist_deploy --help`
|
||||
|
||||
If you want to avoid building new containers for each change, simply mount your code into the container using
|
||||
|
||||
`docker run --rm -v $(pwd):/app mastodon_blocklist_deploy`
|
||||
|
||||
Please be aware that changes to the package itself require a rebuild anyways.
|
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
COPY pyproject.toml poetry.lock README.md /app/
|
||||
COPY mastodon_blocklist_deploy /app/mastodon_blocklist_deploy
|
||||
WORKDIR /app
|
||||
|
||||
ENTRYPOINT ["mastodon_blocklist_deploy"]
|
||||
|
||||
RUN pip install -e .
|
@@ -7,6 +7,7 @@ import os
|
||||
import toml
|
||||
|
||||
from mastodon_blocklist_deploy.models import Instance
|
||||
from mastodon_blocklist_deploy.helpers import blocklist_to_markdown
|
||||
|
||||
|
||||
def load_blocklist_file(filename: str) -> [Instance]:
|
||||
@@ -38,6 +39,9 @@ def load_blocklist_from_instance(server: str, token: str) -> [Instance]:
|
||||
else:
|
||||
raise ConnectionError(f"Could not connect to the server ({response.status_code}: {response.reason})")
|
||||
|
||||
def remove_key_from_dict(dict, key):
|
||||
del dict[key]
|
||||
return dict
|
||||
|
||||
def cli():
|
||||
parser = argparse.ArgumentParser(description='Deploy blocklist updates to a mastodon server')
|
||||
@@ -53,6 +57,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('--markdown', action='store_true', help="Export as markdown table")
|
||||
args = parser.parse_args()
|
||||
if args.verbose:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
@@ -79,7 +84,11 @@ def cli():
|
||||
blocklist_filename = args.input_file
|
||||
else:
|
||||
blocklist_filename = "../blocklist.toml"
|
||||
local_blocklist = load_blocklist_file(blocklist_filename)
|
||||
try:
|
||||
local_blocklist = load_blocklist_file(blocklist_filename)
|
||||
except FileNotFoundError:
|
||||
print("Local blocklist file was not found. Make sure to specify it's location via -i")
|
||||
exit()
|
||||
|
||||
if args.action == "diff":
|
||||
Instance.show_diffs(local_blocklist, remote_blocklist)
|
||||
@@ -88,10 +97,16 @@ def cli():
|
||||
Instance.apply_blocks_from_diff(diffs, args.server, token, args.no_delete)
|
||||
elif args.action == "export":
|
||||
if not args.output:
|
||||
print(toml.dumps({"instances": [b.__dict__ for b in remote_blocklist]}))
|
||||
if args.markdown:
|
||||
print(blocklist_to_markdown(remote_blocklist))
|
||||
else:
|
||||
print(toml.dumps({"instances": [remove_key_from_dict(b.__dict__, 'id') for b in remote_blocklist]}))
|
||||
else:
|
||||
with open(args.output, "w") as f:
|
||||
toml.dump({"instances": [b.__dict__ for b in remote_blocklist]}, f)
|
||||
if args.markdown:
|
||||
f.write(blocklist_to_markdown(remote_blocklist))
|
||||
else:
|
||||
toml.dump({"instances": [remove_key_from_dict(b.__dict__, 'id') for b in remote_blocklist]}, f)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
6
mastodon_blocklist_deploy/helpers.py
Normal file
6
mastodon_blocklist_deploy/helpers.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from mastodon_blocklist_deploy.models import Instance
|
||||
def blocklist_to_markdown(blocklist:[Instance]):
|
||||
markdown_string = "| Instance | Status | Reason |\n | --- | --- | --- |\n"
|
||||
for instance in blocklist:
|
||||
markdown_string += f"| {instance.domain} | {instance.severity} | {instance.public_comment} |\n"
|
||||
return markdown_string
|
@@ -38,7 +38,10 @@ class Instance:
|
||||
self.reject_reports = instance_dict["reject_reports"]
|
||||
|
||||
def parse_local_block(self, instance_dict):
|
||||
self.name = instance_dict["name"]
|
||||
try:
|
||||
self.name = instance_dict["name"]
|
||||
except KeyError:
|
||||
pass
|
||||
self.domain = instance_dict["domain"]
|
||||
self.severity = instance_dict["severity"]
|
||||
self.public_comment = instance_dict["public_comment"]
|
||||
|
Reference in New Issue
Block a user