diff --git a/src/python/dm/common/objects/daqInfo.py b/src/python/dm/common/objects/daqInfo.py new file mode 100755 index 0000000000000000000000000000000000000000..e28bc5e9ab395179cdc98a47f34d309104ede132 --- /dev/null +++ b/src/python/dm/common/objects/daqInfo.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +from dmObject import DmObject + +class DaqInfo(DmObject): + + DEFAULT_KEY_LIST = [ 'id', 'experimentName', 'dataDirectory' ] + + def __init__(self, dict): + DmObject.__init__(self, dict) + diff --git a/src/python/dm/common/objects/dmObject.py b/src/python/dm/common/objects/dmObject.py index 5c85b8ea387edc9894edbaf60a25af5d269f5985..843be2d01fb95332d22722f2b2c0c5ec30088bce 100755 --- a/src/python/dm/common/objects/dmObject.py +++ b/src/python/dm/common/objects/dmObject.py @@ -13,6 +13,7 @@ import json import datetime from dm.common.exceptions.invalidArgument import InvalidArgument +from dm.common.exceptions.objectNotFound import ObjectNotFound from dm.common.utility import loggingManager class DmObject(UserDict.UserDict): @@ -40,6 +41,12 @@ class DmObject(UserDict.UserDict): self.logger = loggingManager.getLogger(self._class__.__name__) return self.logger + def getRequiredKeyValue(self, key): + value = self.get(key) + if value is None: + errorMsg = 'Required dictionary key %s is missing.' % key + raise ObjectNotFound(errorMsg) + @classmethod def getFromDict(cls, dict): inst = cls() diff --git a/src/python/dm/common/objects/observedFile.py b/src/python/dm/common/objects/observedFile.py index 8ef9ac2bef320732693761efd6364ddccc8ec2f1..a183351ccf873d5d81f1d99b5d9897c2d6f3611f 100755 --- a/src/python/dm/common/objects/observedFile.py +++ b/src/python/dm/common/objects/observedFile.py @@ -1,18 +1,21 @@ #!/usr/bin/env python import time +import os from dmObject import DmObject class ObservedFile(DmObject): - DEFAULT_KEY_LIST = [ 'path', 'lastUpdatedTimestamp' ] + DEFAULT_KEY_LIST = [ 'filePath', 'lastUpdatedTimestamp' ] - def __init__(self, dict={}, filePath=None, daqPath=None, experiment=None): + def __init__(self, dict={}, filePath=None, dataDirectory=None, experiment=None): DmObject.__init__(self, dict) if filePath: self['filePath'] = filePath - if daqPath: - self['daqPath'] = daqPath + if dataDirectory: + self['dataDirectory'] = dataDirectory + if filePath: + self['experimentFilePath'] = os.path.relpath(filePath, dataDirectory) if experiment: self['experiment'] = experiment @@ -25,8 +28,8 @@ class ObservedFile(DmObject): def getFilePath(self): return self.get('filePath') - def getDaqPath(self): - return self.get('daqPath') + def getDataDirectory(self): + return self.get('dataDirectory') def getExperiment(self): return self.get('experiment') @@ -34,7 +37,7 @@ class ObservedFile(DmObject): #################################################################### # Testing if __name__ == '__main__': - of = ObservedFile(path='tmp/xyz') + of = ObservedFile(filePath='tmp/xyz') print of of.setLastUpdatedTimestampToNow() print of