Mercurial > hg > sworduploader
view sword2-libraries-pyinstaller-compatible/tests/c4dmsword.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 * 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 "Available collections" for w in c.workspaces: #print w print "Community: ",w[1] print "*---------------------------*" print "Collections: " for collection in w[1]: print "Name: ",collection.title print collection.description print "URI: ",collection.href print "Accepted types: ",collection.accept print "---------------------------" # create an entry #entry = Entry(title = "My new deposit 1", id = "foo:id", dcterms_abstract = "My Thesis", dcterms_author = "Me", dcterms_issued = "2009") #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"