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
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()
......
#!/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
......
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