
BenO
By: a guest on
Dec 14th, 2007 | syntax:
Python | size: 1.60 KB | hits: 209 | expires: Never
# This is to be put in line by line into an interactive python
# command line
from lib.fedoraClient import FedoraClient
from lib.foxml import *
from lib.dc import *
# Get the fedora client:
f = FedoraClient(serverurl='http://localhost:8080/fedora', username='fedoraAdmin', password='fedoraAdmin', version="2.2")
# Get an empty foxml object:
foxml = Foxml()
foxml.setProperty('contentModel', 'eprint')
foxml.setProperty('ownerId', 'Owner ID or name')
foxml.setProperty('label', 'Title of thing')
# Get next pid:
pid_response = f.getNextPID(namespace='changeme')
found_pid = None
if pid_response._pid != None and pid_response._pid != '':
found_pid = pid_response._pid[0]
foxml.setPID(found_pid)
response = f.ingest(foxml.toString())
# Now you have a fresh new item in the repository, as long as the response
# doesn't say otherwise.
# Let's get the DC field from the repository in a helper function and
# add a few fields and save it back:
# Create dc helper and pass a reference to the Fedora client:
dc = DC(FedoraClient=f)
# This will get the DC from the object in the repository. The '' is there
# as this is another way to pass the DC xml into this object.
dc.setDOM('',pid=found_pid)
dc.addField('creator', 'A.N.Other')
dc.addField('date', '2007')
dc.addField('identifier', 'urn:isbn:dadedadedah')
# Whoops, let's get rid of that identifier:
# dc.removeField('field') works in a LiFo way - Last in, First Out.
dc.removeField('identifier')
print dc.toString()
# This works, as the Fedora client ref was passed to it. It knows how to store itself.
dc.store()