Skip to content
Snippets Groups Projects
Commit 1655dcbe authored by sveseli's avatar sveseli
Browse files

changed file processing interface; added support for relative file paths (with...

changed file processing interface; added support for relative file paths (with respect to daq directory)
parent 2952ab6d
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,6 @@ import abc
class FileProcessorInterface:
@abc.abstractmethod
def processFile(self, srcPath):
def processFile(self, filePath, daqPath, experiment):
return NotImplemented
#!/usr/bin/env python
import os
from dm.common.utility.loggingManager import LoggingManager
from dm.common.utility.dmSubprocess import DmSubprocess
from dm.common.exceptions.invalidArgument import InvalidArgument
......@@ -17,11 +18,17 @@ class FileTransferPlugin(FileProcessorInterface):
self.command = command
self.subprocess = None
def processFile(self, src):
self.start(src)
def processFile(self, filePath, daqPath, experiment):
storageHost = experiment.get('storageHost')
storageDirectory = experiment.get('storageDirectory')
dest = '%s:%s' % (storageHost, storageDirectory)
# Use relative path with respect to daq directory as a source
os.chdir(daqPath)
src = os.path.relpath(filePath, daqPath)
self.start(src, dest)
def getFullCommand(self):
return '%s %s %s' % (self.command, self.src, self.dest)
def getFullCommand(self, src, dest):
return '%s %s %s' % (self.command, src, dest)
def setSrc(self, src):
self.src = src
......@@ -29,12 +36,20 @@ class FileTransferPlugin(FileProcessorInterface):
def setDest(self, dest):
self.dest = dest
def start(self, src=None):
if src is not None:
self.src = src
if not self.src or not self.dest:
def start(self, src=None, dest=None):
# Use preconfigured source if provided source is None
fileSrc = src
if src is None:
fileSrc = self.src
# Use provided destination only if preconfigured destination is None
# Plugins may have desired destination preconfigured for all files
fileDest = self.dest
if self.dest is None:
fileDest = dest
if not fileSrc or not fileDest:
raise InvalidRequest('Both source and destination must be non-empty strings.')
self.subprocess = DmSubprocess.getSubprocess(self.getFullCommand())
self.subprocess = DmSubprocess.getSubprocess(self.getFullCommand(fileSrc, fileDest))
return self.subprocess.run()
def wait(self):
......
......@@ -3,7 +3,7 @@
from fileTransferPlugin import FileTransferPlugin
class RsyncFileTransferPlugin(FileTransferPlugin):
COMMAND = 'rsync -arvlP'
COMMAND = 'rsync -arvlPR'
def __init__(self, src=None, dest=None):
FileTransferPlugin.__init__(self, self.COMMAND, src, dest)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment