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


Python Repository.find_objects方法代码示例

本文整理汇总了Python中keep.common.fedora.Repository.find_objects方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.find_objects方法的具体用法?Python Repository.find_objects怎么用?Python Repository.find_objects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keep.common.fedora.Repository的用法示例。


在下文中一共展示了Repository.find_objects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: largefile_ingest

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import find_objects [as 别名]
def largefile_ingest(request):
    '''Large-file ingest.  On GET, displays a form allowing user to
    select a BagIt that has been uploaded to the configured large-file
    ingest staging area for ingest and association with a collection.
    '''
    # ingest content from upload staging area

    context = {}
    template_name = 'file/largefile_ingest.html'
    form = None

    # on POST, process the form and ingest if valid
    if request.method == 'POST':
        form = LargeFileIngestForm(request.POST)

        # if form is not valid, add to context for redisplay with errors
        if not form.is_valid():
            context['form'] = form

        # otherwise, process the form
        else:
            repo = Repository(request=request)

            # Get collection & check for optional comment
            collection = repo.get_object(pid=form.cleaned_data['collection'],
                                         type=CollectionObject)
            # get user comment if any; default to a generic ingest comment
            comment = form.cleaned_data['comment'] or 'initial repository ingest'
            bag = form.cleaned_data['bag']

            # create dict with file info to add success/failure info
            file_info = {'label': os.path.basename(bag)}

            #assuming type of ingest from subdirectory
            type = bag.split('/')[-2]
            try:

                if type == 'diskimage':
                    obj = DiskImage.init_from_bagit(bag, request)

                elif type == 'video':
                    obj = Video.init_from_bagit(bag, request)

                # set collection on ingest
                obj.collection = collection

                ## NOTE: Due to a bug in Fedora 3.4 with checksums and
                ## and file uri ingest, the content datastream checksum
                ## must be cleared before ingest; manually check it
                ## after ingest to confirm Fedora calculated what we expect.
                ## This work-around can be removed once we upgrade to Fedora 3.6

                # store datastream checksum that would be sent to fedora
                checksum = obj.content.checksum
                obj._content_checksum = checksum
                # clear it out so Fedora can ingest without erroring
                obj.content.checksum = None

                # file URIs also used for supplemental files; needs
                # to be handled the same way as content datastream
                # - look for any supplementN datastreams, store checksum, and remove
                supplemental_checksums = {}
                for i in range(20):
                    try:
                        dsid = 'supplement%d' % i
                        dsobj = getattr(obj, dsid)
                        supplemental_checksums[dsid] = dsobj.checksum
                        dsobj.checksum = None
                    except AttributeError:
                        # stop iterating - we have found last supplemental file
                        break

                # same for access copy checksum on Video files
                if type == 'video':
                    access_checksum = obj.access_copy.checksum
                    obj.access_copy.checksum = None
                
                pids_exists = []
                if type == 'video':
                    pids_exists = repo.find_objects(type=Video, label=obj.label)
                
                if type == 'diskimage':
                    pids_exists = repo.find_objects(type=DiskImage, label=obj.label)

                exists = 0
                for pid in pids_exists:
                    if pid.pid:
                        exists += 1

                if exists == 0:
                    obj.save(comment)
                else:
                    raise ValueError('Duplicate content detected.')


                # remove the ingested bag from large-file staging area
                shutil.rmtree(bag)

                # re-init to allow checking fedora-calculated checksums on
                # supplemental datastreams
#.........这里部分代码省略.........
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:103,代码来源:views.py

示例2: Command

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import find_objects [as 别名]

#.........这里部分代码省略.........
    def handle(self, *args, **options):
        #setup verbosity
        #0 = none, 1 = normal, 2 = all
        self.v_none = 0
        self.v_normal = 1

        if 'verbosity' in options:
            self.verbosity = int(options['verbosity'])
        else:
            self.verbosity = self.v_normal

        #Create the repo
        repo_args = {}
        if options.get('username') is not None:
            repo_args['username'] = options.get('username')
        if options.get('password') is not None:
            repo_args['password'] = options.get('password')
        self.repo = Repository(**repo_args)

        #Check options

        #if no steps are specified then run all steps
        if not options["simple-collection-step"] and not options["datastreams-step"]:
            options["simple-collection-step"] = True
            options["datastreams-step"] = True

        #This step requires simeple collection Label
        if options["simple-collection-step"]:
            if not options["simple-collection"]:
                raise CommandError("When running SimpleCollection step SimpleCollection Label is required")
            else:
                #lookup Simplecollection
                try:
                    sc_list = list(self.repo.find_objects(label__exact=options["simple-collection"], type=SimpleCollection))
                    if len(sc_list) > 1:  # something is wrong need to investigate
                        raise CommandError("More than one SimpleCollection with Label %s exists" % options["simple-collection"])
                    elif len(sc_list) == 1:  # use this as the simple collection
                        self.simple_collection = sc_list[0]
                    elif len(sc_list) == 0:  # create new simple collection
                        self.simple_collection = self.repo.get_object(type=SimpleCollection)
                        self.simple_collection.label = options["simple-collection"]
                        self.simple_collection.dc.content.title = options["simple-collection"]
                        self.simple_collection.mods.content.create_restrictions_on_access()
                        self.simple_collection.mods.content.restrictions_on_access.text = "Accessioned"
                except Exception as e:
                    if not isinstance(e, CommandError):
                        raise CommandError("Could not obtain requested SimpleCollection %s : %s" % (options["simple-collection"], e))
                    else:
                        raise e

        if options["datastreams-step"]:
            if not options["master-collection-pid"]:
                raise CommandError("When running Datastream step Master collection pid is required")
            else:
                try:
                    self.master_collection = self.repo.get_object(pid=options["master-collection-pid"],
                        type=CollectionObject)
                    if not self.master_collection.exists:
                        raise CommandError("Master Collection %s does not exist" \
                            % options["master-collection-pid"])
                except Exception as e:
                    raise CommandError("Could not obtain requested Master Collection %s : %s" \
                        % (options["master-collection-pid"], e))

        #Create lookup for series
        series_lookup = self._create_series_lookup()
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:70,代码来源:migrate_rushdie.py


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