Guest User

BenO

a guest
Dec 14th, 2007
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. # This is to be put in line by line into an interactive python
  2. # command line
  3.  
  4. from lib.fedoraClient import FedoraClient
  5.  
  6. from lib.foxml import *
  7. from lib.dc import *
  8.  
  9. # Get the fedora client:
  10. f = FedoraClient(serverurl='http://localhost:8080/fedora', username='fedoraAdmin', password='fedoraAdmin', version="2.2")
  11.  
  12. # Get an empty foxml object:
  13. foxml = Foxml()
  14.  
  15. foxml.setProperty('contentModel', 'eprint')
  16. foxml.setProperty('ownerId', 'Owner ID or name')
  17. foxml.setProperty('label', 'Title of thing')
  18.  
  19. # Get next pid:
  20. pid_response = f.getNextPID(namespace='changeme')
  21.  
  22. found_pid = None
  23. if pid_response._pid != None and pid_response._pid != '':
  24.     found_pid = pid_response._pid[0]
  25.     foxml.setPID(found_pid)
  26.     response = f.ingest(foxml.toString())
  27.  
  28. # Now you have a fresh new item in the repository, as long as the response
  29. # doesn't say otherwise.
  30.  
  31. # Let's get the DC field from the repository in a helper function and
  32. # add a few fields and save it back:
  33.  
  34. # Create dc helper and pass a reference to the Fedora client:
  35. dc = DC(FedoraClient=f)
  36.  
  37. # This will get the DC from the object in the repository. The '' is there
  38. # as this is another way to pass the DC xml into this object.
  39. dc.setDOM('',pid=found_pid)
  40.  
  41. dc.addField('creator', 'A.N.Other')
  42. dc.addField('date', '2007')
  43. dc.addField('identifier', 'urn:isbn:dadedadedah')
  44.  
  45. # Whoops, let's get rid of that identifier:
  46. # dc.removeField('field') works in a LiFo way - Last in, First Out.
  47. dc.removeField('identifier')
  48.  
  49. print dc.toString()
  50.  
  51. # This works, as the Fedora client ref was passed to it. It knows how to store itself.
  52. dc.store()
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment