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
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:
def add_assertions(request, ark): assertions = [] # loop over metadata to store for i in range(int(request.POST.get('metadata_count'))): k = request.POST.get('meta_type_'+str(i+1)) v = request.POST.get('meta_value_'+str(i+1)) #assertion = (ark, ("dc", "http://purl.org/dc/elements/1.1/", k), v) #assertions.append(annotation) assertion = (ark, settings.METADATA_URLS[k], v) assertions.append(assertion) annotate.add(ark, assertions)
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 pass except: print "Unexpected error:", sys.exc_info()[0] print "%s" % newf raise shutil.rmtree(uploaddir) print "ending" return