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 ...@@ -4,6 +4,6 @@ import abc
class FileProcessorInterface: class FileProcessorInterface:
@abc.abstractmethod @abc.abstractmethod
def processFile(self, srcPath): def processFile(self, filePath, daqPath, experiment):
return NotImplemented return NotImplemented
#!/usr/bin/env python #!/usr/bin/env python
import os
from dm.common.utility.loggingManager import LoggingManager from dm.common.utility.loggingManager import LoggingManager
from dm.common.utility.dmSubprocess import DmSubprocess from dm.common.utility.dmSubprocess import DmSubprocess
from dm.common.exceptions.invalidArgument import InvalidArgument from dm.common.exceptions.invalidArgument import InvalidArgument
...@@ -17,11 +18,17 @@ class FileTransferPlugin(FileProcessorInterface): ...@@ -17,11 +18,17 @@ class FileTransferPlugin(FileProcessorInterface):
self.command = command self.command = command
self.subprocess = None self.subprocess = None
def processFile(self, src): def processFile(self, filePath, daqPath, experiment):
self.start(src) 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): def getFullCommand(self, src, dest):
return '%s %s %s' % (self.command, self.src, self.dest) return '%s %s %s' % (self.command, src, dest)
def setSrc(self, src): def setSrc(self, src):
self.src = src self.src = src
...@@ -29,12 +36,20 @@ class FileTransferPlugin(FileProcessorInterface): ...@@ -29,12 +36,20 @@ class FileTransferPlugin(FileProcessorInterface):
def setDest(self, dest): def setDest(self, dest):
self.dest = dest self.dest = dest
def start(self, src=None): def start(self, src=None, dest=None):
if src is not None: # Use preconfigured source if provided source is None
self.src = src fileSrc = src
if not self.src or not self.dest: 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.') 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() return self.subprocess.run()
def wait(self): def wait(self):
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
from fileTransferPlugin import FileTransferPlugin from fileTransferPlugin import FileTransferPlugin
class RsyncFileTransferPlugin(FileTransferPlugin): class RsyncFileTransferPlugin(FileTransferPlugin):
COMMAND = 'rsync -arvlP' COMMAND = 'rsync -arvlPR'
def __init__(self, src=None, dest=None): def __init__(self, src=None, dest=None):
FileTransferPlugin.__init__(self, self.COMMAND, src, dest) 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