From cb1aea666cf8d971e050b568cbf6f5a7ba9dfbe3 Mon Sep 17 00:00:00 2001 From: Manuela Kuhn <manuela.kuhn@desy.de> Date: Wed, 15 Jul 2015 15:23:15 +0200 Subject: [PATCH] Only files with a specific extention are send to the ring buffer --- wrapper_script.py | 63 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/wrapper_script.py b/wrapper_script.py index 40859e7e..97d1536c 100644 --- a/wrapper_script.py +++ b/wrapper_script.py @@ -1,6 +1,11 @@ import argparse import subprocess import os +import time + + +supportedFormats = [ "tif", "cbf", "hdf5"] +watchFolder = "/space/projects/Live_Viewer/source/" parser = argparse.ArgumentParser() @@ -9,29 +14,51 @@ parser.add_argument("--mv_target", help = "Move target") arguments = parser.parse_args() -source = arguments.mv_source -target = arguments.mv_target +source = os.path.normpath ( arguments.mv_source ) +target = os.path.normpath ( arguments.mv_target ) -watchFolder = "/space/projects/Live_Viewer/source/" +( parentDir, filename ) = os.path.split ( source ) +commonPrefix = os.path.commonprefix ( [ watchFolder, source ] ) +relativebasepath = os.path.relpath ( source, commonPrefix ) +( relativeParent, blub ) = os.path.split ( relativebasepath ) + +( name, postfix ) = filename.split( "." ) +supported_file = postfix in supportedFormats + +if supported_File: + my_cmd = 'echo "' + source + '" > /tmp/zeromqllpipe' + p = subprocess.Popen ( my_cmd, shell=True ) + p.communicate() + + # wait to ZeroMQ to finish + time.sleep(5) + +# get responce from zeromq +#pipe_path = "/tmp/zeromqllpipe_resp" + +# Open the fifo. We need to open in non-blocking mode or it will stalls until +# someone opens it for writting +#pipe_fd = os.open(pipe_path, os.O_RDONLY | os.O_NONBLOCK) + +#waitForAnswer = True + +#wait for new files +#with os.fdopen(pipe_fd) as pipe: +# while waitForAnswer: +# message = pipe.read() +# if message: +# pathnames = message.splitlines() +# for filepath in pathnames: +# if filepath == source: +# waitForAnswer = False +# break +# print "sleep" +# time.sleep(0.1) -filepathNormalised = os.path.normpath ( source ) -( parentDir, filename ) = os.path.split ( filepathNormalised ) -commonPrefix = os.path.commonprefix ( [ watchFolder, filepathNormalised ] ) -#print "commonPrefix", commonPrefix -relativeBasepath = os.path.relpath ( filepathNormalised, commonPrefix ) -#print "relativeBasepath", relativeBasepath -( relativeParent, blub ) = os.path.split ( relativeBasepath ) -print "filename ", filename -print "parentDir ", parentDir -print "relativeParent", relativeParent -my_cmd = 'echo "' + arguments.mv_source + '" > /tmp/zeromqllpipe' -print my_cmd -p = subprocess.Popen ( my_cmd, shell=True ) -p.communicate() -p = subprocess.Popen ( [ 'mv', arguments.mv_source, arguments.mv_target ], +p = subprocess.Popen ( [ 'mv', source, target ], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, universal_newlines = False ) out, err = p.communicate() -- GitLab