From 654f6720fa5c14d80682f63e955e04f52376d810 Mon Sep 17 00:00:00 2001 From: Homer S Date: Tue, 29 Jun 2021 14:26:04 +0200 Subject: [PATCH] * had a hard time with docker image only to find out in the end - after hours - that I commented out the matrix-commander command for testing purposes :see-no-evil: * There is still testing if I use ENTRYPOINT in the _Dockerfile_ or only entrypoint in the _docker-compose.yml_ as the latter worked well and without any problem. * fritzab2matrix.py is now executable (WATCHOUT! The hashbang points to your system's python3 NOT to your virtualenv where the dependencies are met!) * the monitoring is now part of the main function --- docker/Dockerfile | 13 +++++-------- docker/docker-compose.yml | 5 +++-- fritzab2matrix.py | 21 +++++++++++++++------ 3 files changed, 23 insertions(+), 16 deletions(-) mode change 100644 => 100755 fritzab2matrix.py diff --git a/docker/Dockerfile b/docker/Dockerfile index 22330e4..4989b6a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,23 +3,20 @@ FROM ubuntu:latest ENV TZ=Europe/Berlin -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone WORKDIR /app VOLUME /app COPY . . -RUN ls -la -RUN ["cat", "/app/requirements.txt"] - -RUN /bin/bash -c 'apt update && apt install -y libolm-dev python3-pip ffmpeg;' +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone; \ + /bin/bash -c 'apt update && apt install -y libolm-dev python3-pip ffmpeg htop; \ + pip install update pip && pip install -r requirements.txt ;' -RUN pip install update pip && pip install -r requirements.txt - -CMD python3 fritzab2matrix.py && tail -f /dev/null +ENTRYPOINT ["./fritzab2matrix.py "] + diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 421eea3..820721d 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -7,8 +7,9 @@ services: context: ../. dockerfile: ./docker/Dockerfile working_dir: /app - volumes: - - ./:/app + entrypoint: ./fritzab2matrix.py +# volumes: +# - ./:/app diff --git a/fritzab2matrix.py b/fritzab2matrix.py old mode 100644 new mode 100755 index 0278d7f..d133d1f --- a/fritzab2matrix.py +++ b/fritzab2matrix.py @@ -1,3 +1,4 @@ +#! /usr/bin/python3 from fritzconnection import FritzConnection from dotenv import load_dotenv @@ -85,7 +86,7 @@ def main(): # ... and send message and file to Matrix Room command = "python3 matrix-commander.py -a " + os.path.join(env_tmp,"message.ogg") + " -m '{}'".format(msg_info) - # os.system(command) + os.system(command) else: # Mark MessageInfo as too short for the log @@ -108,14 +109,22 @@ def main(): continue continue + ### Monitor the FritzBox and trigger the main script whenever a call disconnects ### + ################################################################################### + endedCall(main, env_ip) -main() - -### Monitor the FritzBox and trigger the main script whenever a call disconnects ### -################################################################################### -endedCall(main, env_ip) +if __name__ == "__main__": + try: + print("I enter the main loop ...") + while main(): + pass + else: + print("I left the main loop!") + + except: + print("An erroneous error happened!")