Sligtly more elegant workaround for the synchronization/buffering issue. But still only a workaround I's say

This commit is contained in:
Reto Bollinger 2024-11-28 09:02:55 +01:00
parent 855639a09d
commit 2bb845e17c
2 changed files with 6 additions and 6 deletions

View file

@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
sh -c ". /opt/venv/bin/activate && exec python /opt/lektor/scripts/calendar-fetcher.py ${CALENDAR_URL} > /opt/lektor/project/content/termine/contents.lr" sh -c ". /opt/venv/bin/activate && exec python /opt/lektor/scripts/calendar-fetcher.py ${CALENDAR_URL} > /opt/lektor/project/content/termine/contents.lr"
# TODO Something with python and reading from docker mounts is broken but only when piping # TODO As the file reads from the same file as it's output is afterwards piped into this leads to synchronization/buffering issues, we therefore write to a temporaray file and move it to the right place in a subsequent step
cp /opt/lektor/project/content/contents.lr /tmp/myshadowcopyformisbehavingpython.txt tempfile="/tmp/contents.lr"
sh -c ". /opt/venv/bin/activate && exec python /opt/lektor/scripts/calendar-fetcher-main.py ${CALENDAR_URL} > /opt/lektor/project/content/contents.lr" sh -c ". /opt/venv/bin/activate && exec python /opt/lektor/scripts/calendar-fetcher-main.py ${CALENDAR_URL} > $tempfile"
mv $tempfile /opt/lektor/project/content/contents.lr
/root/.local/bin/lektor --project /opt/lektor/project server --host 0.0.0.0 /root/.local/bin/lektor --project /opt/lektor/project server --host 0.0.0.0

View file

@ -10,9 +10,8 @@ import locale
if len(sys.argv) != 2: if len(sys.argv) != 2:
print("Usage: python3 {} <ICS_URL>".format(sys.argv[0])) print("Usage: python3 {} <ICS_URL>".format(sys.argv[0]))
# this should actually be the following file. But since piping from a Python-script which reads from a Docker-volume is broken we use the entrypoint.sh script to copy the file into the dockercontainer before running and thus we have that od /tmp/ path # TODO Reading from the same file as the output of this script is piped into leads to synchronization/buffering issues, we therefore have to do some quirks in entrypoint.sh
# sourcefile = "/opt/lektor/project/content/contents.lr" sourcefile = "/opt/lektor/project/content/contents.lr"
sourcefile = "/tmp/myshadowcopyformisbehavingpython.txt"
with open(sourcefile) as fp: with open(sourcefile) as fp:
soup = BeautifulSoup(fp, 'html.parser') soup = BeautifulSoup(fp, 'html.parser')