#!/usr/bin/env python
# EasyPub: easy publication of RDF vocabulary
# Copyright (C) 2009 Pierre-Antoine Champin
#
# EasyPub is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# KTBS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with KTBS. If not, see .
"""
This is a drop-in CGI/WSGI script for publishing RDF vocabulary.
Quick start
===========
Assuming you want to publish the vocabulary http://example.com/mydir/myvoc, the
reciepe with the most chances to work is the following:
1. Make `myvoc` a directory at a place where your HTTP server will serve it at
the desired URI.
2. Copy the script in this directory as 'index.cgi' (or 'index.wsgi' if your
server as WSGI support).
3. In the same directory, put two files named 'index.html' and 'index.rdf'
At this point, it may work (if you are lucky), or may have to tell your HTTP
server that the directory index (i.e. the file to serve for the bare directory)
is index.wsgi.
In apache, this is done by creating (if not present) a `.htaccess` file in the
`myvoc` diractory, and adding the following line::
DirectoryIndex index.cgi
(or `index.wsgi`, accordingly)
Fortunately, this option is allowed to end-users by most webmasters.
More generaly
=============
The script will redirect, according to the Accept HTTP header, to a file with
the same name but a different extension. The file may have no extension at all, so the following layout would work as well::
mydir/myvoc (the script)
mydir/myvoc.html
mydir/myvoc.rdf
However, the tricky part is to convince the HTTP server to consider `myvoc` (an
extension-less file) as a CGI script (a thing in which I didn't succeed for the
moment...). The interesting feature of such a config is that it would support
"slash-based" vocabulary. For example, http://example.com/mydir/myvoc/MyTerm
would still redirect to the html or rdf file. This would not work with the reciep. This would not work with the `index.cgi` recipe.
The script is can be configured to serve different files or support other mime
types by altering the `MAPPING` constant below.
"""
# the list below maps mime-types to redirection URL; %s is to be replaced by
# the script name (without its extension); note that the order may be
# significant (when matching */*)
MAPPING = [
("text/html", "%s.html"),
("application/rdf+xml", "%s.rdf"),
## uncomment the following if applicable
#("application/turtle", "%s.ttl"),
#("text/n3", "%s.n3"),
]
HTML_REDIRECT = """
Non-Information Resource

Non-Information Resource

You should be redirected to %s.
"""
HTML_NOT_ACCEPTABLE = """
No acceptable representation

No acceptable representation

This server has no representation of the required resource that is acceptable
by your web agent. Available representations are: