本文整理汇总了Python中DIRAC.Core.Base.DB.DB._update方法的典型用法代码示例。如果您正苦于以下问题:Python DB._update方法的具体用法?Python DB._update怎么用?Python DB._update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.Core.Base.DB.DB
的用法示例。
在下文中一共展示了DB._update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update
# 需要导入模块: from DIRAC.Core.Base.DB import DB [as 别名]
# 或者: from DIRAC.Core.Base.DB.DB import _update [as 别名]
def _update( self, cmd, conn=False ):
start = time.time()
ret = DB._update( self, cmd, conn )
if DEBUG:
print >> debugFile, time.time() - start, cmd.replace('\n','')
debugFile.flush()
return ret
示例2: _update
# 需要导入模块: from DIRAC.Core.Base.DB import DB [as 别名]
# 或者: from DIRAC.Core.Base.DB.DB import _update [as 别名]
def _update( self, cmd, conn=False ):
""" Update MPIJob Database
"""
print "DB4"
start = Time.time()
ret = DB._update( self, cmd, conn )
if DEBUG:
print >> debugFile, Time.time() - start, cmd.replace('\n','')
debugFile.flush()
print ret
return ret
示例3: ResourceManagementDB
# 需要导入模块: from DIRAC.Core.Base.DB import DB [as 别名]
# 或者: from DIRAC.Core.Base.DB.DB import _update [as 别名]
#.........这里部分代码省略.........
:attr:`policyName`: string - the policy name
:attr:`status`: string - a ValidStatus:
see :mod:`DIRAC.ResourceStatusSystem.Utilities.Utils`
:attr:`reason`: string - free
:attr:`dateEffective`: datetime.datetime -
date from which the result is effective
"""
now = datetime.datetime.utcnow().replace(microsecond = 0).isoformat(' ')
if dateEffective is None:
dateEffective = now
req = "SELECT Granularity, Name, PolicyName, Status, Reason FROM PolicyRes "
req = req + "WHERE Granularity = '%s' AND Name = '%s' AND " %(granularity, name)
req = req + "PolicyName = '%s'" %(policyName)
resQuery = self.db._query(req)
if not resQuery['OK']:
raise RSSManagementDBException, where(self, self.addOrModifyPolicyRes) + resQuery['Message']
if resQuery['Value']:
req = "UPDATE PolicyRes SET "
if resQuery['Value'][0][3] != status:
req = req + "Status = '%s', Reason = '%s', DateEffective = '%s', " %(status, reason, dateEffective)
elif resQuery['Value'][0][4] != reason:
req = req + "Reason = '%s', " %(reason)
req = req + "LastCheckTime = '%s' WHERE Granularity = '%s' " %(now, granularity)
req = req + "AND Name = '%s' AND PolicyName = '%s'" %(name, policyName)
resUpdate = self.db._update(req)
if not resUpdate['OK']:
raise RSSManagementDBException, where(self, self.addOrModifyPolicyRes) + resUpdate['Message']
else:
req = "INSERT INTO PolicyRes (Granularity, Name, PolicyName, Status, Reason, DateEffective, "
req = req + "LastCheckTime) VALUES ('%s', '%s', '%s', " %(granularity, name, policyName)
req = req + "'%s', '%s', '%s', '%s')" %(status, reason, dateEffective, now)
resUpdate = self.db._update(req)
if not resUpdate['OK']:
raise RSSManagementDBException, where(self, self.addOrModifyPolicyRes) + resUpdate['Message']
#############################################################################
def getPolicyRes(self, name, policyName, lastCheckTime = False):
"""
Get a Policy Result from the PolicyRes table.
:params:
:attr:`name`: string - name of the ValidRes
:attr:`policyName`: string - the policy name
:attr:`lastCheckTime`: optional - if TRUE, it will get also the
LastCheckTime
"""
req = "SELECT Status, Reason"
if lastCheckTime:
req = req + ", LastCheckTime"
req = req + " FROM PolicyRes WHERE"
req = req + " Name = '%s' AND PolicyName = '%s'" %(name, policyName)
resQuery = self.db._query(req)
示例4: RSSConfigurationDB
# 需要导入模块: from DIRAC.Core.Base.DB import DB [as 别名]
# 或者: from DIRAC.Core.Base.DB.DB import _update [as 别名]
class RSSConfigurationDB(object):
def __init__(self, DBin = None, maxQueueSize = 10):
if DBin: self.db = DBin
else:
from DIRAC.Core.Base.DB import DB
self.db = DB('RSSConfigurationDB',
'ResourceStatus/RSSConfigurationDB', maxQueueSize)
def _delete(self, tableName, inFields, inValues):
# FIXME: Should go in DIRAC.Core.Utilities.MySQL
zipped = zip(inFields, inValues)
where_clause = ''
for i,(l,v) in enumerate(zipped):
if i == 0:
where_clause = where_clause + l + '="' + v + '" '
else:
where_clause = where_clause + 'AND ' + l + '="' + v + '" '
return self.db._update('DELETE FROM ' + tableName + ' WHERE ' + where_clause)
def _addValue(self, table, vdict):
keys, values = list_split(vdict.items())
return self.db._insert(table, keys, values)
def _delValue(self, table, vdict):
keys, values = list_split(vdict.items())
return self._delete(table, keys, values)
def _addValues(self, table, vdicts):
res = []
for d in vdicts:
res.append(self._addValue(table, d))
return res
def _delValues(self, table, vdicts):
res = []
for d in vdicts:
res.append(self._delValue(table, d))
return res
def _query(self, table):
"""
Returns values in a list instead of a tuple, i.e. retval[1] is a
list of tuples, one per line of result.
"""
retval = self.db._query("SELECT * from " + table)
return retval['OK'], list(retval['Value'])
# Helper functions.
def addUsers(self, unames):
"""Add users. The argument is a list of strings representing
usernames."""
unames = [{'login':u} for u in unames]
return self._addValues(t_users, unames)
def addUser(self, uname):
"""Add one user. The argument is a string representing the
username"""
return self.addUsers([uname])[0]
def delUsers(self, unames):
"""Delete users. The argument is a list of strings representing
usernames."""
unames = [{'login': u} for u in unames]
return self._delValues(t_users, unames)
def delUser(self, uname):
"""Delete a user. The argument is a string representing
username."""
return self.delUsers([uname])[0]
def getUsers(self):
"""Return users registered in database. Return S_OK() with Value:
a dict representing users with (for now) only a field 'login'.
TODO: This function is not supposed to fail in normal conditions,
and result incorrect if it fails. Fix this.
"""
ret, users = self._query(t_users)
users = [{'login': u} for u in users]
return {'OK':ret, 'Value':users}
def addStatuses(self, statuses):
"""Add statuses. Argument is a list of tuples (label, priority)"""
statuses = [{'label':l, 'priority':p} for (l,p) in statuses]
return self._addValues(t_statuses, statuses)
def addStatus(self, label, priority):
"""Add a status. The argument is respectively a string and an
integer, representing the name of the status and the priority"""
return self.addStatuses([(label, priority)])[0]
def delStatuses(self, statuses):
"""Delete statuses. Argument is a list of strings (labels)"""
statuses = [{'label':l} for l in statuses]
return self._delValues(t_statuses, statuses)
def delStatus(self, status):
return self.delStatuses([status])[0]
#.........这里部分代码省略.........