本文整理汇总了Python中DIRAC.Resources.Catalog.FileCatalogClient.FileCatalogClient.addDataset方法的典型用法代码示例。如果您正苦于以下问题:Python FileCatalogClient.addDataset方法的具体用法?Python FileCatalogClient.addDataset怎么用?Python FileCatalogClient.addDataset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.Resources.Catalog.FileCatalogClient.FileCatalogClient
的用法示例。
在下文中一共展示了FileCatalogClient.addDataset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient [as 别名]
# 或者: from DIRAC.Resources.Catalog.FileCatalogClient.FileCatalogClient import addDataset [as 别名]
class DfcOperation:
'''Class for DFC operation'''
_username = ''
_groupname = ''
_rootdir = ''
def __init__(self):
_fcType = 'DataManagement/FileCatalog'
self.client = FileCatalogClient(_fcType)
def getUserName(self):
'''get username'''
if not DfcOperation._username:
DfcOperation._username = getProxyInfo()['Value'].get('username', 'unknown')
return DfcOperation._username
def getGroupName(self):
'''get groupname'''
if not DfcOperation._groupname:
DfcOperation._groupname = getProxyInfo()['Value'].get('group', 'unknown')
return DfcOperation._groupname
def setRootDir(self, rootDir):
DfcOperation._rootdir = rootDir
def getRootDir(self):
if not DfcOperation._rootdir:
if self.getGroupName() == 'production':
DfcOperation._rootdir = self.getOfficialRootDir()
DfcOperation._rootdir = self.getUserRootDir()
return DfcOperation._rootdir
def getOfficialRootDir(self):
return '/bes'
def getUserRootDir(self):
'''get user's initial root directory'''
username = self.getUserName()
initial = username[:1]
vo = getVO()
if not vo:
vo = 'bes'
ops = Operations(vo = vo)
user_prefix = ops.getValue('LFNUserPrefix', 'user')
basePath = '/' + vo + '/' + user_prefix + '/' + initial + '/' + username
return basePath
def isDirExists(self,dir):
'''check whether dir on DFC exists'''
result = self.client.listDirectory(dir)
if result['OK'] and result['Value']['Successful']:
return True
return False
def validateDir(self, dir):
'''if the dir on DFC does not exist, create it'''
if not self.isDirExists(dir):
logger.debug('Creating dir: %s', dir)
return self.client.createDirectory(dir)
def _getDatasetPrefix(self):
if self.getGroupName() == 'production':
return 'Prod'
return 'User_' + self.getUserName()
def createDataset(self, metadata):
metaDic = {}
metaDic['resonance'] = metadata.get('resonance', 'unknown')
metaDic['bossVer'] = metadata.get('bossVer', 'xxx')
metaDic['eventType'] = metadata.get('eventType', 'unknown')
metaDic['round'] = metadata.get('round', 'roundxx')
metaDic['streamId'] = metadata.get('streamId', 'streamxxx')
metaDic['dataType'] = metadata.get('dataType', 'unknown')
metaDic['Path'] = self.getRootDir() + ('/Log' if metadata.get('dataType', 'unknown').lower() == 'log' else '/File')
runFrom = metadata.get('runFrom', 0)
runTo = metadata.get('runTo', 0)
metaDic['runL'] = {'>=': runFrom}
metaDic['runH'] = {'<=': runTo}
datasetName = '%s_%s_%s_%s_%s_%s_%s_%s_%s' % (self._getDatasetPrefix(),
metaDic['resonance'], metaDic['bossVer'], metaDic['eventType'], metaDic['round'],
runFrom, runTo, metaDic['streamId'], metaDic['dataType'])
result = self.client.addDataset({'/dataset/'+datasetName: metaDic})
if not result['OK']:
logger.warning("Can not create dataset: %s", result['Message'])
return datasetName
def getDirName(self, metadata):
return self._getDirNames(metadata)[6]
def _getDirNames(self, metadata):
rootDir = self.getRootDir()
dir_start = rootDir + ('/Log' if metadata.get('dataType', 'unknown').lower() == 'log' else '/File')
dir_resonance = dir_start + '/' + metadata.get('resonance', 'unknown')
#.........这里部分代码省略.........