コード例 #1
0
ファイル: speedtest.py プロジェクト: JohannaPu/DNSCore
#!/usr/bin/env python

from fedorarest import FedoraClient
from sys import argv
import time

client = FedoraClient(url="http://localhost:8080/fedora",password="")
times = []

for i in range(50):
	content = open(argv[1], "rb").read()
	t = time.time()
	dsId = "ds_%s" % i
	response, body = client.addDatastream(argv[2], dsId, content, mimeType="image/tiff", controlGroup="M")
	times.append(time.time() - t)
	print "%s - status: %s" % (dsId, response["status"])
	if response["status"][0] == "4" or response["status"][0] == "5":
		print body

sum = sum(times)
print "Average: %s s" % (sum / len(times))
print "Total: %s s" % sum
コード例 #2
0
#!/usr/bin/env python

from fedorarest import FedoraClient
import os

client = FedoraClient(url="http://localhost:8080/fedora",password="")

# delete standard policies
delete = ["access-staff","access-teacher","access-student","public-demo_demoObjectCollection"]
for policy in delete:
	pid = "fedora-policy:" + policy
	response, body = client.purgeObject(pid)
	print "purged %s - status: %s" % (pid,response["status"])

# ingest custom policies
foxmls = os.listdir("policies/");
for foxml in foxmls:
	content = open("policies/"+foxml).read()
	response, body = client.ingest(content=content)
	print "ingested %s - status: %s" % (foxml,response["status"])
	if response["status"][0] == "4" or response["status"][0] == "5":
		print body
コード例 #3
0
ファイル: modify.py プロジェクト: JohannaPu/DNSCore
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput

client = FedoraClient(url="http://localhost:8080/fedora",password="")

for line in fileinput.input():
	pid = line[0:-1]
	response, body = client.modifyObject(pid)
	print "%s - status: %s" % (pid,response["status"])
コード例 #4
0
ファイル: ingest.py プロジェクト: StephanU/prepscripts
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput
from sys import argv

client = FedoraClient(url="http://localhost:8080/fedora",password="")

files = []

if argv[1] == "-f":
	files.append(argv[2])
else:
	files = fileinput.input()

for line in  files:
	filename = line.strip()
	content = open(filename).read()
	response, body = client.ingest(content=content)
	print "%s - status: %s" % (filename,response["status"])
	print "ingested %s - status: %s" % (filename,response["status"])
	if response["status"][0] == "4" or response["status"][0] == "5":
		print body
コード例 #5
0
ファイル: markAsDeleted.py プロジェクト: JohannaPu/DNSCore
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput

client = FedoraClient(url="http://localhost:8080/fedora",password="")

for line in fileinput.input():
	pid = line[0:-1]
	response, body = client.modifyObject(pid,state="D")
	print "%s - status: %s" % (pid,response["status"])
コード例 #6
0
ファイル: modify.py プロジェクト: StephanU/prepscripts
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput

client = FedoraClient(url="http://localhost:8080/fedora", password="")

for line in fileinput.input():
    pid = line[0:-1]
    response, body = client.modifyObject(pid)
    print "%s - status: %s" % (pid, response["status"])
コード例 #7
0
#!/usr/bin/env python

from fedorarest import FedoraClient
from lxml import etree
import fileinput

client = FedoraClient(url="http://localhost:8080/fedora",password="")

parser = etree.XMLParser(remove_blank_text=True)

for line in fileinput.input():
	pid = line[0:-1]
	response, body = client.getDatastreamDissemination(pid,"DC")
	tree = etree.fromstring(body,parser)
	for el in tree.xpath('//dc:title',namespaces={'dc': 'http://purl.org/dc/elements/1.1/'}):
		if el.text.startswith("urn:nbn:de"):
			 el.getparent().remove(el)
	content = etree.tostring(tree, pretty_print=True)
	response, body = client.addDatastream(pid,"DC",content)
	print "%s - status: %s" % (pid,response["status"])
	
