当前位置: 首页>>代码示例>>Python>>正文


Python Guid.find方法代码示例

本文整理汇总了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
开发者ID:545zhou,项目名称:osf.io,代码行数:32,代码来源:base.py

示例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
开发者ID:monikagrabowska,项目名称:osf.io,代码行数:32,代码来源:osfstorage.py

示例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()
开发者ID:wearpants,项目名称:osf_models,代码行数:36,代码来源:verify_guids.py

示例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
开发者ID:ccfair,项目名称:osf.io,代码行数:13,代码来源:base.py

示例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)
开发者ID:545zhou,项目名称:osf.io,代码行数:15,代码来源:base.py

示例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)
开发者ID:cslzchen,项目名称:osf.io,代码行数:17,代码来源:base.py

示例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
开发者ID:545zhou,项目名称:osf.io,代码行数:17,代码来源:find_guids_without_referents.py

示例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
开发者ID:exmo,项目名称:osf.io,代码行数:20,代码来源:osfstorage.py

示例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]
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:7,代码来源:find_guids_without_referents.py

示例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()
开发者ID:545zhou,项目名称:osf.io,代码行数:6,代码来源:base.py

示例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)
开发者ID:545zhou,项目名称:osf.io,代码行数:4,代码来源:fix_tag_guids.py


注:本文中的framework.guid.model.Guid.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。