From 897985a3cfa71efba832f7d19139d5b56271c87a Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 5 Jul 2023 21:16:35 +0200 Subject: [PATCH] copy images to tmp dir and signal --- msv_webcam_backend.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/msv_webcam_backend.py b/msv_webcam_backend.py index e70cedb..3c92f0d 100644 --- a/msv_webcam_backend.py +++ b/msv_webcam_backend.py @@ -9,13 +9,24 @@ import time import shutil import sys +signal_pipe_path = "/tmp/msv-webcam-signal-pipe" +signal_pipe_msg = "msv-webcam-new-images" + def copy_image(src, destination_dir_path, destination_owner): # print("src: " + str(src)) # print("dst: " + str(destination_dir_path)) + os.makedirs(os.path.dirname(destination_dir_path), exist_ok=True) shutil.copyfile(src, destination_dir_path) os.chmod(destination_dir_path, 0o0644) shutil.chown(destination_dir_path, destination_owner) +def signal_new_images(): + if not os.path.exists(signal_pipe_path): + os.mkfifo(signal_pipe_path) + with open(signal_pipe_path, "w") as f: + f.write(signal_pipe_msg) + f.close() + def main(): print("starting ...") @@ -42,10 +53,11 @@ def main(): if ((update_interval == -1) or (destination_dir_path == -1) or (destination_owner == -1) or (len(search_dirs) == 0)): print("Unable to parse config!") print("Example usage:") - print(" python msv_webcam_backend.py interval=10 search_dir=test_images/msvcamS search_dir=test_images/msvcamN destination_dir=www/ destination_owner=hendrik") + print(" python msv_webcam_backend.py interval=10 search_dir=test_images/msvcamS search_dir=test_images/msvcamN destination_dir=/tmp/msv_webcam_current destination_owner=hendrik") sys.exit(-1) while True: + new_images_found = False for search_dir in search_dirs: try: # print("\nSearch dir: " + str(search_dir["search_dir_path"])) @@ -74,12 +86,15 @@ def main(): print("Size: " + str(search_dir["newest_file_size"])) dst_file_tmp = os.path.join(destination_dir_path, (os.path.basename(os.path.normpath(search_dir["search_dir_path"])) + os.path.splitext(search_dir["newest_file_path"])[1])) copy_image(search_dir["newest_file_path"], dst_file_tmp, destination_owner) + new_images_found = True #break else: print("Upload not finished yet!") except Exception as e: print(e) #break + if(new_images_found == True): + signal_new_images() time.sleep(update_interval) if __name__ == "__main__":