コード例 #8
0
ファイル: export.py プロジェクト: JohannaPu/DNSCore
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput
from sys import argv

client = FedoraClient(url="http://localhost:8080/fedora",password="")

for line in fileinput.input():
	pid = line[0:-1]
	response, body = client.export(pid,context="archive")
	print "%s - status: %s" % (pid,response["status"])
	FILE = open(pid + ".xml","w")
	FILE.writelines(body)
	FILE.close()
コード例 #9
0
#!/usr/bin/env python

from fedorarest import FedoraClient
from sys import argv
import os

client = FedoraClient(url="http://localhost:8080/fedora",password="")

foxml = open(argv[2], "w")

head = """<?xml version="1.0" encoding="UTF-8"?>
<foxml:digitalObject xmlns:foxml="info:fedora/fedora-system:def/foxml#" VERSION="1.1" PID="test:speedFoxml"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="info:fedora/fedora-system:def/foxml#
                                         http://www.fedora.info/definitions/1/0/foxml1-1.xsd">
  <foxml:objectProperties>
    <foxml:property NAME="info:fedora/fedora-system:def/model#state" VALUE="A"/>
    <foxml:property NAME="info:fedora/fedora-system:def/model#label" VALUE="FOXML Speedtest"/>
  </foxml:objectProperties>"""
foxml.write(head)

dsTemplate = """<foxml:datastream CONTROL_GROUP="E" ID="{0}" STATE="A">
    <foxml:datastreamVersion ID="{0}.0" MIMETYPE="image/png"
                             LABEL="Test image">
      <foxml:contentLocation REF="{1}" TYPE="URL"/>
    </foxml:datastreamVersion>
  </foxml:datastream>"""

for i in range(50):
	dsId = "ds_%s" % i
	foxml.write(dsTemplate.format(dsId, argv[1]))
コード例 #10
0
ファイル: findObjects.py プロジェクト: StephanU/prepscripts
#!/usr/bin/env python

from fedorarest import FedoraClient
from lxml import etree
from sys import argv
import re

client = FedoraClient(url="http://localhost:8080/fedora", password="")

# get objects from fedora
pids = []
sessionToken = ""

while True:
    response, body = client.findObjects(argv[1], sessionToken=sessionToken)
    result_tree = etree.fromstring(body)
    token_elem = result_tree.xpath(
        "/f:result/f:listSession/f:token",
        namespaces={'f': 'http://www.fedora.info/definitions/1/0/types/'})
    pid_elems = result_tree.xpath(
        "//f:pid",
        namespaces={'f': 'http://www.fedora.info/definitions/1/0/types/'})
    for pid_elem in pid_elems:
        pids.append(pid_elem.text)
    if len(token_elem) == 0:
        break
    sessionToken = token_elem[0].text

for pid in pids:
    print pid
コード例 #11
0
ファイル: speedtest.py プロジェクト: StephanU/prepscripts
#!/usr/bin/env python

from fedorarest import FedoraClient
from sys import argv
import time

client = FedoraClient(url="http://localhost:8080/fedora", password="")
times = []

for i in range(50):
    content = open(argv[1], "rb").read()
    t = time.time()
    dsId = "ds_%s" % i
    response, body = client.addDatastream(argv[2],
                                          dsId,
                                          content,
                                          mimeType="image/tiff",
                                          controlGroup="M")
    times.append(time.time() - t)
    print "%s - status: %s" % (dsId, response["status"])
    if response["status"][0] == "4" or response["status"][0] == "5":
        print body

sum = sum(times)
print "Average: %s s" % (sum / len(times))
print "Total: %s s" % sum
コード例 #12
0
#!/usr/bin/env python

import os
from sys import argv
from fedorarest import FedoraClient

client = FedoraClient(url="http://localhost:8080/fedora", password="")

