15 Commits

Author SHA1 Message Date
8a8a725002 fix: Remove id from export
As this wil not be the same id on other instances exporting it does not make sense
2023-01-25 23:36:25 +01:00
58998e1c17 fix: Allow name to be empty in local blocklist 2023-01-25 23:35:04 +01:00
a484a41b45 Merge branch 'develop' of https://git.gieszer.link/gcrkrause/mastodon-blocklist-deploy into develop 2023-01-22 18:23:54 +01:00
Georg Krause
8d5676d0b2 refactor: Avoid manually templating toml file entries 2023-01-13 13:56:56 +01:00
6d2a4d82b4 fix: Avoid exception when input is missing for diff and deploy 2023-01-13 13:56:55 +01:00
Georg Krause
d9d3f02fda feat: Add Dockerfile for development and deployment 2023-01-13 13:56:55 +01:00
0fca58810a feat: Allow token via environment variables 2023-01-13 13:56:55 +01:00
181ac45bbf refactor: Rename load_remote_blocklist->load_blocklist_from_instance 2023-01-13 13:56:43 +01:00
6a2a13bd74 refactor: Add missing return types 2023-01-13 13:56:43 +01:00
0dd6930c0f refactor: Rename load_local_blocklist -> load_blocklist_file 2023-01-13 13:56:43 +01:00
33fee03059 Merge branch 'develop' of https://git.gieszer.link/gcrkrause/mastodon-blocklist-deploy into develop 2023-01-13 08:12:35 +01:00
2066c0332d fix: Avoid exception when input is missing for diff and deploy 2023-01-13 08:12:29 +01:00
moanos
5376af3e7e Merge pull request 'refactor: Avoid manually templating toml file entries' (#6) from toml-dump into develop
Reviewed-on: https://git.gieszer.link/gcrkrause/mastodon-blocklist-deploy/pulls/6
2023-01-13 08:08:26 +01:00
moanos
1565f17778 Merge pull request 'feat: Add Dockerfile for development and deployment' (#5) from dockerfile into develop
Reviewed-on: https://git.gieszer.link/gcrkrause/mastodon-blocklist-deploy/pulls/5
2023-01-12 22:27:21 +01:00
Georg Krause
ddc2ba1b43 feat: Add Dockerfile for development and deployment 2023-01-12 16:31:58 +01:00
4 changed files with 43 additions and 4 deletions

17
DEVELOPMENT.md Normal file
View 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
View 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 .

View File

@@ -38,6 +38,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')
@@ -79,7 +82,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 +95,10 @@ 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]}))
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)
toml.dump({"instances": [remove_key_from_dict(b.__dict__, 'id') for b in remote_blocklist]}, f)
if __name__ == "__main__":

View File

@@ -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"]