本文整理汇总了Python中framework.guid.model.Guid.find方法的典型用法代码示例。如果您正苦于以下问题:Python Guid.find方法的具体用法?Python Guid.find怎么用?Python Guid.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类framework.guid.model.Guid
的用法示例。
在下文中一共展示了Guid.find方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: restore
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def restore(self, recursive=True, parent=None):
"""Recreate a StoredFileNode from the data in this object
Will re-point all guids and finally remove itself
:raises KeyExistsException:
"""
data = self.to_storage()
data.pop('deleted_on')
data.pop('deleted_by')
data.pop('suspended')
if parent:
data['parent'] = parent._id
elif data['parent']:
# parent is an AbstractForeignField, so it gets stored as tuple
data['parent'] = data['parent'][0]
restored = FileNode.resolve_class(self.provider, int(self.is_file))(**data)
if not restored.parent:
raise ValueError('No parent to restore to')
restored.save()
# repoint guid
for guid in Guid.find(Q('referent', 'eq', self)):
guid.referent = restored
guid.save()
if recursive:
for child in TrashedFileNode.find(Q('parent', 'eq', self)):
child.restore(recursive=recursive, parent=restored)
TrashedFileNode.remove_one(self)
return restored
示例2: get_file_guids
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def get_file_guids(cls, materialized_path, provider, node=None):
guids = []
path = materialized_path.strip('/')
file_obj = cls.load(path)
if not file_obj:
file_obj = TrashedFileNode.load(path)
# At this point, file_obj may be an OsfStorageFile, an OsfStorageFolder, or a
# TrashedFileNode. TrashedFileNodes do not have *File and *Folder subclasses, since
# only osfstorage trashes folders. To search for children of TrashFileNodes
# representing ex-OsfStorageFolders, we will reimplement the `children` method of the
# Folder class here.
if not file_obj.is_file:
children = []
if isinstance(file_obj, TrashedFileNode):
children = TrashedFileNode.find(Q('parent', 'eq', file_obj._id))
else:
children = file_obj.children
for item in children:
guids.extend(cls.get_file_guids(item.path, provider, node=node))
else:
try:
guid = Guid.find(Q('referent', 'eq', file_obj))[0]
except IndexError:
guid = None
if guid:
guids.append(guid._id)
return guids
示例3: main
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def main():
modm_guids = MODMGuid.find()
print 'MODM Guids: {}'.format(len(modm_guids))
guids = Guid.objects.filter(guid__in=modm_guids.get_keys())
filtered_count = len(guids)
total_count = Guid.objects.count()
if len(modm_guids) == filtered_count == total_count:
print 'Guids verified!'
else:
print 'Guids not verified!'
print 'Postgres Guids: {}'.format(Guid.objects.count())
guids = modm_guids = filtered_count = total_count = None
gc.collect()
modm_blacklist_guids = MODMBlacklistGuid.find()
print 'MODM BlacklistGuids: {}'.format(len(modm_blacklist_guids))
blacklist_guids = BlackListGuid.objects.filter(guid__in=modm_blacklist_guids.get_keys())
filtered_count = len(blacklist_guids)
total_count = BlackListGuid.objects.count()
if len(modm_blacklist_guids) == filtered_count == total_count:
print 'Blacklist Guids Verified!'
else:
print 'Blacklist Guids Not Verified!'
print 'Postgres Blacklist Guids: {}'.format(BlackListGuid.objects.count())
blacklist_guids = modm_blacklist_guids = filtered_count = total_count = None
gc.collect()
示例4: get_guid
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def get_guid(self):
"""Attempt to find a Guid that points to this object.
:rtype: Guid or None
"""
try:
# Note sometimes multiple GUIDs can exist for
# a single object. Just go with the first one
return Guid.find(Q('referent', 'eq', self))[0]
except IndexError:
return None
示例5: get_guid
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def get_guid(self, create=False):
"""Attempt to find a Guid that points to this object.
One will be created if requested.
:rtype: Guid
"""
try:
# Note sometimes multiple GUIDs can exist for
# a single object. Just go with the first one
return Guid.find(Q('referent', 'eq', self))[0]
except IndexError:
if not create:
return None
return Guid.generate(self)
示例6: get_guid
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def get_guid(self, create=False):
"""Attempt to find a Guid that points to this object.
One will be created if requested.
:param Boolean create: Should we generate a GUID if there isn't one? Default: False
:rtype: Guid or None
"""
try:
# Note sometimes multiple GUIDs can exist for
# a single object. Just go with the first one
return Guid.find(Q("referent", "eq", self))[0]
except IndexError:
if not create:
return None
return Guid.generate(self)
示例7: get_targets
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def get_targets():
"""Find GUIDs with no referents and GUIDs with referents that no longer exist."""
# Use a loop because querying MODM with Guid.find(Q('referent', 'eq', None))
# only catches the first case.
ret = []
# NodeFiles were once a GuidStored object and are no longer used any more.
# However, they still exist in the production database. We just skip over them
# for now, but they can probably need to be removed in the future.
# There were also 10 osfguidfile objects that lived in a corrupt repo that
# were not migrated to OSF storage, so we skip those as well. /sloria /jmcarp
for each in Guid.find(Q('referent.1', 'nin', ['nodefile', 'osfguidfile'])):
if each.referent is None:
logger.info('GUID {} has no referent.'.format(each._id))
ret.append(each)
return ret
示例8: get_file_guids
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def get_file_guids(cls, materialized_path, provider, node=None, guids=None):
guids = guids or []
path = materialized_path.strip('/')
file_obj = cls.load(path)
if not file_obj:
file_obj = TrashedFileNode.load(path)
if not file_obj.is_file:
for item in file_obj.children:
cls.get_file_guids(item.path, provider, node=node, guids=guids)
else:
try:
guid = Guid.find(Q('referent', 'eq', file_obj))[0]
except IndexError:
guid = None
if guid:
guids.append(guid._id)
return guids
示例9: get_targets
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def get_targets():
"""Find GUIDs with no referents and GUIDs with referents that no longer exist."""
# Use a list comp because querying MODM with Guid.find(Q('referent', 'eq', None))
# only catches the first case.
return [each for each in Guid.find() if each.referent is None]
示例10: _repoint_guids
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def _repoint_guids(self, updated):
for guid in Guid.find(Q('referent', 'eq', self)):
guid.referent = updated
guid.save()
示例11: get_targets
# 需要导入模块: from framework.guid.model import Guid [as 别名]
# 或者: from framework.guid.model.Guid import find [as 别名]
def get_targets():
return Guid.find(QUERY)