Skip to content

Instantly share code, notes, and snippets.

@cbeer
Created February 15, 2010 18:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbeer/304883 to your computer and use it in GitHub Desktop.
Save cbeer/304883 to your computer and use it in GitHub Desktop.
RewriteEngine On
RewriteMap fedora-map prg:/wgbh/http/openvault/map.fedora.py
RewriteCond %{REQUEST_URI} Proxy #map just URIs with Proxy in them..
RewriteRule ^/fedora/get/([a-zA-Z0-9/:\-\.]+)$ ${fedora-map:$1} [QSA] # send along the query string.. hopefully the regex is about right.. ought to check it someday.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# map fedora commons datastream requests to files for an apache_rewrite handler
import sys,os
from elementtree import ElementTree
import urllib2
from urllib import urlencode
datastream_store_base = '/Users/chris/fedora-3.3/data/datastreams'
fedora_http = 'http://localhost:8080/fedora/'
username='fedoraAdmin'
password='fedora'
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, fedora_http, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
while sys.stdin:
id = sys.stdin.readline().rstrip()
pid, dsid = id.split('/')
content = urllib2.urlopen(fedora_http + 'objects/' + pid + '/datastreams/' + dsid + '/?format=xml').read()
e = ElementTree.fromstring(content)
l = e.find('.//dsLocation').text
t = e.find('.//dsLocationType').text
if(t == 'INTERNAL_ID'):
print(os.popen('find ' + datastream_store_base + " -name " + l + " -print").readline().rstrip())
else:
print(l)
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment