From 45e0693933ba0afc37171fea5e99e0d8366fca85 Mon Sep 17 00:00:00 2001 From: Sinisa Veseli <sveseli@aps.anl.gov> Date: Thu, 3 Dec 2015 14:25:11 +0000 Subject: [PATCH] support for DM_FILE_SERVER_URL variable --- .../cli/daqWebServiceSessionCli.py | 16 ++++++++++++++++ src/python/dm/daq_web_service/cli/startDaqCli.py | 10 ++-------- src/python/dm/daq_web_service/cli/stopDaqCli.py | 8 +------- src/python/dm/daq_web_service/cli/uploadCli.py | 8 +------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/python/dm/daq_web_service/cli/daqWebServiceSessionCli.py b/src/python/dm/daq_web_service/cli/daqWebServiceSessionCli.py index c7f02f28..e2e74172 100755 --- a/src/python/dm/daq_web_service/cli/daqWebServiceSessionCli.py +++ b/src/python/dm/daq_web_service/cli/daqWebServiceSessionCli.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +import os from dm.common.cli.dmRestSessionCli import DmRestSessionCli from dm.common.utility.osUtility import OsUtility from dm.common.utility.configurationManager import ConfigurationManager @@ -7,6 +8,7 @@ from dm.common.utility.configurationManager import ConfigurationManager class DaqWebServiceSessionCli(DmRestSessionCli): """ DM DAQ web service session cli class. """ + DM_FILE_SERVER_URL_ENV_VAR = 'DM_FILE_SERVER_URL' DEFAULT_SESSION_CACHE_FILE = OsUtility.getUserHomeDir() + '/.dm/.daq.session.cache' def __init__(self, validArgCount=0): @@ -19,3 +21,17 @@ class DaqWebServiceSessionCli(DmRestSessionCli): def getDefaultServicePort(self): return ConfigurationManager.getInstance().getDaqWebServicePort() + def getId(self): + return self.options.id + + def getExperimentName(self): + return self.options.experimentName + + def getDataDirectory(self): + dataDirectory = self.options.dataDirectory + # Make sure data directory already does not have url scheme + if dataDirectory and dataDirectory.find('://') < 0: + fileServerUrl = os.environ.get(self.DM_FILE_SERVER_URL_ENV_VAR, '') + dataDirectory = '%s%s' % (fileServerUrl, dataDirectory) + return dataDirectory + diff --git a/src/python/dm/daq_web_service/cli/startDaqCli.py b/src/python/dm/daq_web_service/cli/startDaqCli.py index aac21b57..ea7cf18d 100755 --- a/src/python/dm/daq_web_service/cli/startDaqCli.py +++ b/src/python/dm/daq_web_service/cli/startDaqCli.py @@ -8,7 +8,7 @@ class StartDaqCli(DaqWebServiceSessionCli): def __init__(self): DaqWebServiceSessionCli.__init__(self, validArgCount=self.ANY_NUMBER_OF_POSITIONAL_ARGS) self.addOption('', '--experiment', dest='experimentName', help='Experiment name.') - self.addOption('', '--data-directory', dest='dataDirectory', help='Experiment data directory.') + self.addOption('', '--data-directory', dest='dataDirectory', help='Experiment data directory. If specified string does not already contain file server URL, value of the %s environment variable will be prepended to it.' % self.DM_FILE_SERVER_URL_ENV_VAR) def checkArgs(self): if self.options.experimentName is None: @@ -16,12 +16,6 @@ class StartDaqCli(DaqWebServiceSessionCli): if self.options.dataDirectory is None: raise InvalidRequest('Experiment data directory must be provided.') - def getExperimentName(self): - return self.options.experimentName - - def getDataDirectory(self): - return self.options.dataDirectory - def runCommand(self): self.parseArgs(usage=""" dm-start-daq --experiment=EXPERIMENTNAME --data-directory=DATADIRECTORY @@ -30,7 +24,7 @@ class StartDaqCli(DaqWebServiceSessionCli): Description: Starts DAQ for a given experiment. Specified data directory will be monitored for data files. All provided key/value pairs will be passed to - file processing plugins. + file processing plugins. """) self.checkArgs() api = ExperimentRestApi(self.getLoginUsername(), self.getLoginPassword(), self.getServiceHost(), self.getServicePort(), self.getServiceProtocol()) diff --git a/src/python/dm/daq_web_service/cli/stopDaqCli.py b/src/python/dm/daq_web_service/cli/stopDaqCli.py index 6310a316..98bf9d72 100755 --- a/src/python/dm/daq_web_service/cli/stopDaqCli.py +++ b/src/python/dm/daq_web_service/cli/stopDaqCli.py @@ -8,7 +8,7 @@ class StopDaqCli(DaqWebServiceSessionCli): def __init__(self): DaqWebServiceSessionCli.__init__(self) self.addOption('', '--experiment', dest='experimentName', help='Experiment name.') - self.addOption('', '--data-directory', dest='dataDirectory', help='Experiment data directory.') + self.addOption('', '--data-directory', dest='dataDirectory', help='Experiment data directory. If specified string does not already contain file server URL, value of the %s environment variable will be prepended to it.' % self.DM_FILE_SERVER_URL_ENV_VAR) def checkArgs(self): if self.options.experimentName is None: @@ -16,12 +16,6 @@ class StopDaqCli(DaqWebServiceSessionCli): if self.options.dataDirectory is None: raise InvalidRequest('Experiment data directory must be provided.') - def getExperimentName(self): - return self.options.experimentName - - def getDataDirectory(self): - return self.options.dataDirectory - def runCommand(self): self.parseArgs(usage=""" dm-stop-daq --experiment=EXPERIMENTNAME --data-directory=DATADIRECTORY diff --git a/src/python/dm/daq_web_service/cli/uploadCli.py b/src/python/dm/daq_web_service/cli/uploadCli.py index 0b62bb03..80f5c3ca 100755 --- a/src/python/dm/daq_web_service/cli/uploadCli.py +++ b/src/python/dm/daq_web_service/cli/uploadCli.py @@ -8,7 +8,7 @@ class UploadCli(DaqWebServiceSessionCli): def __init__(self): DaqWebServiceSessionCli.__init__(self, validArgCount=self.ANY_NUMBER_OF_POSITIONAL_ARGS) self.addOption('', '--experiment', dest='experimentName', help='Experiment name.') - self.addOption('', '--data-directory', dest='dataDirectory', help='Experiment data directory.') + self.addOption('', '--data-directory', dest='dataDirectory', help='Experiment data directory. If specified string does not already contain file server URL, value of the %s environment variable will be prepended to it.' % self.DM_FILE_SERVER_URL_ENV_VAR) def checkArgs(self): if self.options.experimentName is None: @@ -16,12 +16,6 @@ class UploadCli(DaqWebServiceSessionCli): if self.options.dataDirectory is None: raise InvalidRequest('Experiment data directory must be provided.') - def getExperimentName(self): - return self.options.experimentName - - def getDataDirectory(self): - return self.options.dataDirectory - def runCommand(self): self.parseArgs(usage=""" dm-upload --experiment=EXPERIMENTNAME --data-directory=DATADIRECTORY -- GitLab