Forked from
DM / dm-docs
261 commits behind, 808 commits ahead of the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
uploadTracker.py 2.16 KiB
#!/usr/bin/env python
import os
from dm.common.constants import dmProcessingStatus
from dm.common.objects.uploadInfo import UploadInfo
from dm.common.utility.objectTracker import ObjectTracker
from dm.common.exceptions.objectAlreadyExists import ObjectAlreadyExists
class UploadTracker(ObjectTracker):
# Cache configuration
objectClass = UploadInfo
cacheSize = 100
def __init__(self, *args, **kwargs):
ObjectTracker.__init__(self, args, kwargs)
self.activeUploadDict = {}
def checkForActiveUpload(self, experiment, dataDirectory):
experimentName = experiment.get('name')
dataDir = os.path.normpath(dataDirectory)
activeUploadKey = experimentName + dataDir
uploadId = self.activeUploadDict.get(activeUploadKey)
if uploadId:
uploadInfo = self.get(uploadId)
if uploadInfo is not None:
uploadInfo.updateStatus()
if uploadInfo.get('status') in dmProcessingStatus.DM_ACTIVE_PROCESSING_STATUS_LIST:
raise ObjectAlreadyExists('Upload id %s is already active for experiment %s in data directory %s.' % (uploadId, experimentName, dataDir))
del self.activeUploadDict[activeUploadKey]
def startUpload(self, uploadId, uploadInfo):
experimentName = uploadInfo.get('experimentName')
dataDirectory = uploadInfo.get('dataDirectory')
dataDir = os.path.normpath(dataDirectory)
activeUploadKey = experimentName + dataDir
self.activeUploadDict[activeUploadKey] = uploadId
self.put(uploadId, uploadInfo)
def getUploadInfo(self, id):
return self.get(id)
def getUploadInfos(self, status=None):
uploadInfoList = self.getAll()
filteredUploadInfoList = []
for uploadInfo in uploadInfoList:
uploadInfo.updateStatus()
if status is None or status == dmProcessingStatus.DM_PROCESSING_STATUS_ANY or uploadInfo.get('status', '') == status:
filteredUploadInfoList.append(uploadInfo)
return filteredUploadInfoList
####################################################################
# Testing
if __name__ == '__main__':
pass