예제 #1
0
파일: SWORD.py 프로젝트: kwierman/pyDryad
	def __init__(self, owner):
		raise NotImplementedError
		c = Connection(SD_URI, user_name = owner.username, user_pass=owner.password)
		c.get_service_document()

		# pick the first collection within the first workspace:
		workspace_1_title, workspace_1_collections = c.workspaces[0]
		collection = workspace_1_collections[0]

		# upload "package.zip" to this collection as a new (binary) resource:
		with open("package.zip", "r") as pkg:
		    receipt = c.create(col_iri = collection.href,
		                                payload = pkg,
		                                mimetype = "application/zip",
		                                filename = "package.zip",
		                                packaging = 'http://purl.org/net/sword/package/Binary',
		                                in_progress = True)    # As the deposit isn't yet finished


		# Add a metadata record to this newly created resource (or 'container')
		from sword2 import Entry
		# Entry can be passed keyword parameters to add metadata to the entry (namespace + '_' + tagname)
		e = Entry(id="atomid", 
		          title="atom-title",
		          dcterms_abstract = "Info about the resource....",
		          )
		# to add a new namespace:
		e.register_namespace('skos', 'http://www.w3.org/2004/02/skos/core#')
		e.add_field("skos_Concept", "...")


		# Update the metadata entry to the resource:
		updated_receipt = c.update(metadata_entry = e,
		                           dr = receipt,   # use the receipt to discover the right URI to use
		                           in_progress = False)  # finish the deposit
예제 #2
0
    def test_08_advanced_create_resource_with_entry(self):
        conn = Connection(SSS_URL,
                          user_name=SSS_UN,
                          user_pass=SSS_PW,
                          on_behalf_of=SSS_OBO)
        conn.get_service_document()
        col = conn.sd.workspaces[0][1][0]

        e = Entry(title="An entry only deposit",
                  id="asidjasidj",
                  dcterms_abstract="abstract",
                  dcterms_identifier="http://whatever/")
        e.register_namespace("oxds", "http://databank.ox.ac.uk/terms/")
        e.add_field("oxds_whatever", "whatever")

        receipt = conn.create(col_iri=col.href,
                              metadata_entry=e,
                              in_progress=True,
                              suggested_identifier=str(uuid.uuid4()))

        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
예제 #3
0
 def test_05_init_add_fields(self):
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               author={
                   'name': 'Ben',
                   'email': '*****@*****.**'
               })
     e.add_field("dcterms_issued", "2009")
     assert e.entry.find(NS['dcterms'] % 'issued') != None
     assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"
예제 #4
0
 def test_07_init_add_new_ns_field(self):
     e = Entry(title="Foo",
               id="asidjasidj",
               dcterms_appendix="blah blah",
               author={
                   'name': 'Ben',
                   'email': '*****@*****.**'
               })
     e.register_namespace("mylocal", "info:localnamespace")
     e.add_field("mylocal_issued", "2003")
     assert e.entry.find(NS['mylocal'] % 'issued') != None
     assert e.entry.find(NS['mylocal'] % 'issued').text == "2003"
예제 #5
0
 def test_08_advanced_create_resource_with_entry(self):
     conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
     conn.get_service_document()
     col = conn.sd.workspaces[0][1][0]
     
     e = Entry(title="An entry only deposit", id="asidjasidj", 
                 dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
     e.register_namespace("oxds", "http://databank.ox.ac.uk/terms/")
     e.add_field("oxds_whatever", "whatever")
     
     receipt = conn.create(col_iri = col.href,
                 metadata_entry = e,
                 in_progress = True,
                 suggested_identifier = str(uuid.uuid4()))
     
     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
예제 #6
0
 def test_07_init_add_new_ns_field(self):
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'*****@*****.**'})
     e.register_namespace("mylocal", "info:localnamespace")
     e.add_field("mylocal_issued", "2003")
     assert e.entry.find(NS['mylocal'] % 'issued') != None
     assert e.entry.find(NS['mylocal'] % 'issued').text == "2003"
예제 #7
0
 def test_05_init_add_fields(self):
     e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'*****@*****.**'})
     e.add_field("dcterms_issued", "2009")
     assert e.entry.find(NS['dcterms'] % 'issued') != None
     assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"