Forked from
DM / dm-docs
261 commits behind, 732 commits ahead of the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
getExperimentCli.py 1.72 KiB
#!/usr/bin/env python
from dm.common.exceptions.invalidRequest import InvalidRequest
from dm.ds_web_service.api.experimentRestApi import ExperimentRestApi
from dsWebServiceSessionCli import DsWebServiceSessionCli
class GetExperimentCli(DsWebServiceSessionCli):
def __init__(self):
DsWebServiceSessionCli.__init__(self)
self.addOption('', '--id', dest='id', help='Experiment id. Either id or name must be provided. If both are provided, id takes precedence.')
self.addOption('', '--experiment', dest='experimentName', help='Experiment name. Either id or name must be provided. If both are provided, id takes precedence.')
def checkArgs(self):
if self.options.id is None and self.options.experimentName is None:
raise InvalidRequest('Either experiment id or name must be provided.')
def getId(self):
return self.options.id
def getExperimentName(self):
return self.options.experimentName
def runCommand(self):
self.parseArgs(usage="""
dm-get-experiment --id=ID|--experiment=EXPERIMENTNAME
Description:
Retrieves experiment information.
""")
self.checkArgs()
api = ExperimentRestApi(self.getLoginUsername(), self.getLoginPassword(), self.getServiceHost(), self.getServicePort(), self.getServiceProtocol())
if self.getId() is not None:
experiment = api.getExperimentById(self.getId())
else:
experiment = api.getExperimentByName(self.getExperimentName())
print experiment.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
#######################################################################
# Run command.
if __name__ == '__main__':
cli = GetExperimentCli()
cli.run()