예제 #1
0
    def handle(self, *args, **options):
        print "starting"
        source_location = mkdtemp()
        myfile = args[0]
        shutil.copy(myfile, source_location)
        new_id = identity.mint()
        print "new_id:%s" % new_id
        print "exists:%s" % identity.exists(new_id)
        print "is it valid:%s" % identity.validate(new_id)

        identity.bind(new_id, myfile, 'tstem31')

        print "exists:%s" % identity.exists(new_id)
        print "store"
        storage.ingest_directory(new_id, source_location)
        print "stored"

        fix = fixity.generate(myfile, 'md5')
        print "fixity for %s is: %s" % (myfile, fix)
        fixity.bind(new_id, fix)

        print "adding an annotation"
        assertions = []
        assertions.append((new_id, ("dc", "http://purl.org/dc/elements/1.1/", "title"), "this is a test title"))
        assertions.append((new_id, ("dc", "http://purl.org/dc/elements/1.1/", "author"), "Shakespeare, Billy"))
        annotate.add(new_id, assertions)
        print "annotation added"
        print "ending"
        return 
예제 #2
0
def upload_batch(request):
    if request.method == 'POST':
        spreadsheet = request.FILES['file_0']
        archive = request.FILES['file_1']
        stats = Philes().get_stats()

        # enforce the upload files order/type
        if not is_spreadsheet(spreadsheet) or not is_archive(archive):
            print "one of your files just ain't right"
            return render_to_response('ingest.html', {'batch': True, 'stats':stats})

        # both uploads are valid: process batch upload
        # upload spreadsheet and pass file to get_meta_dict
        uploaddir = mkdtemp()
        ss = handle_file_upload(uploaddir, spreadsheet) 

        # get spreadsheet meta data  
        metadict = get_meta_dict(ss)

        # unpack the archive file, 
        handle_file_upload(uploaddir, archive) 
        aname = os.path.join(uploaddir, archive.name)
        unpack_archive(aname, archive)

        # create identifier for each object
        # upload object individually and assign
        # -------  loop over the metadata dict and find file name
        errors = []
        for key,val in metadict.iteritems():
            fp = os.path.dirname(aname) + "/" + key
            # move the file from the zip into new tmp directory
            t = mkdtemp()
            sz = os.path.getsize(fp)
            shutil.move(fp, t) 
            newf = t + "/" + key
            try:
                
                ark = identity.mint_new()
                repopath = storage.ingest_directory(ark, t)
                identity.bind(ark, repopath, 'dmc186', sz)
                # can't put this in ingest_directory b.c.
                # bind hasn't been done yet.  yucky.
                Log().logark(ark, 'ObjectIngested')
                assertions = []
                # loop over metadata to store
                for i, v in enumerate(val):
                    #print "\t%s" % v
                    for vals in metadict[key][v]:
                        #print "\t\t%s" % vals
                        #assertion = (ark, ("dc", "http://purl.org/dc/elements/1.1/", v), vals) 
                        assertion = (ark, settings.METADATA_URLS[v], vals) 
                        assertions.append(assertion)
                annotate.add(ark, assertions)
                shutil.rmtree(t)
            except IOError as (errno, strerror):
                print "I/O error({0}): {1}".format(errno, strerror)
                print "%s" % newf 
                pass
            except:
예제 #3
0
파일: views.py 프로젝트: DanCoughlin/caps
def upload_object(request):
    stats = Philes().get_stats()
    if request.method == 'POST':
             
        ark = identity.mint_new()
        print "posting:%s" % ark
        
        uploaddir = mkdtemp()
        print "dir:%s" % uploaddir

        # loop over the files to upload
        f_sz = 0
        f_nm = int(request.POST.get('upload_count', 1))
        o_type = ''
        for i in range(f_nm):
            f = request.FILES['file_'+str(i+1)]
            cb_key = 'unzip_cb_' + str(i+1)
            # if user does not want to unpack or just regular file upload
            print "index:%s" % str(i+1)
            print "file:%s" % f 
            print "filetype:%s" % f.content_type
            o_type = f.content_type
            # unpacking a file for user and uploading that
            f_sz += f.size
            print "size:%d" % f_sz
            handle_file_upload(uploaddir, f)
            # archive file and user has selected to have system unpack
            if request.POST.has_key(cb_key) == False and is_archive(f):
                print "unpack"
                aname = os.path.join(uploaddir, f.name)
                unpack_archive(aname, f)
                o_type = 'compound'
            print "------------\n"

        # done uploading the files 
        repopath = storage.ingest_directory(ark, uploaddir)
        print "num:%d totalsize:%d" % (f_nm, f_sz)
        if f_nm > 1:
            o_type = 'compound'
        identity.bind(ark, repopath, 'dmc186', f_sz, f_nm, o_type) 

        # can't be put in storage.ingest_directory because
        # bind hasn't happened yet - yucky.
        Log().logark(ark, 'ObjectIngested')
        add_assertions(request, ark)

        # remove temp files from webserver
        shutil.rmtree(uploaddir)

        # done adding metadata 
        return HttpResponseRedirect('/pilot/list')

    return render_to_response('ingest.html', {'batch': False, 'stats': stats})
예제 #4
0
        print "extracted to:%s" % uploaddir
        # get spreadsheet meta data  
        metadict = views.get_meta_dict(spreadsheet)

        for key,val in metadict.iteritems():
            fp = uploaddir + "/" + key
            # move the file from the zip into new tmp directory
            t = mkdtemp()
            shutil.move(fp, t) 
            newf = t + "/" + key
            print "file:%s" % newf
            try:
                open(newf, "r")
                print "%s found" % newf 
                ark = identity.mint_new()
                repopath = storage.ingest_directory(ark, t)
                identity.bind(ark, repopath, 'dmc186')

                assertions = []
                # loop over metadata to store
                for i, v in enumerate(val):
                    #print "\t%s" % v
                    for vals in metadict[key][v]:
                        #print "\t\t%s" % vals
                        assertion = (ark, ("dc", "http://purl.org/dc/elements/1.1/", v), vals) 
                        assertions.append(assertion)
                annotate.add(ark, assertions)
                shutil.rmtree(t)
            except IOError as (errno, strerror):
                print "I/O error({0}): {1}".format(errno, strerror)
                print "%s" % newf