From 4cff169332db751203f5a006928b6a31de0092f0 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Thu, 2 Jul 2015 12:18:22 +0100 Subject: schema: Add example browser application Change-Id: I1a4f97db7db32d33530ad9fd1009579611f8521d --- schema/browser/README.txt | 41 +++++++++++++++++++++++++++++++++++++++++ schema/browser/main.py | 23 +++++++++++++++++++++++ schema/browser/manifest.yml | 10 ++++++++++ schema/browser/requirements.txt | 5 +++++ 4 files changed, 79 insertions(+) create mode 100644 schema/browser/README.txt create mode 100644 schema/browser/main.py create mode 100644 schema/browser/manifest.yml create mode 100644 schema/browser/requirements.txt diff --git a/schema/browser/README.txt b/schema/browser/README.txt new file mode 100644 index 00000000..45745b6d --- /dev/null +++ b/schema/browser/README.txt @@ -0,0 +1,41 @@ +This is a demo application for browsing Baserock definitions. + +It is a tiny wrapper over the 'rdflib_web' Python library, which provides a +really cool web interface for browsing RDF data, based on the Flask and RDFLib +libaries. + +DISCLAIMER: this was hacked up in a few hours, please don't expect greatness. + + +Deploying to Cloud Foundry +-------------------------- + +You can deploy to Pivotal Cloud Foundry by setting up an account at +. Or you can deploy to another Cloud Foundry instance, +probably. Make sure you have the `cf` commandline client installed and have run +`cf login` with your details. + +You need to 'vendor' the dependencies by running: + + mkdir vendor + pip install --download vendor -r requirements.txt + +You need to clone 'rdflib_web' from Git, because it isn't packaged in Pip. + + git clone https://github.com/RDFLib/rdflib-web + +Finally you need to create the file 'definitions.rdfxml' from the definitions. + + cd ../ + python ./to-rdfxml.py + cd schema + mv ../definitions.rdfxml . + +Test the app locally. + + PYTHONPATH=rdflib-web python main.py + +If it works, push to Cloud Foundry (10 second timeout, the default is probably +too long): + + cf push -t 10 diff --git a/schema/browser/main.py b/schema/browser/main.py new file mode 100644 index 00000000..e977cd76 --- /dev/null +++ b/schema/browser/main.py @@ -0,0 +1,23 @@ +import flask +import rdflib +import rdflib_web.lod + +import os + + +definitions = rdflib.Graph() +definitions.parse('definitions.rdfxml') + +#app = flask.Flask('Example Baserock definitions browser') +#app.config['graph'] = definitions +#app.register_blueprint(rdflib_web.lod.lod) + +app = rdflib_web.lod.get( + definitions, + types='auto', + dbname='Baserock reference system definitions (example)') + +# Cloud Foundry runtime will set this variable. Or you can set it. +port = int(os.environ.get('PORT', 5000)) + +app.run(host="0.0.0.0", port=port) diff --git a/schema/browser/manifest.yml b/schema/browser/manifest.yml new file mode 100644 index 00000000..6722944b --- /dev/null +++ b/schema/browser/manifest.yml @@ -0,0 +1,10 @@ +# Cloud Foundry manifest for Baserock definitions browser demo app +# +# You can deploy with: `cf push`. But you'll need to change the name if you're +# deploying to Pivotal's Cloud Foundry http://run.pivotal.io/ because I already +# used 'http://baserock-definitions-rdf-test.cfapps.io'. + +--- +applications: +- name: baserock-definitions-rdf-test + command: PYTHONPATH=rdflib-web python main.py diff --git a/schema/browser/requirements.txt b/schema/browser/requirements.txt new file mode 100644 index 00000000..63034598 --- /dev/null +++ b/schema/browser/requirements.txt @@ -0,0 +1,5 @@ +# This file causes the Cloud Foundry Python buildpack to recognise this app +# as Python. + +Flask==0.10.1 +rdflib==4.2.0 -- cgit v1.2.1