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

add few object classes

parent c2ea1622
No related branches found
No related tags found
No related merge requests found
#!/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)
...@@ -13,6 +13,7 @@ import json ...@@ -13,6 +13,7 @@ import json
import datetime import datetime
from dm.common.exceptions.invalidArgument import InvalidArgument from dm.common.exceptions.invalidArgument import InvalidArgument
from dm.common.exceptions.objectNotFound import ObjectNotFound
from dm.common.utility import loggingManager from dm.common.utility import loggingManager
class DmObject(UserDict.UserDict): class DmObject(UserDict.UserDict):
...@@ -40,6 +41,12 @@ class DmObject(UserDict.UserDict): ...@@ -40,6 +41,12 @@ class DmObject(UserDict.UserDict):
self.logger = loggingManager.getLogger(self._class__.__name__) self.logger = loggingManager.getLogger(self._class__.__name__)
return self.logger 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 @classmethod
def getFromDict(cls, dict): def getFromDict(cls, dict):
inst = cls() inst = cls()
......
#!/usr/bin/env python #!/usr/bin/env python
import time import time
import os
from dmObject import DmObject from dmObject import DmObject
class ObservedFile(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) DmObject.__init__(self, dict)
if filePath: if filePath:
self['filePath'] = filePath self['filePath'] = filePath
if daqPath: if dataDirectory:
self['daqPath'] = daqPath self['dataDirectory'] = dataDirectory
if filePath:
self['experimentFilePath'] = os.path.relpath(filePath, dataDirectory)
if experiment: if experiment:
self['experiment'] = experiment self['experiment'] = experiment
...@@ -25,8 +28,8 @@ class ObservedFile(DmObject): ...@@ -25,8 +28,8 @@ class ObservedFile(DmObject):
def getFilePath(self): def getFilePath(self):
return self.get('filePath') return self.get('filePath')
def getDaqPath(self): def getDataDirectory(self):
return self.get('daqPath') return self.get('dataDirectory')
def getExperiment(self): def getExperiment(self):
return self.get('experiment') return self.get('experiment')
...@@ -34,7 +37,7 @@ class ObservedFile(DmObject): ...@@ -34,7 +37,7 @@ class ObservedFile(DmObject):
#################################################################### ####################################################################
# Testing # Testing
if __name__ == '__main__': if __name__ == '__main__':
of = ObservedFile(path='tmp/xyz') of = ObservedFile(filePath='tmp/xyz')
print of print of
of.setLastUpdatedTimestampToNow() of.setLastUpdatedTimestampToNow()
print of print of
......
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