for file in os.listdir(argv[1]):
    content = open(argv[1] + file).read()
    response, body = client.modifyDatastream(argv[2], file, content)
    print "%s - status: %s" % (file, response["status"])
    if response["status"][0] == "4" or response["status"][0] == "5":
        print body
コード例 #13
0
ファイル: ingest.py プロジェクト: jschnasse/DNSCore
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput
from sys import argv

client = FedoraClient(url="http://localhost:8080/fedora",password="******")

files = []

if argv[1] == "-f":
	files.append(argv[2])
else:
	files = fileinput.input()

for line in  files:
	filename = line.strip()
	content = open(filename).read()
	response, body = client.ingest(content=content)
	print "%s - status: %s" % (filename,response["status"])
	print "ingested %s - status: %s" % (filename,response["status"])
	if response["status"][0] == "4" or response["status"][0] == "5":
		print body
コード例 #14
0
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput
from sys import argv

client = FedoraClient(url="http://localhost:8080/fedora", password="")

for line in fileinput.input():
    pid = line[0:-1]
    response, body = client.export(pid, context="archive")
    print "%s - status: %s" % (pid, response["status"])
    FILE = open(pid + ".xml", "w")
    FILE.writelines(body)
    FILE.close()
コード例 #15
0
ファイル: purge.py プロジェクト: JohannaPu/DNSCore
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput

client = FedoraClient(url="http://localhost:8080/fedora",password="")

for line in fileinput.input():
	pid = line[0:-1]
	response, body = client.purgeObject(pid)
	print "%s - status: %s" % (pid,response["status"])
コード例 #16
0
#!/usr/bin/env python

from fedorarest import FedoraClient
from sys import argv
import time

client = FedoraClient(url="http://localhost:8080/fedora", password="")
times = []

t = time.time()

content = open(argv[1], "r").read()
response, body = client.ingest(argv[2], "FOXML Speedtest", "fedoraAdmin",
                               content)
print "%s - status: %s" % (argv[2], response["status"])
if response["status"][0] == "4" or response["status"][0] == "5":
    print body

print "Total: %s s" % (time.time() - t)
コード例 #17
0
ファイル: findObjects.py プロジェクト: JohannaPu/DNSCore
#!/usr/bin/env python

from fedorarest import FedoraClient
from lxml import etree
from sys import argv
import re

client = FedoraClient(url="http://localhost:8080/fedora",password="")

# get objects from fedora
pids = []
sessionToken = ""

while True:
	response,body = client.findObjects(argv[1],sessionToken=sessionToken)
	result_tree = etree.fromstring(body)
	token_elem = result_tree.xpath("/f:result/f:listSession/f:token",namespaces={'f':'http://www.fedora.info/definitions/1/0/types/'})
	pid_elems = result_tree.xpath("//f:pid",namespaces={'f':'http://www.fedora.info/definitions/1/0/types/'})
	for pid_elem in pid_elems:
		pids.append(pid_elem.text)
	if len(token_elem) == 0:
		break
	sessionToken = token_elem[0].text
	
for pid in pids:
	print pid
コード例 #18
0
from lxml import etree
import argparse

parser = argparse.ArgumentParser(description='Transform a Fedora XML Datastream with XSLT. Expects a list of pids as input.')
parser.add_argument('pid_file', help='a text file containing the pids of the objects to be processed, seperated by newline')
parser.add_argument('source_dsId', help='the dsId of the datastream to be processed')
parser.add_argument('target_dsId', help='the dsId of the datastream the result will be saved in')
parser.add_argument('xslt_path', help='path to the xslt file used for the transformation')
parser.add_argument('--merge', action='store_true',
                   help='merge the result with the target datastream (only works for flat xmls)')
parser.add_argument('--test', action='store_true',
                   help='do not change target datastream, instead print the result')

args = parser.parse_args()

client = FedoraClient(url="http://localhost:8080/fedora",password="")

xslt_tree = etree.parse(args.xslt_path)
transform = etree.XSLT(xslt_tree)
parser = etree.XMLParser(remove_blank_text=True)

