Mercurial > hg > sworduploader
view sword2-libraries-pyinstaller-compatible/tests/c4dmprompt.py @ 16:8b69bba225c9
Added pyinstaller compatible sword2 python libraries
author | Marco Fabiani <marco.fabiani@eecs.qmul.ac.uk> |
---|---|
date | Tue, 29 May 2012 12:42:49 +0100 |
parents | |
children |
line wrap: on
line source
from sword2 import * testentry = 'd'; # 'd' for metadata + data c = Connection("http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/servicedocument", user_name="marco.fabiani@eecs.qmul.ac.uk", user_pass="housecouch29",keep_history=False) c.get_service_document() if c.sd != None: #c.sd.parsed #c.sd.valid #print c.history print "Welcome to the ",c.workspaces[0][0], "repository" print "Available Collections: " numColl = len(c.workspaces[0][1]) for ctr in range(numColl): coll = c.workspaces[0][1][ctr] print ctr+1,":",coll.title #print coll.description #print "URI: ",coll.href #print "Accepted types: ",coll.accept #print "---------------------------" sel = -1 while (sel<=0 or sel>numColl): sel = input("Select a Collection: ") collection = c.workspaces[0][1][sel-1] print "You selected: " print "Name: ",collection.title print collection.description print "URI: ",collection.href print "Accepted types: ",collection.accept if testentry == 'd': # create a metadata + files entry entry = Entry(dcterms_title = "Another Two PFDs deposit", dcterms_abstract = "My Thesis", dcterms_created = "2009",dcterms_creator="Fabiani, Marco",dcterms_publisher="C4DM",dcterms_type="Dataset",dcterms_subject="test",dcterms_isReferencedBy="Myself (2009). Another test deposit.") entry.add_fields(dcterms_creator="Pallino, Pinco") print str(entry) receipt = c.create(col_iri = collection.href, metadata_entry = entry) # HERE GOES BITSTREAM UPLOAD! print receipt.edit_media_feed #print receipt.se_iri #print receipt myfile = open("PDF1.pdf", "rb") try: receipt_dep = c.add_file_to_resource(edit_media_iri = receipt.edit_media, payload = myfile, filename = 'PDF1.pdf', mimetype = 'application/zip', packaging = 'http://purl.org/net/sword/package/Binary' #packaging = 'http://purl.org/net/sword/package/SimpleZip') ) except HTTPResponseError: print "Bad request" myfile.close() myfile = open("PDF2.pdf", "rb") try: receipt_dep = c.add_file_to_resource(edit_media_iri = receipt.edit_media, payload = myfile, filename = 'PDF2.pdf', mimetype = 'application/zip', packaging = 'http://purl.org/net/sword/package/Binary' #packaging = 'http://purl.org/net/sword/package/SimpleZip') ) except HTTPResponseError: print "Bad request" myfile.close() try: dr = c.complete_deposit(se_iri = receipt.se_iri) except ServerError: print "Server error!" #entry.register_namespace("simpledc","http://purl.org/dc/terms/") #entry.add_fields(simpledc_contributor="Marco",simpledc_title="Test title 1" ,simpledc_creator="myself",simpledc_description="A description") #entry.register_namespace("mo","http://purl.org/ontology/mo/") #entry.add_fields(mo_track="testtrack") #e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title 1") #with open("foo.zip","rb") as pkg: # receipt = c.create(col_iri = c.sd.workspaces[0][1][1].href,metadata_entry = e,payload=pkg,mimetype="application/zip", filename="foo.zip", packaging = 'http://purl.org/net/sword/package/Binary',in_progress = True) # assert receipt.code == 201 # assert receipt.location != None # these last two assertions are contingent on if we actually get a # receipt back from the server (which we might not legitimately get) #assert receipt.dom is None or receipt.parsed == True #assert receipt.dom is None or receipt.valid == True #print entry #data = open("foo.pdf", "rb") #receipt = c.create(col_iri = w[1][0].href, metadata_entry = entry,payload = data, mimetype = "application/pdf",packaging = "http://purl.org/net/sword/package/Binary") #try: ##receipt = c.create(col_iri = c.sd.workspaces[0][1][1].href, payload = data, mimetype = "application/zip",filename="example.zip", packaging = "http://purl.org/net/sword/package/METSDSpaceSIP") #receipt = c.create(col_iri = c.sd.workspaces[0][1][1].href, metadata_entry = entry) #receipt = c.create(col_iri = w[1][0].href, metadata_entry = entry,payload = data, mimetype = "application/pdf",packaging = "http://purl.org/net/sword/package/Binary",filename="foo.pdf") #except ServerError: #print "Server error!" #except HTTPResponseError: #print "Bad request" #try:#data=("foo.zip","rb") # deposit_receipt = c.append(dr=receipt,payload="hello",filename="foo.txt",packaging = "http://purl.org/net/sword/package/Binary",mimetype = "text/plain") #except HTTPResponseError: # print "Bad request" #try: # dr = c.complete_deposit(se_iri = receipt.se_iri) #except ServerError: # print "Server error!" #else: #print "Couldn't retrieve SD" elif testentry == 'm': # create a metadata + files entry #entry = Entry(dcterms_title = "Test Mets", dcterms_abstract = "My Thesis", dcterms_created = "2009",dcterms_creator="Fabiani, Marco",dcterms_publisher="C4DM",dcterms_type="Dataset",dcterms_subject="test",dcterms_isReferencedBy="Myself (2009). Another test deposit.") # entry.add_fields(dcterms_creator="Pallino, Pinco") # print str(entry) #receipt = c.create(col_iri = collection.href, metadata_entry = entry) # HERE GOES BITSTREAM UPLOAD! #print receipt.edit_media_feed # Send a DSPACE mets package myfile = open("example.zip", "rb") try: # receipt_dep = c.update(dr = receipt, # receipt_dep = c.add_file_to_resource(edit_media_iri = receipt.edit_media, receipt_dep = c.create(col_iri = collection.href, payload = myfile, filename = 'example.zip', mimetype = 'application/zip', packaging = 'http://purl.org/net/sword/package/METSDSpaceSIP') #in_progress = True) receipt = receipt_dep except: print "Error!" myfile.close() else: # create a metadata + files entry #entry = Entry(dcterms_title = "Test Mets", dcterms_abstract = "My Thesis", dcterms_created = "2009",dcterms_creator="Fabiani, Marco",dcterms_publisher="C4DM",dcterms_type="Dataset",dcterms_subject="test",dcterms_isReferencedBy="Myself (2009). Another test deposit.") # entry.add_fields(dcterms_creator="Pallino, Pinco") # print str(entry) #receipt = c.create(col_iri = collection.href, metadata_entry = entry) # HERE GOES BITSTREAM UPLOAD! #print receipt.edit_media_feed # Send a DSPACE mets package myfile = open("pdfs.zip", "rb") try: # receipt_dep = c.update(dr = receipt, # receipt_dep = c.add_file_to_resource(edit_media_iri = receipt.edit_media, receipt_dep = c.create(col_iri = collection.href, payload = myfile, filename = 'pdfs.zip', mimetype = 'application/zip', packaging = 'http://purl.org/net/sword/package/SimpleZip') #in_progress = True) receipt = receipt_dep except: print "Error!" myfile.close() entry = Entry(dcterms_title = "Test Simple zip 343", dcterms_abstract = "abstract", dcterms_created = "2009",dcterms_creator="Fabiani, Marco",dcterms_publisher="C4DM",dcterms_type="Dataset",dcterms_subject="test",dcterms_isReferencedBy="Myself (2009). Another test deposit.") receipt_update = c.update(dr = receipt_dep , metadata_entry = entry, in_progress = True) #try: # dr = c.complete_deposit(se_iri = receipt.se_iri) #except ServerError: # print "Server error!"