|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-01-14 13:34:14
|
Revision: 449
http://sword-app.svn.sourceforge.net/sword-app/?rev=449&view=rev
Author: richard-jones
Date: 2012-01-14 13:34:07 +0000 (Sat, 14 Jan 2012)
Log Message:
-----------
fix bugs with primitive webui, and wiring into webpy and pylons interfaces
Modified Paths:
--------------
sss/branches/sss-2/PYLONS.txt
sss/branches/sss-2/sss/pylons_sword_controller.py
sss/branches/sss-2/sss/webpy.py
sss/branches/sss-2/sss/webui.py
Modified: sss/branches/sss-2/PYLONS.txt
===================================================================
--- sss/branches/sss-2/PYLONS.txt 2012-01-14 12:08:07 UTC (rev 448)
+++ sss/branches/sss-2/PYLONS.txt 2012-01-14 13:34:07 UTC (rev 449)
@@ -19,6 +19,9 @@
routing.py
+In order to make the routes work properly, you need to remove the public/index.html
+to make the "/" route work properly
+
"""Routes configuration
The more specific and detailed routes should be defined first so they
Modified: sss/branches/sss-2/sss/pylons_sword_controller.py
===================================================================
--- sss/branches/sss-2/sss/pylons_sword_controller.py 2012-01-14 12:08:07 UTC (rev 448)
+++ sss/branches/sss-2/sss/pylons_sword_controller.py 2012-01-14 13:34:07 UTC (rev 449)
@@ -3,10 +3,11 @@
from pylons.controllers import WSGIController
from pylons.templating import render_mako as render
-import re, base64, urllib, uuid
+import re, base64, urllib, uuid, inspect
from core import Auth, SWORDSpec, SwordError, AuthException, DepositRequest, DeleteRequest
from negotiator import ContentNegotiator, AcceptParameters, ContentType
from spec import Errors, HttpHeaders, ValidationException
+from webui import HomePage, CollectionPage, ItemPage
import logging
ssslog = logging.getLogger(__name__)
@@ -263,7 +264,7 @@
if http_method == "GET":
return self._GET_service_document(sub_path)
else:
- ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + __name__)
+ ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + inspect.stack()[0][3])
abort(405, "Method Not Allowed")
return
@@ -274,7 +275,7 @@
elif http_method == "POST":
return self._POST_collection(path)
else:
- ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + __name__)
+ ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + inspect.stack()[0][3])
abort(405, "Method Not Allowed")
return
@@ -289,7 +290,7 @@
elif http_method == "DELETE":
return self._DELETE_media_resource(path)
else:
- ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + __name__)
+ ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + inspect.stack()[0][3])
abort(405, "Method Not Allowed")
return
@@ -304,7 +305,7 @@
elif http_method == "DELETE":
return self._DELETE_container(path)
else:
- ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + __name__)
+ ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + inspect.stack()[0][3])
abort(405, "Method Not Allowed")
return
@@ -313,14 +314,40 @@
if http_method == "GET":
return self._GET_statement(path)
else:
- ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + __name__)
+ ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + inspect.stack()[0][3])
abort(405, "Method Not Allowed")
return
- def aggregation(self, path=None): pass
- def part(self, path=None): pass
- def webui(self, path=None): pass
+ def aggregation(self, path=None):
+ http_method = request.environ['REQUEST_METHOD']
+ if http_method == "GET":
+ return self._GET_aggregation(path)
+ else:
+ ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + inspect.stack()[0][3])
+ abort(405, "Method Not Allowed")
+ return
+ def webui(self, path=None):
+ http_method = request.environ['REQUEST_METHOD']
+ if http_method == "GET":
+ return self._GET_webui(path)
+ else:
+ ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + inspect.stack()[0][3])
+ abort(405, "Method Not Allowed")
+ return
+
+
+ def part(self, path=None):
+ http_method = request.environ['REQUEST_METHOD']
+ if http_method == "GET":
+ return self._GET_part(path)
+ elif http_method == "PUT":
+ return self._PUT_part(path)
+ else:
+ ssslog.info("Returning (405) Method Not Allowed; Received " + http_method + " request on " + inspect.stack()[0][3])
+ abort(405, "Method Not Allowed")
+ return
+
# SWORD Protocol Operations
###########################
@@ -341,7 +368,7 @@
ss = SwordServer(config, auth)
sd = ss.service_document(path)
response.content_type = "text/xml"
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return sd
def _GET_collection(self, path=None):
@@ -363,7 +390,7 @@
ss = SwordServer(config, auth)
cl = ss.list_collection(path)
response.content_type = "text/xml"
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return cl
def _POST_collection(self, path=None):
@@ -398,11 +425,11 @@
response.status = "201 Created"
if config.return_deposit_receipt:
ssslog.info("Returning deposit receipt")
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return result.receipt
else:
ssslog.info("Omitting deposit receipt")
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return
except SwordError as e:
@@ -456,7 +483,7 @@
f = open(media_resource.filepath, "r")
response.status_int = 200
response.status = "200 OK"
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return f.read()
def _PUT_media_resource(self, path=None):
@@ -493,7 +520,7 @@
ssslog.info("Content replaced")
response.status_int = 204
response.status = "204 No Content" # notice that this is different from the POST as per AtomPub
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return
except SwordError as e:
@@ -532,11 +559,11 @@
response.status = "201 Created"
if config.return_deposit_receipt:
ssslog.info("Returning Receipt")
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return result.receipt
else:
ssslog.info("Omitting Receipt")
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return
except SwordError as e:
@@ -574,7 +601,7 @@
# just return, no need to give any more feedback
response.status_int = 204
response.status = "204 No Content" # No Content
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return
except SwordError as e:
@@ -619,7 +646,7 @@
# now actually get hold of the representation of the container and send it to the client
cont = ss.get_container(path, accept_parameters)
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return cont
except SwordError as e:
@@ -656,13 +683,13 @@
response.status_int = 200
response.status = "200 OK"
ssslog.info("Returning Deposit Receipt")
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return result.receipt
else:
response.status_int = 204
response.status = "204 No Content"
ssslog.info("Omitting Deposit Receipt")
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return
except SwordError as e:
@@ -706,11 +733,11 @@
if config.return_deposit_receipt:
response.content_type = "application/atom+xml;type=entry"
ssslog.info("Returning Deposit Receipt")
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return result.receipt
else:
ssslog.info("Omitting Deposit Receipt")
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return
except SwordError as e:
@@ -746,7 +773,7 @@
# no need to return any content
response.status_int = 204
response.status = "204 No Content"
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return
except SwordError as e:
@@ -769,8 +796,59 @@
# now actually get hold of the representation of the statement and send it to the client
cont = ss.get_statement(path)
- ssslog.info("Returning " + response.status + " from request on " + __name__)
+ ssslog.info("Returning " + response.status + " from request on " + inspect.stack()[0][3])
return cont
except SwordError as e:
return self.manage_error(e)
+
+
+ # OTHER HTTP HANDLERS
+ #############################################################################
+ # Define a set of handlers for the various URLs defined above to be used by web.py
+ # These ones aren't anything to do with the SWORD standard, they are just
+ # convenient to support the additional URIs produced
+
+ def _GET_aggregation(self, path=None):
+ # in this case we just redirect back to the Edit-URI with a 303 See Other
+ ss = SwordServer(config, None)
+ edit_uri = ss.get_edit_uri()
+ response.status_int = 303
+ response.status = "303 See Other"
+ response.headers["Content-Location"] = edit_uri
+ return
+
+ def _GET_webui(self, path=None):
+ if path is not None:
+ if path.find("/") >= 0:
+ ip = ItemPage(config)
+ return ip.get_item_page(path)
+ else:
+ cp = CollectionPage(config)
+ return cp.get_collection_page(path)
+ else:
+ hp = HomePage(config)
+ return hp.get_home_page()
+
+ def _GET_part(self, path):
+ ss = SwordServer(config, None)
+
+ # if we did, we can get hold of the media resource
+ fh = ss.get_part(path)
+
+ if fh is None:
+ return self.manage_error(SwordError(status=404, empty=True))
+
+ response.content_type = "application/octet-stream" # FIXME: we're not keeping track of content types
+ response.status_int = 200
+ response.status = "200 OK"
+ return fh.read()
+
+ def _PUT_part(self, path):
+ # FIXME: the spec says that we should either support this or return
+ # 405 Method Not Allowed.
+ # This would be useful for DepositMO compliance, so we should consider
+ # implementing this when time permits
+ response.status_int = 405
+ response.status = "405 Method Not Allowed"
+ return
Modified: sss/branches/sss-2/sss/webpy.py
===================================================================
--- sss/branches/sss-2/sss/webpy.py 2012-01-14 12:08:07 UTC (rev 448)
+++ sss/branches/sss-2/sss/webpy.py 2012-01-14 13:34:07 UTC (rev 449)
@@ -736,10 +736,10 @@
def GET(self, path=None):
if path is not None:
if path.find("/") >= 0:
- ip = ItemPage()
+ ip = ItemPage(config)
return ip.get_item_page(path)
else:
- cp = CollectionPage()
+ cp = CollectionPage(config)
return cp.get_collection_page(path)
else:
hp = HomePage(config)
Modified: sss/branches/sss-2/sss/webui.py
===================================================================
--- sss/branches/sss-2/sss/webui.py 2012-01-14 12:08:07 UTC (rev 448)
+++ sss/branches/sss-2/sss/webui.py 2012-01-14 13:34:07 UTC (rev 449)
@@ -18,15 +18,13 @@
def __init__(self, config):
self.config = config
self.dao = DAO(self.config)
- self.um = URIManager()
+ self.um = URIManager(config)
def get_home_page(self):
- cfg = self.config
-
frag = "<h1>Simple SWORDv2 Server</h1>"
- frag += "<p><strong>Service Document (SD-IRI)</strong>: <a href=\"" + cfg.base_url + "sd-uri\">" + cfg.base_url + "sd-uri</a></p>"
- frag += "<p>If prompted, use the username <strong>" + cfg.user + "</strong> and the password <strong>" + cfg.password + "</strong></p>"
- frag += "<p>The On-Behalf-Of user to use is <strong>" + cfg.obo + "</strong></p>"
+ frag += "<p><strong>Service Document (SD-IRI)</strong>: <a href=\"" + self.config.base_url + "sd-uri\">" + self.config.base_url + "sd-uri</a></p>"
+ frag += "<p>If prompted, use the username <strong>" + self.config.user + "</strong> and the password <strong>" + self.config.password + "</strong></p>"
+ frag += "<p>The On-Behalf-Of user to use is <strong>" + self.config.obo + "</strong></p>"
# list the collections
frag += "<h2>Collections</h2><ul>"
@@ -34,14 +32,15 @@
frag += "<li><a href=\"" + self.um.html_url(col) + "\">" + col + "</a></li>"
frag += "</ul>"
- head_frag = "<link rel=\"http://purl.org/net/sword/discovery/service-document\" href=\"" + cfg.base_url + "sd-uri\"/>"
+ head_frag = "<link rel=\"http://purl.org/net/sword/discovery/service-document\" href=\"" + self.config.base_url + "sd-uri\"/>"
return self._wrap_html("Simple SWORDv2 Server", frag, head_frag)
class CollectionPage(WebPage):
- def __init__(self):
- self.dao = DAO()
- self.um = URIManager()
+ def __init__(self, config):
+ self.config = config
+ self.dao = DAO(config)
+ self.um = URIManager(config)
def get_collection_page(self, id):
frag = "<h1>Collection: " + id + "</h1>"
@@ -59,9 +58,10 @@
return self._wrap_html("Collection: " + id, frag, head_frag)
class ItemPage(WebPage):
- def __init__(self):
- self.dao = DAO()
- self.um = URIManager()
+ def __init__(self, config):
+ self.config = config
+ self.dao = DAO(config)
+ self.um = URIManager(config)
def get_item_page(self, oid):
collection, id = self.um.interpret_oid(oid)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|