From 9d2c69849376acd20dfb0f1b0c652b6aa726c32d Mon Sep 17 00:00:00 2001 From: Manuela Kuhn <manuela.kuhn@desy.de> Date: Tue, 14 Jul 2015 16:17:43 +0200 Subject: [PATCH] Added wrapper-script --- lsyncd.conf | 41 +++++++++++++++++++++++++++++++---------- wrapper_script.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 wrapper_script.py diff --git a/lsyncd.conf b/lsyncd.conf index 65433a0d..a1c636dd 100644 --- a/lsyncd.conf +++ b/lsyncd.conf @@ -11,8 +11,9 @@ -- configuration parameters -- settings { - statusFile = "/var/log/lsyncd.stat", + statusFile = "/space/projects/Live_Viewer/lsyncd.stat", statusInterval = 1, + nodaemon = true } local formats = { jpg = true, tif = true, cbf = true, log = true } @@ -44,12 +45,22 @@ gpfs = { local extension = string.match(event.name, ".*%.([^.]+)$") if formats[extension] ~= true then return end - spawn( + spawn ( event, - '/bin/mv', + '/usr/bin/python', + '/space/projects/Live_Viewer/wrapper_script.py', + '--mv_source', event.sourcePath, + '--mv_target', event.targetPathdir ) + +-- spawn( +-- event, +-- '/bin/mv', +-- event.sourcePath, +-- event.targetPathdir +-- ) end end, @@ -71,12 +82,22 @@ gpfs = { local extension = string.match(event.name, ".*%.([^.]+)$") if formats[extension] ~= true then return end - spawn( + spawn ( event, - '/bin/mv', + '/usr/bin/python', + '/space/projects/Live_Viewer/wrapper_script.py', + '--mv_source', event.sourcePath, + '--mv_target', event.targetPathdir ) + +-- spawn( +-- event, +-- '/bin/mv', +-- event.sourcePath, +-- event.targetPathdir +-- ) end end, @@ -89,8 +110,8 @@ gpfs = { if not agent.isList and agent.etype == "Blanket" then if exitcode == 0 then log("Normal", "Startup of '",agent.source,"' finished.") - elseif config.exitcodes and - config.exitcodes[exitcode] == "again" + elseif config.exitcodes and + config.exitcodes[exitcode] == "again" then log("Normal", "Retrying startup of '",agent.source,"'.") return "again" @@ -100,7 +121,7 @@ gpfs = { return end - local rc = config.exitcodes and config.exitcodes[exitcode] + local rc = config.exitcodes and config.exitcodes[exitcode] if rc == "die" then return rc end @@ -126,6 +147,6 @@ sync { gpfs, delay=0, init=false, - source="/rd", - target="/gpfs", + source="/space/projects/Live_Viewer/source", + target="/space/projects/Live_Viewer/target", } diff --git a/wrapper_script.py b/wrapper_script.py new file mode 100644 index 00000000..40859e7e --- /dev/null +++ b/wrapper_script.py @@ -0,0 +1,38 @@ +import argparse +import subprocess +import os + + +parser = argparse.ArgumentParser() +parser.add_argument("--mv_source", help = "Move source") +parser.add_argument("--mv_target", help = "Move target") + +arguments = parser.parse_args() + +source = arguments.mv_source +target = arguments.mv_target + +watchFolder = "/space/projects/Live_Viewer/source/" + +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 ], + stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, + universal_newlines = False ) +out, err = p.communicate() + -- GitLab