本文整理汇总了Python中id_scope.IdScope.getNewId方法的典型用法代码示例。如果您正苦于以下问题:Python IdScope.getNewId方法的具体用法?Python IdScope.getNewId怎么用?Python IdScope.getNewId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类id_scope.IdScope
的用法示例。
在下文中一共展示了IdScope.getNewId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DBVistrail
# 需要导入模块: from id_scope import IdScope [as 别名]
# 或者: from id_scope.IdScope import getNewId [as 别名]
#.........这里部分代码省略.........
for annotation in self.db_actionAnnotations:
self.idScope.updateBeginId('annotation', annotation.db_id+1)
for paramexp in self.db_parameter_explorations:
self.idScope.updateBeginId('parameter_exploration',
paramexp.db_id+1)
def db_add_object(self, obj):
self.db_objects[(obj.vtType, obj.db_id)] = obj
def db_get_object(self, type, id):
return self.db_objects.get((type, id), None)
def db_update_object(self, obj, **kwargs):
# want to swap out old object with a new version
# need this for updating aliases...
# hack it using setattr...
real_obj = self.db_objects[(obj.vtType, obj.db_id)]
for (k, v) in kwargs.iteritems():
if hasattr(real_obj, k):
setattr(real_obj, k, v)
def update_checkout_version(self, app=''):
checkout_key = "__checkout_version_"
action_key = checkout_key + app
annotation_key = action_key + '_annotationhash'
action_annotation_key = action_key + '_actionannotationhash'
# delete previous checkout annotations
deletekeys = [action_key,annotation_key,action_annotation_key]
for key in deletekeys:
while self.db_has_annotation_with_key(key):
a = self.db_get_annotation_by_key(key)
self.db_delete_annotation(a)
# annotation hash - requires annotations to be clean
value = self.hashAnnotations()
if self.db_has_annotation_with_key(annotation_key):
annotation = self.db_get_annotation_by_key(annotation_key)
annotation.db_value = value
else:
annotation=DBAnnotation(self.idScope.getNewId(DBAnnotation.vtType),
annotation_key, value)
self.db_add_annotation(annotation)
# action annotation hash
value = self.hashActionAnnotations()
if self.db_has_annotation_with_key(action_annotation_key):
annotation = self.db_get_annotation_by_key(action_annotation_key)
annotation.db_value = value
else:
annotation=DBAnnotation(self.idScope.getNewId(DBAnnotation.vtType),
action_annotation_key, value)
self.db_add_annotation(annotation)
# last action id hash
if len(self.db_actions) == 0:
value = 0
else:
value = max(v.db_id for v in self.db_actions)
if self.db_has_annotation_with_key(action_key):
annotation = self.db_get_annotation_by_key(action_key)
annotation.db_value = str(value)
else:
annotation=DBAnnotation(self.idScope.getNewId(DBAnnotation.vtType),
action_key, str(value))
self.db_add_annotation(annotation)
def hashAnnotations(self):
annotations = {}
for annotation in self.db_annotations:
if annotation._db_key not in annotations:
annotations[annotation._db_key] = []
if annotation._db_value not in annotations[annotation._db_key]:
annotations[annotation._db_key].append(annotation._db_value)
keys = annotations.keys()
keys.sort()
m = hashlib.md5()
for k in keys:
m.update(str(k))
annotations[k].sort()
for v in annotations[k]:
m.update(str(v))
return m.hexdigest()
def hashActionAnnotations(self):
action_annotations = {}
for action_id, key, value in [[aa.db_action_id, aa.db_key,
aa.db_value] for aa in self.db_actionAnnotations]:
index = (str(action_id), key)
if index not in action_annotations:
action_annotations[index] = []
if value not in action_annotations[index]:
action_annotations[index].append(value)
keys = action_annotations.keys()
keys.sort()
m = hashlib.md5()
for k in keys:
m.update(k[0] + k[1])
action_annotations[k].sort()
for v in action_annotations[k]:
m.update(str(v))
return m.hexdigest()