for line in open(args.pid_file,'r'):
	try:
		pid = line[0:-1]
		response, body = client.getDatastreamDissemination(pid,args.source_dsId)
		orig_tree = etree.fromstring(body,parser)
		result_tree = transform(orig_tree, object_id=("'%s'" % pid.split(':')[1]))
		if args.merge:
			response, body = client.getDatastreamDissemination(pid,args.target_dsId)
			merge_tree = etree.fromstring(body,parser)
			for child in list(result_tree.getroot()):
コード例 #19
0
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput
from lxml import etree
import re

client = FedoraClient(url="http://localhost:8080/fedora",password="")

for line in fileinput.input():
	pid = line[0:-1]
	response, body = client.listDatastreams(pid)
	result_tree = etree.fromstring(body)
	ds_elems = result_tree.xpath("//f:datastream",namespaces={'f':'http://www.fedora.info/definitions/1/0/access/'})
	for ds_elem in ds_elems:
		dsid = ds_elem.get("dsid")
		if re.match(r"institution-", dsid):
			response, body = client.purgeDatastream(pid,dsid)
			print "%s - %s - status: %s" % (pid, dsid,response["status"])
コード例 #20
0
ファイル: setup-policies.py プロジェクト: BvK200/DNSCore
#!/usr/bin/env python

from fedorarest import FedoraClient
import os

client = FedoraClient(url="http://localhost:8080/fedora",password="******")

# delete standard policies
delete = ["access-staff","access-teacher","access-student","public-demo_demoObjectCollection"]
for policy in delete:
	pid = "fedora-policy:" + policy
	response, body = client.purgeObject(pid)
	print "purged %s - status: %s" % (pid,response["status"])

# ingest custom policies
foxmls = os.listdir("policies/");
for foxml in foxmls:
	content = open("policies/"+foxml).read()
	response, body = client.ingest(content=content)
	print "ingested %s - status: %s" % (foxml,response["status"])
	if response["status"][0] == "4" or response["status"][0] == "5":
		print body
コード例 #21
0
#!/usr/bin/env python

import os
from sys import argv
from fedorarest import FedoraClient

client = FedoraClient(url="http://localhost:8080/fedora",password="")

for file in os.listdir(argv[1]):
	content = open(argv[1] + file).read()
	response, body = client.modifyDatastream(argv[2], file, content)
	print "%s - status: %s" % (file,response["status"])
	if response["status"][0] == "4" or response["status"][0] == "5":
		print body
コード例 #22
0
#!/usr/bin/env python

from fedorarest import FedoraClient
import fileinput
from lxml import etree
import re

client = FedoraClient(url="http://localhost:8080/fedora", password="")

for line in fileinput.input():
    pid = line[0:-1]
    response, body = client.listDatastreams(pid)
    result_tree = etree.fromstring(body)
    ds_elems = result_tree.xpath(
        "//f:datastream",
        namespaces={'f': 'http://www.fedora.info/definitions/1/0/access/'})
    for ds_elem in ds_elems:
        dsid = ds_elem.get("dsid")
        if re.match(r"institution-", dsid):
            response, body = client.purgeDatastream(pid, dsid)
            print "%s - %s - status: %s" % (pid, dsid, response["status"])
コード例 #23
0
ファイル: speedtestFoxml.py プロジェクト: JohannaPu/DNSCore
#!/usr/bin/env python

from fedorarest import FedoraClient
from sys import argv
import time

client = FedoraClient(url="http://localhost:8080/fedora",password="")
times = []

t = time.time()

content = open(argv[1], "r").read()
response, body = client.ingest(argv[2], "FOXML Speedtest", "fedoraAdmin", content)
print "%s - status: %s" % (argv[2], response["status"])
if response["status"][0] == "4" or response["status"][0] == "5":
	print body

print "Total: %s s" % (time.time() - t)